Пример #1
0
 /**
  * Save an entry
  *
  * @return  void
  */
 private function saveAction()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         return $this->loginAction();
     }
     if (!$this->params->get('access-manage')) {
         throw new Exception(\Lang::txt('PLG_MEMBERS_CITATIONS_NOT_AUTHORIZED'), 403);
     }
     // set scope & scope id in save so no one can mess with hidden form inputs
     $scope = 'member';
     $scopeID = $this->member->get('uidNumber');
     // get tags
     $tags = trim(Request::getVar('tags', ''));
     // get badges
     $badges = trim(Request::getVar('badges', ''));
     // check to see if new
     $cid = Request::getInt('cid');
     $isNew = $cid < 0 ? true : false;
     // get the citation (single) or create a new one
     $citation = \Components\Citations\Models\Citation::oneOrNew($cid)->set(array('type' => Request::getInt('type'), 'cite' => Request::getVar('cite'), 'ref_type' => Request::getVar('ref_type'), 'date_submit' => Request::getVar('date_submit', '0000-00-00 00:00:00'), 'date_accept' => Request::getVar('date_accept', '0000-00-00 00:00:00'), 'date_publish' => Request::getVar('date_publish', '0000-00-00 00:00:00'), 'year' => Request::getVar('year'), 'month' => Request::getVar('month'), 'author_address' => Request::getVar('author_address'), 'editor' => Request::getVar('editor'), 'title' => Request::getVar('title'), 'booktitle' => Request::getVar('booktitle'), 'short_title' => Request::getVar('short_title'), 'journal' => Request::getVar('journal'), 'volume' => Request::getVar('volume'), 'number' => Request::getVar('number'), 'pages' => Request::getVar('pages'), 'isbn' => Request::getVar('isbn'), 'doi' => Request::getVar('doi'), 'call_number' => Request::getVar('call_number'), 'accession_number' => Request::getVar('accession_number'), 'series' => Request::getVar('series'), 'edition' => Request::getVar('edition'), 'school' => Request::getVar('school'), 'publisher' => Request::getVar('publisher'), 'institution' => Request::getVar('institution'), 'address' => Request::getVar('address'), 'location' => Request::getVar('location'), 'howpublished' => Request::getVar('howpublished'), 'url' => Request::getVar('uri'), 'eprint' => Request::getVar('eprint'), 'abstract' => Request::getVar('abstract'), 'keywords' => Request::getVar('keywords'), 'research_notes' => Request::getVar('research_notes'), 'language' => Request::getVar('language'), 'label' => Request::getVar('label'), 'uid' => User::get('id'), 'created' => Date::toSql(), 'affiliated' => Request::getInt('affiliated', 0), 'fundedby' => Request::getInt('fundedby', 0), 'scope' => $scope, 'scope_id' => $scopeID));
     // Store new content
     if (!$citation->save() && !$citation->validate()) {
         $this->setError($citation->getError());
         $this->editAction($citation);
         return;
     }
     $authorCount = $citation->relatedAuthors()->count();
     // update authors entries for new citations
     if ($isNew) {
         $authors = \Components\Citations\Models\Author::all()->where('cid', '=', $cid);
         foreach ($authors as $author) {
             $author->set('cid', $citation->id);
             $author->save();
         }
     } elseif (!$isNew && $authorCount == 0) {
         $authorField = explode(',', Request::getVar('author'));
         $totalAuths = count($authorField);
         if ($totalAuths == 0) {
             // redirect
         }
         foreach ($authorField as $key => $a) {
             // create a new row
             $authorObj = \Components\Citations\Models\Author::blank()->set(array('cid' => $citation->id, 'ordering' => $key, 'author' => $a));
             $authorObj->save();
         }
         // turn the author string into author entries
     }
     // check if we are allowing tags
     $ct1 = new \Components\Tags\Models\Cloud($citation->id, 'citations');
     $ct1->setTags($tags, User::get('id'), 0, 1, '');
     // check if we are allowing badges
     $ct2 = new \Components\Tags\Models\Cloud($citation->id, 'citations');
     $ct2->setTags($badges, User::get('id'), 0, 1, 'badge');
     // resdirect after save
     App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), $this->getError() ? $this->getError() : Lang::txt('PLG_MEMBERS_CITATIONS_CITATION_SAVED'), $this->getError() ? 'error' : 'success');
     return;
 }
Пример #2
0
 /**
  * Save an entry
  *
  * @return		 void
  */
 private function _save()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         $this->_loginTask();
     }
     // set scope & scope id in save so no one can mess with hidden form inputs
     //$scope = 'group';
     $scope_id = $this->group->get('gidNumber');
     // get tags
     $tags = trim(Request::getVar('tags', ''));
     // get badges
     $badges = trim(Request::getVar('badges', ''));
     // check to see if new
     $cid = Request::getInt('id');
     $isNew = $cid < 0 ? true : false;
     // get the citation (single) or create a new one
     $citation = \Components\Citations\Models\Citation::oneOrNew($cid)->set(array('type' => Request::getInt('type'), 'cite' => Request::getVar('cite'), 'ref_type' => Request::getVar('ref_type'), 'date_submit' => Request::getVar('date_submit'), 'date_accept' => Request::getVar('date_accept'), 'date_publish' => Request::getVar('date_publish'), 'year' => Request::getVar('year'), 'month' => Request::getVar('month'), 'author_address' => Request::getVar('author_address'), 'editor' => Request::getVar('editor'), 'title' => Request::getVar('title'), 'booktitle' => Request::getVar('booktitle'), 'short_title' => Request::getVar('short_title'), 'journal' => Request::getVar('journal'), 'volume' => Request::getVar('volume'), 'number' => Request::getVar('number'), 'pages' => Request::getVar('pages'), 'isbn' => Request::getVar('isbn'), 'doi' => Request::getVar('doi'), 'call_number' => Request::getVar('call_number'), 'accession_number' => Request::getVar('accession_number'), 'series' => Request::getVar('series'), 'edition' => Request::getVar('edition'), 'school' => Request::getVar('school'), 'publisher' => Request::getVar('publisher'), 'institution' => Request::getVar('institution'), 'address' => Request::getVar('address'), 'location' => Request::getVar('location'), 'howpublished' => Request::getVar('howpublished'), 'url' => Request::getVar('uri'), 'eprint' => Request::getVar('eprint'), 'abstract' => Request::getVar('abstract'), 'keywords' => Request::getVar('keywords'), 'research_notes' => Request::getVar('research_notes'), 'language' => Request::getVar('language'), 'label' => Request::getVar('label'), 'uid' => User::get('id'), 'created' => Date::toSql(), 'scope' => self::PLUGIN_SCOPE, 'scope_id' => $scope_id));
     // Store new content
     if (!$citation->save()) {
         $this->setError($citation->getError());
         $this->_edit();
         return;
     }
     $authorCount = $citation->relatedAuthors()->count();
     // update authors entries for new citations
     if ($isNew) {
         $authors = \Components\Citations\Models\Author::all()->where('cid', '=', $cid);
         foreach ($authors as $author) {
             $author->set('cid', $citation->id);
             $author->save();
         }
     } elseif (!$isNew && $authorCount == 0) {
         $authorField = explode(',', Request::getVar('author'));
         $totalAuths = count($authorField);
         if ($totalAuths == 0) {
             // redirect with Error
         } else {
             foreach ($authorField as $key => $a) {
                 // create a new author entry
                 $authorObj = \Components\Citations\Models\Author::blank()->set(array('cid' => $citation->id, 'ordering' => $key, 'author' => $a));
                 $authorObj->save();
             }
         }
     }
     // check if we are allowing tags
     $ct1 = new \Components\Tags\Models\Cloud($citation->id, 'citations');
     $ct1->setTags($tags, User::get('id'), 0, 1, '');
     // check if we are allowing badges
     $ct2 = new \Components\Tags\Models\Cloud($citation->id, 'citations');
     $ct2->setTags($badges, User::get('id'), 0, 1, 'badge');
     // redirect after save
     App::redirect(Route::url('index.php?option=com_groups&cn=' . $this->group->cn . '&active=citations'), Lang::txt('PLG_GROUPS_CITATIONS_CITATION_SAVED'), 'success');
     return;
 }