I'm extending my controller's publishing method for a task called "setup".
This is the extended method:
/**
* publish function.
*
* @access public
* @return void
*/
public function publish()
{
$app = JFactory::getApplication();
$jinput = JFactory::getApplication()->input;
$ids = $jinput->get('cid', '', 'array');
$task = $this->getTask();
$date = JFactory::getDate();
$modelitem = $this->getModel('Item');
$tableitem = JTable::getInstance('Item','BestiaTable');
foreach($ids as $id)
{
$tableitem->load($id);
switch($task)
{
case 'publish' : $tableitem->autorenew = 1;
break;
case 'unpublish': $tableitem->autorenew = 1;
break;
case 'archive' : $tableitem->autorenew = 0;
$tableitem->terminatedon = $date->toSql();
break;
case 'trash' : $tableitem->autorenew = 0;
$tableitem->terminatedon = $date->toSql();
$tableitem->end = $date->toSql();
$tableitem->overwriteend = 1;
case 'setup' : $SetupHelper = SetupHelper::getInstance();
$setupitem = $SetupHelper->setupItem($id);
if ($setupitem)
{
}
else
{
$app->enqueueMessage(implode(", ", $SetupHelper->getErrors()), 'warning');
}
break;
break;
}
$tableitem->store();
}
$publish = parent::publish();
$this->setRedirect('index.php?option=com_bestia&view=items', false);
return true;
}
Okay - publishing and unpublishing works fine, but the setup-task which is started by a toolbar-button like this:
JToolbarHelper::custom('items.setup', 'cogs', '', 'Setup item', true);
Always changes the item's state to 0
instead of -1
(which is the state for "wait for setup" or 1
(which is the state for "setup okay").
How can I change this behavior and tell the method which state to use?
break;
at the end ofcase 'trash'
, and you have 2break;
's at the end ofcase 'setup'
– Lodder Nov 4 '15 at 16:18