Ejemplo n.º 1
0
 /**
  * Remove one or more types
  *
  * @return  void  Redirects back to main listing
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.delete', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming (expecting an array)
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Ensure we have an ID to work with
     if (empty($ids)) {
         // Redirect with error message
         Notify::warning(Lang::txt('COM_RESOURCES_NO_ITEM_SELECTED'));
         return $this->cancelTask();
     }
     $i = 0;
     foreach ($ids as $id) {
         $row = Role::oneOrFail((int) $id);
         if (!$row->destroy()) {
             Notify::error($row->getError());
             continue;
         }
         $i++;
     }
     if ($i) {
         Notify::success(Lang::txt('COM_RESOURCES_ITEMS_REMOVED', $i));
     }
     // Redirect
     $this->cancelTask();
 }
Ejemplo n.º 2
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $fields = Request::getVar('fields', array(), 'post');
     $authorid = Request::getVar('authorid', 0);
     $id = Request::getVar('id', 0);
     if (!$authorid) {
         return $this->cancelTask();
     }
     $rows = array();
     if (is_array($fields)) {
         foreach ($fields as $fieldset) {
             $fieldset['authorid'] = $authorid;
             $row = Role::oneOrNew($fieldset['id'])->set($fieldset);
             if (!$row->save()) {
                 $this->setError($row->getError());
             }
             $rows[] = $row;
         }
     }
     if ($this->getTask() == 'apply') {
         return $this->editTask($rows);
     }
     $this->cancelTask();
 }