Esempio n. 1
0
 /**
  * Import citations from a raw citation list to the object
  * described by the given association type and id.
  * @param $request Request
  * @param $assocType int
  * @param $assocId int
  * @param $rawCitationList string
  * @return integer the number of spawned citation checking processes
  */
 function importCitations(&$request, $assocType, $assocId, $rawCitationList)
 {
     assert(is_numeric($assocType) && is_numeric($assocId));
     $assocType = (int) $assocType;
     $assocId = (int) $assocId;
     // Remove existing citations.
     $this->deleteObjectsByAssocId($assocType, $assocId);
     // Tokenize raw citations
     import('lib.pkp.classes.citation.CitationListTokenizerFilter');
     $citationTokenizer = new CitationListTokenizerFilter();
     $citationStrings = $citationTokenizer->execute($rawCitationList);
     // Instantiate and persist citations
     $citations = array();
     if (is_array($citationStrings)) {
         foreach ($citationStrings as $seq => $citationString) {
             $citation = new Citation($citationString);
             // Initialize the citation with the raw
             // citation string.
             $citation->setRawCitation($citationString);
             // Set the object association
             $citation->setAssocType($assocType);
             $citation->setAssocId($assocId);
             // Set the counter
             $citation->setSeq($seq + 1);
             $this->insertObject($citation);
             $citations[$citation->getId()] = $citation;
             unset($citation);
         }
     }
     // Check new citations in parallel.
     $noOfProcesses = (int) Config::getVar('general', 'citation_checking_max_processes');
     $processDao =& DAORegistry::getDAO('ProcessDAO');
     return $processDao->spawnProcesses($request, 'api.citation.CitationApiHandler', 'checkAllCitations', PROCESS_TYPE_CITATION_CHECKING, $noOfProcesses);
 }
 /**
  * @covers CitationListTokenizerFilter
  */
 public function testCitationListTokenizerFilter()
 {
     $tokenizer = new CitationListTokenizerFilter();
     $rawCitationList = "\t1. citation1\n\n2 citation2\r\n 3) citation3\n[4]citation4";
     $expectedResult = array('citation1', 'citation2', 'citation3', 'citation4');
     self::assertEquals($expectedResult, $tokenizer->process($rawCitationList));
     $rawCitationList = '';
     self::assertEquals(array(), $tokenizer->process($rawCitationList));
 }
 /**
  * Import citations from the article
  * @param $args array
  * @param $request PKPRequest
  * @return string
  */
 function importCitations(&$args, &$request)
 {
     $article =& $this->getArticle();
     // Delete existing citations
     $citationDAO =& DAORegistry::getDAO('CitationDAO');
     $citationDAO->deleteCitationsByAssocId(ASSOC_TYPE_ARTICLE, $article->getId());
     // (Re-)import raw citations from the article
     $rawCitationList = $article->getCitations();
     import('citation.CitationListTokenizerFilter');
     $citationTokenizer = new CitationListTokenizerFilter();
     $citationStrings = $citationTokenizer->execute($rawCitationList);
     // Instantiate and persist citations
     import('citation.Citation');
     $citations = array();
     foreach ($citationStrings as $citationString) {
         $citation = new Citation($citationString);
         // Initialize the edited citation with the raw
         // citation string.
         $citation->setEditedCitation($citationString);
         // Set the article association
         $citation->setAssocType(ASSOC_TYPE_ARTICLE);
         $citation->setAssocId($article->getId());
         $citationDAO->insertCitation($citation);
         // FIXME: Database error handling.
         $citations[$citation->getId()] = $citation;
         unset($citation);
     }
     $this->setData($citations);
     // Re-display the grid
     $json = new JSON('true', $this->fetchGrid($args, $request));
     return $json->getString();
 }