Example #1
0
 /**
  * Method to publish a list of items
  *
  * @return  void
  */
 public function publishTask()
 {
     // Check for request forgeries
     Request::checkToken() or die(Lang::txt('JINVALID_TOKEN'));
     // Get items to publish from the request.
     $cid = Request::getVar('cid', array(), '', 'array');
     $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
     $value = \Hubzero\Utility\Arr::getValue($data, $this->_task, 0, 'int');
     if (empty($cid)) {
         throw new Exception(Lang::txt('COM_REDIRECT_NO_ITEM_SELECTED'), 500);
     } else {
         // Get the model.
         $model = new Record();
         // Make sure the item ids are integers
         \Hubzero\Utility\Arr::toInteger($cid);
         // Publish the items.
         if (!$model->publish($cid, $value)) {
             throw new Exception($model->getError(), 500);
         } else {
             if ($value == 1) {
                 $ntext = 'COM_REDIRECT_N_ITEMS_PUBLISHED';
             } elseif ($value == 0) {
                 $ntext = 'COM_REDIRECT_N_ITEMS_UNPUBLISHED';
             } elseif ($value == 2) {
                 $ntext = 'COM_REDIRECT_N_ITEMS_ARCHIVED';
             } else {
                 $ntext = 'COM_REDIRECT_N_ITEMS_TRASHED';
             }
             Notify::success(Lang::txts($ntext, count($cid)));
         }
     }
     App::redirect(Route::url('index.php?option=' . $this->_option, false));
 }