Beispiel #1
0
 /**
  * Download a batch of entries
  *
  * @return  void
  */
 public function downloadbatchTask()
 {
     // get the submit buttons value
     $download = Request::getVar('download', '');
     $no_html = Request::getVar('no_html', 0);
     // get the citations we want to export
     $citationsString = Request::getVar('idlist', '');
     $citations = explode('-', $citationsString);
     // return to browse mode if we really dont wanna download
     if (strtolower($download) != 'endnote' && strtolower($download) != 'bibtex') {
         if (!$no_html) {
             return $this->displayTask();
         } else {
             return json_encode(array('status' => '1'));
         }
     }
     // var to hold output
     $doc = '';
     // for each citation we want to downlaod
     foreach ($citations as $c) {
         $cc = new Citation($this->database);
         $cc->load($c);
         //get the badges
         $ct = new Tags($cc->id);
         $cc->badges = $ct->render('string', array('label' => 'badge'));
         $cd = new Download();
         $cd->setFormat(strtolower($download));
         $doc .= $cd->formatReference($cc) . "\r\n\r\n";
         $mine = $cd->getMimeType();
     }
     $ext = strtolower($download) == 'bibtex' ? '.bib' : '.enw';
     // filename
     $filename = 'citations_export_' . strtolower($download) . '_' . Date::of('now')->format('Y_m_d') . $ext;
     // output file
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: Attachment; filename=' . $filename);
     header('Pragma: no-cache');
     echo $doc;
     exit;
 }
Beispiel #2
0
 /**
  * Get a list of citations requiring attention
  *
  * @param   array  $action_attention
  * @param   array  $action_no_attention
  * @return  array
  */
 public function process($action_attention = array(), $action_no_attention = array())
 {
     $results = array('saved' => array(), 'not_saved' => array(), 'error' => array());
     $now = with(new Date('now'))->toSql();
     $user = $this->get('user');
     $scope = $this->get('scope');
     $scope_id = $this->get('scope_id');
     $published = $this->get('published', null);
     // loop through each citation that required attention from user
     if ($cites_require_attention = $this->readRequiresAttention()) {
         foreach ($cites_require_attention as $k => $cra) {
             $cc = new Tables\Citation($this->database);
             // add a couple of needed keys
             $cra['uid'] = $user;
             $cra['created'] = $now;
             // reset tags and badges
             $tags = '';
             $badges = '';
             // remove errors
             unset($cra['errors']);
             // if tags were sent over
             if (array_key_exists('tags', $cra)) {
                 $tags = $cra['tags'];
                 unset($cra['tags']);
             }
             // if badges were sent over
             if (array_key_exists('badges', $cra)) {
                 $badges = $cra['badges'];
                 unset($cra['badges']);
             }
             //take care fo type
             $ct = new Tables\Type($this->database);
             $types = $ct->getType();
             $type = '';
             foreach ($types as $t) {
                 if (strtolower($t['type_title']) == strtolower($cra['type'])) {
                     $type = $t['id'];
                 }
             }
             $cra['type'] = $type ? $type : '1';
             switch ($action_attention[$k]) {
                 case 'overwrite':
                     $cra['id'] = $cra['duplicate'];
                     break;
                 case 'both':
                     break;
                 case 'discard':
                     $results['not_saved'][] = $cra;
                     continue 2;
                     break;
             }
             // remove duplicate flag
             unset($cra['duplicate']);
             //sets group if set
             if ($scope) {
                 $cra['scope'] = $scope;
             }
             if ($scope_id) {
                 $cra['scope_id'] = $scope_id;
             }
             if (!is_null($published)) {
                 $cra['published'] = $published;
             }
             // save the citation
             if (!$cc->save($cra)) {
                 $results['error'][] = $cra;
             } else {
                 // tags
                 if ($this->tags && isset($tags)) {
                     $this->tag($user, $cc->id, $tags, '');
                 }
                 // badges
                 if ($this->badges && isset($badges)) {
                     $this->tag($user, $cc->id, $badges, 'badge');
                 }
                 // add the citattion to the saved
                 $results['saved'][] = $cc->id;
             }
         }
     }
     if ($cites_require_no_attention = $this->readRequiresNoAttention()) {
         foreach ($cites_require_no_attention as $k => $crna) {
             // new citation object
             $cc = new Tables\Citation($this->database);
             // add a couple of needed keys
             $crna['uid'] = $user;
             $crna['created'] = $now;
             // reset tags and badges
             $tags = '';
             $badges = '';
             // remove errors
             unset($crna['errors']);
             // if tags were sent over
             if (array_key_exists('tags', $crna)) {
                 $tags = $crna['tags'];
                 unset($crna['tags']);
             }
             // if badges were sent over
             if (array_key_exists('badges', $crna)) {
                 $badges = $crna['badges'];
                 unset($crna['badges']);
             }
             // verify we haad this one checked to be submitted
             if ($action_no_attention[$k] != 1) {
                 $results['not_saved'][] = $crna;
                 continue;
             }
             // take care fo type
             $ct = new Tables\Type($this->database);
             $types = $ct->getType();
             $type = '';
             foreach ($types as $t) {
                 // TODO: undefined index type? I just suppressed the error b/c I'm not sure what the logic is supposed to be /SS
                 if (strtolower($t['type_title']) == strtolower($crna['type'])) {
                     $type = $t['id'];
                 }
             }
             $crna['type'] = $type ? $type : '1';
             // remove duplicate flag
             unset($crna['duplicate']);
             // sets group if set
             if ($scope) {
                 $crna['scope'] = $scope;
             }
             if ($scope_id) {
                 $crna['scope_id'] = $scope_id;
             }
             if (!is_null($published)) {
                 $crna['published'] = $published;
             }
             // save the citation
             if (!$cc->save($crna)) {
                 $results['error'][] = $crna;
             } else {
                 // tags
                 if ($this->tags && isset($tags)) {
                     $this->tag($user, $cc->id, $tags, '');
                 }
                 // badges
                 if ($this->badges && isset($badges)) {
                     $this->tag($user, $cc->id, $badges, 'badge');
                 }
                 // add the citattion to the saved
                 $results['saved'][] = $cc->id;
             }
         }
     }
     $this->cleanup();
     return $results;
 }
