Joomla publish() Method of Admin Controller

Admin Controller
Joomla publish() Method of Admin Controller

This method is used to publish a list of items.

  • return - void
public function publish()
{
// Check for request forgeries
$this->checkToken();

// Get items to publish from the request.
$cid = $this->input->get('cid', array(), 'array');
$data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
$task = $this->getTask();
$value = ArrayHelper::getValue($data, $task, 0, 'int');

if (empty($cid))
{
\JLog::add(\JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), \JLog::WARNING, 'jerror');
}
else
{
// Get the model.
$model = $this->getModel();

// Make sure the item ids are integers
$cid = ArrayHelper::toInteger($cid);

// Publish the items.
try
{
$model->publish($cid, $value);
$errors = $model->getErrors();
$ntext = null;

if ($value === 1)
{
if ($errors)
{
\JFactory::getApplication()->enqueueMessage(\JText::plural($this->text_prefix . '_N_ITEMS_FAILED_PUBLISHING', count($cid)), 'error');
}
else
{
$ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED';
}
}
elseif ($value === 0)
{
$ntext = $this->text_prefix . '_N_ITEMS_UNPUBLISHED';
}
elseif ($value === 2)
{
$ntext = $this->text_prefix . '_N_ITEMS_ARCHIVED';
}
else
{
$ntext = $this->text_prefix . '_N_ITEMS_TRASHED';
}

if ($ntext !== null)
{
$this->setMessage(\JText::plural($ntext, count($cid)));
}
}
catch (\Exception $e)
{
$this->setMessage($e->getMessage(), 'error');
}
}

$extension = $this->input->get('extension');
$extensionURL = $extension ? '&extension=' . $extension : '';
$this->setRedirect(\JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $extensionURL, false));
}

 

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive