Ejemplo n.º 1
0
 /**
  * Display the form allowing to edit a citation
  *
  * @return  string  HTML
  */
 private function editAction($row = null)
 {
     // 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);
     }
     // Create view object
     $view = $this->view('edit');
     $view->member = $this->member;
     $view->option = $this->option;
     $view->database = $this->database;
     $view->allow_tags = $this->member->getParam('citation_allow_tags', 'yes');
     $view->allow_badges = $this->member->getParam('citatoin_allow_badges', 'yes');
     // Get the citation types
     $citationsType = \Components\Citations\Models\Type::all();
     $view->types = $citationsType->rows();
     $fields = array();
     foreach ($view->types as $type) {
         if (isset($type->fields)) {
             $f = $type->fields;
             if (strpos($f, ',') !== false) {
                 $f = str_replace(',', "\n", $f);
             }
             $f = array_map('trim', explode("\n", $f));
             $f = array_values(array_filter($f));
             $fields[strtolower(str_replace(' ', '', $type->type_title))] = $f;
         }
     }
     // Incoming
     $id = Request::getInt('cid', 0);
     // Load the object
     if (is_object($row)) {
         $view->row = $row;
     } else {
         $view->row = \Components\Citations\Models\Citation::oneOrNew($id);
         // check to see if this member created this citation
         if (!$view->row->isNew() && ($view->row->uid != User::get('id') || $view->row->scope != 'member')) {
             // redirect
             App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_CITATIONS_OWNER_ONLY'), 'warning');
         }
     }
     //make sure title isnt too long
     $maxTitleLength = 30;
     $shortenedTitle = strlen($view->row->title) > $maxTitleLength ? substr($view->row->title, 0, $maxTitleLength) . '…' : $view->row->title;
     // Set the pathway
     if ($id && $id != 0) {
         Pathway::append($shortenedTitle, 'index.php?option=com_citations&task=view&id=' . $view->row->id);
         Pathway::append(Lang::txt('PLG_MEMBERS_CITATIONS_EDIT'));
     } else {
         Pathway::append(Lang::txt('PLG_MEMBERS_CITATIONS_ADD'));
     }
     // Set the page title
     Document::setTitle(Lang::txt('PLG_MEMBERS_CITATIONS_CITATION') . $shortenedTitle);
     //push jquery to doc
     Document::addScriptDeclaration('var fields = ' . json_encode($fields) . ';');
     // Instantiate a new view
     $view->title = Lang::txt('PLG_MEMBERS_CITATIONS') . ': ' . Lang::txt('PLG_MEMBERS_CITATIONS_' . strtoupper($this->action));
     // No ID, so we're creating a new entry
     // Set the ID of the creator
     if (!$id) {
         $view->row->uid = User::get('id');
         //tags & badges
         $view->tags = array();
         $view->badges = array();
         $view->row->id = -time();
     } else {
         if ($view->row->relatedAuthors->count()) {
             $view->authors = $view->row->relatedAuthors;
         } elseif ($view->row->relatedAuthors->count() == 0 && $view->row->author != '') {
             // formats the author for the multi-author plugin
             $authors = explode(';', $view->row->author);
             $authorString = '';
             $totalAuths = count($authors);
             $x = 0;
             foreach ($authors as &$author) {
                 /***
                  * Because the multi-select keys off of a comma,
                  * imported entries may display incorrectly (Wojkovich, Kevin) breaks the multi-select
                  * Convert this to Kevin Wojkovich and I'll @TODO add some logic in the formatter to
                  * format it properly within the bibilographic format ({LASTNAME},{FIRSTNAME})
                  ***/
                 $authorEntry = explode(',', $author);
                 if (count($authorEntry == 2)) {
                     $author = $authorEntry[1] . ' ' . $authorEntry[0];
                 }
                 $authorString .= $author;
                 if ($totalAuths > 1 && $x < $totalAuths - 1) {
                     $authorString .= ',';
                 }
                 $x = $x + 1;
             }
             $view->authorString = $authorString;
         }
         //tags & badges
         $view->tags = \Components\Citations\Helpers\Format::citationTags($view->row, $this->database, false);
         $view->badges = \Components\Citations\Helpers\Format::citationBadges($view->row, $this->database, false);
     }
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $view->setError($error);
     }
     return $view->loadTemplate();
 }
Ejemplo n.º 2
0
 /**
  * Return a list of citations for a specific user
  *
  * @param	object	$group		Current group
  * @param	object	$profile	USer profile
  * @return	string
  */
 public function onGroupMemberAfter($group, $profile)
 {
     $view = $this->view('default', 'member');
     $view->group = $group;
     $view->option = 'com_groups';
     $view->task = $this->_name;
     $view->database = App::get('db');
     $view->title = Lang::txt(strtoupper($this->_name));
     $view->citationTemplate = 'apa';
     $view->filters['search'] = "";
     $view->filters['type'] = '';
     $view->filters['tag'] = '';
     $view->filters['author'] = '';
     $view->filters['publishedin'] = '';
     $view->filters['year_start'] = '';
     $view->filters['year_end'] = '';
     $view->filters['startuploaddate'] = '';
     $view->filters['enduploaddate'] = '';
     $view->filters['sort'] = '';
     // get the preferred labeling scheme
     $view->label = null;
     switch ($view->label) {
         case 'none':
             $view->citations_label_class = 'no-label';
             break;
         case 'number':
             $view->citations_label_class = 'number-label';
             break;
         case 'type':
             $view->citations_label_class = 'type-label';
             break;
         case 'both':
         default:
             $view->citations_label_class = 'both-label';
             break;
     }
     // enable coins support
     $view->coins = 1;
     // types
     $view->types = \Components\Citations\Models\Type::all();
     // OpenURL
     $openURL = $this->_handleOpenURL();
     $view->openurl['link'] = $openURL['link'];
     $view->openurl['text'] = $openURL['text'];
     $view->openurl['icon'] = $openURL['icon'];
     $view->citations = array();
     return $view->loadTemplate();
 }