Beispiel #3
0
 /**
  * Remove one or more citations
  *
  * @return	void
  */
 public function removeTask()
 {
     // Incoming (we're expecting an array)
     $ids = Request::getVar('id', array());
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     // Make sure we have IDs to work with
     if (count($ids) > 0) {
         // Loop through the IDs and delete the citation
         $citation = new Citation($this->database);
         $assoc = new Association($this->database);
         $author = new Author($this->database);
         foreach ($ids as $id) {
             // Fetch and delete all the associations to this citation
             $assocs = $assoc->getRecords(array('cid' => $id));
             foreach ($assocs as $a) {
                 $assoc->delete($a->id);
             }
             // Fetch and delete all the authors to this citation
             $authors = $author->getRecords(array('cid' => $id));
             foreach ($authors as $a) {
                 $author->delete($a->id);
             }
             // Delete the citation
             $citation->delete($id);
             //citation tags
             $ct = new Tags($id);
             $ct->removeAll();
         }
         $message = Lang::txt('CITATION_REMOVED');
     } else {
         $message = Lang::txt('NO_SELECTION');
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, true), $message);
 }
Beispiel #4
0
 /**
  * Show the results of the import
  *
  * @return  void
  */
 public function savedTask()
 {
     // Get the session object
     $session = App::get('session');
     // Get the citations
     $citations_saved = $session->get('citations_saved');
     $citations_not_saved = $session->get('citations_not_saved');
     $citations_error = $session->get('citations_error');
     // Check to make sure we have citations
     if (!$citations_saved && !$citations_not_saved) {
         App::redirect(Route::url('index.php?option=com_citations&task=import'), Lang::txt('COM_CITATIONS_IMPORT_MISSING_FILE_CONTINUE'), 'error');
         return;
     }
     // Set the page title
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // Filters for gettiung just previously uploaded
     $filters = array('start' => 0, 'search' => '');
     // Instantiate a new view
     $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt(strtoupper($this->_option) . '_' . strtoupper($this->_task));
     $this->view->config = $this->config;
     $this->view->database = $this->database;
     $this->view->filters = $filters;
     $this->view->citations = array();
     foreach ($citations_saved as $cs) {
         $cc = new Citation($this->database);
         $cc->load($cs);
         $this->view->citations[] = $cc;
     }
     $this->view->openurl['link'] = '';
     $this->view->openurl['text'] = '';
     $this->view->openurl['icon'] = '';
     //take care fo type
     $ct = new Type($this->database);
     $this->view->types = $ct->getType();
     //get any messages
     $this->view->messages = Notify::messages('citations');
     //display view
     $this->view->display();
 }