Esempio n. 1
0
 /**
  * Publish method for group citations
  *
  * @param null
  * @return void
  *
  **/
 private function publishAction()
 {
     $id = Request::getVar('cid', 0);
     $citationIDs = Request::getVar('citationIDs', array());
     $bulk = Request::getVar('bulk', false);
     if ($id != 0 && !$bulk) {
         $citation = \Components\Citations\Models\Citation::oneOrFail($id);
         if ($citation->uid != $this->member->get('uidNumber')) {
             // redirect
             App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_OWNER_ONLY'), 'warning');
         }
         // toggle the state
         if ($citation->published != $citation::STATE_PUBLISHED) {
             $citation->set('published', $citation::STATE_PUBLISHED);
             $string = 'PLG_MEMBERS_CITATIONS_CITATION_PUBLISHED';
         } else {
             $citation->set('published', $citation::STATE_UNPUBLISHED);
             $string = 'PLG_MEMBERS_CITATIONS_CITATION_UNPUBLISHED';
         }
         // save the state
         if ($citation->save() && $citation->scope == 'member' && $citation->scope_id == $this->member->get('uidNumber')) {
             App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt($string), 'success');
             return;
         } else {
             App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_CITATION_NOT_FOUND'), 'error');
             return;
         }
     } elseif ((bool) $bulk) {
         /***
          * @TODO move to API, possible use of whereIn()?
          ***/
         // when no selection has been made
         if ($bulk == true && $citationIDs == '') {
             // redirect and warn
             App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_SELECTION_NOT_FOUND'), 'warning');
         }
         $published = array();
         $citationIDs = explode(',', $citationIDs);
         $string = 'PLG_MEMBERS_CITATIONS_CITATION_PUBLISHED';
         // error, no such citation
         foreach ($citationIDs as $id) {
             $citation = \Components\Citations\Models\Citation::oneOrFail($id);
             // toggle the state
             if ($citation->published != $citation::STATE_PUBLISHED) {
                 $citation->set('published', $citation::STATE_PUBLISHED);
             } else {
                 $citation->set('published', $citation::STATE_UNPUBLISHED);
             }
             // save the state
             if ($citation->save() && $citation->scope == 'member' && $citation->scope_id == $this->member->get('uidNumber')) {
                 array_push($published, $id);
             }
         }
         App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt($string), 'success');
         return;
     } else {
         App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_CITATION_NOT_FOUND'), 'error');
         return;
     }
 }
Esempio n. 2
0
 /**
  * Delete method for group citations
  *
  * @param null
  * @return void
  *
  **/
 private function _delete()
 {
     // verify that the user is a manager.
     $isManager = $this->authorized == 'manager' ? true : false;
     if (!$isManager) {
         // redirect to browse with admonishment
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_GROUP_MANAGER_ONLY'), 'warning');
         return;
     }
     // get the variables
     $id = Request::getVar('id', 0);
     $citationIDs = Request::getVar('citationIDs', '');
     $bulk = Request::getVar('bulk', false);
     // for single citation operation
     if ($id != 0 && !$bulk) {
         $citation = \Components\Citations\Models\Citation::oneOrFail($id);
         $citation->set('published', $citation::STATE_DELETED);
         if ($citation->save() && $citation->scope == self::PLUGIN_SCOPE && $citation->scope_id == $this->group->get('gidNumber')) {
             App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_CITATION_DELETED'), 'success');
             return;
         } else {
             App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_CITATION_NOT_FOUND'), 'error');
             return;
         }
     } elseif ((bool) $bulk) {
         /***
          * @TODO move to API, possible use of whereIn()?
          ***/
         // when no selection has been made
         if ($bulk == true && $citationIDs == '') {
             App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_SELECTION_NOT_FOUND'), 'warning');
             return;
         }
         $deleted = array();
         $citationIDs = explode(',', $citationIDs);
         $string = 'PLG_GROUPS_CITATIONS_CITATION_DELETED';
         // error, no such citation
         foreach ($citationIDs as $id) {
             $citation = \Components\Citations\Models\Citation::oneOrFail($id);
             // toggle the state
             $citation->set('published', $citation::STATE_DELETED);
             // save the state
             if ($citation->scope == self::PLUGIN_SCOPE && $citation->scope_id == $this->group->get('gidNumber') && $citation->save()) {
                 array_push($deleted, $id);
             }
         }
         if (!empty($deleted)) {
             App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt($string), 'success');
             return;
         } elseif ($citation->scope != self::PLUGIN_SCOPE) {
             App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_PERMISSION_DENIED'), 'error');
             return;
         } else {
             App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_SAVE_ERROR'), 'error');
             return;
         }
     } else {
         App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_CITATION_NOT_FOUND'), 'error');
         return;
     }
 }