/**
* Method to publish a list of items
*
* @return void
*
* @since 1.6
*/
public function publish()
{
// Check for request forgeries
$this->checkToken();
// Get items to publish from the request.
$cid = (array) $this->input->get('cid', array(), 'int');
$data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
$task = $this->getTask();
$value = ArrayHelper::getValue($data, $task, 0, 'int');
// Remove zero values resulting from input filter
$cid = array_filter($cid);
if (empty($cid)) {
$this->app->getLogger()->warning(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), array('category' => 'jerror'));
} else {
// Get the model.
$model = $this->getModel();
// Publish the items.
try {
$model->publish($cid, $value);
$errors = $model->getErrors();
$ntext = null;
if ($value === 1) {
if ($errors) {
$this->app->enqueueMessage(Text::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 (\count($cid)) {
$this->setMessage(Text::plural($ntext, \count($cid)));
}
} catch (\Exception $e) {
$this->setMessage($e->getMessage(), 'error');
}
}
$this->setRedirect(Route::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(), false));
}