public function testCitationCrud()
 {
     $nameSchema = new NlmNameSchema();
     $nameDescription = new MetadataDescription($nameSchema, ASSOC_TYPE_AUTHOR);
     $nameDescription->addStatement('given-names', $value = 'Peter');
     $nameDescription->addStatement('given-names', $value = 'B');
     $nameDescription->addStatement('surname', $value = 'Bork');
     $nameDescription->addStatement('prefix', $value = 'Mr.');
     $citationSchema = new NlmCitationSchema();
     $citationDescription = new MetadataDescription($citationSchema, ASSOC_TYPE_CITATION);
     $citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in Kürze', 'de_DE');
     $citationDescription->addStatement('date', $value = '2009-08-17');
     $citationDescription->addStatement('size', $value = 320);
     $citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
     $citation = new Citation('raw citation');
     $citation->setAssocType(ASSOC_TYPE_ARTICLE);
     $citation->setAssocId(5);
     $citation->setEditedCitation('edited citation');
     $citation->setParseScore(50);
     $citation->injectMetadata($citationDescription);
     $citationId = $this->citationDAO->insertCitation($citation);
     self::assertTrue(is_numeric($citationId));
     self::assertTrue($citationId > 0);
 }
 public function testCitationCrud()
 {
     $nameSchema = new NlmNameSchema();
     $nameDescription = new MetadataDescription($nameSchema, ASSOC_TYPE_AUTHOR);
     $nameDescription->addStatement('given-names', $value = 'Peter');
     $nameDescription->addStatement('given-names', $value = 'B');
     $nameDescription->addStatement('surname', $value = 'Bork');
     $nameDescription->addStatement('prefix', $value = 'Mr.');
     $citationSchema = new NlmCitationSchema();
     $citationDescription = new MetadataDescription($citationSchema, ASSOC_TYPE_CITATION);
     $citationDescription->addStatement('person-group[@person-group-type="author"]', $nameDescription);
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in a nutshell', 'en_US');
     $citationDescription->addStatement('article-title', $value = 'PHPUnit in Kürze', 'de_DE');
     $citationDescription->addStatement('date', $value = '2009-08-17');
     $citationDescription->addStatement('size', $value = 320);
     $citationDescription->addStatement('uri', $value = 'http://phpunit.org/nutshell');
     $citation = new Citation('raw citation');
     $citation->setAssocType(ASSOC_TYPE_ARTICLE);
     $citation->setAssocId(999999);
     $citation->setEditedCitation('edited citation');
     $citation->setParseScore(50);
     $citation->injectMetadata($citationDescription);
     // Create citation
     $citationId = $this->citationDAO->insertCitation($citation);
     self::assertTrue(is_numeric($citationId));
     self::assertTrue($citationId > 0);
     // Retrieve citation
     $citationById = $this->citationDAO->getCitation($citationId);
     $citationById->getMetadataFieldNames();
     // Initializes internal state for comparison.
     self::assertEquals($citation, $citationById);
     $citationsByAssocIdDaoFactory = $this->citationDAO->getCitationsByAssocId(ASSOC_TYPE_ARTICLE, 999999);
     $citationsByAssocId = $citationsByAssocIdDaoFactory->toArray();
     self::assertEquals(1, count($citationsByAssocId));
     $citationsByAssocId[0]->getMetadataFieldNames();
     // Initializes internal state for comparison.
     self::assertEquals($citation, $citationsByAssocId[0]);
     // Update citation
     $citationDescription->removeStatement('date');
     $citationDescription->addStatement('article-title', $value = 'PHPUnit rápido', 'pt_BR');
     $updatedCitation = new Citation('another raw citation');
     $updatedCitation->setId($citationId);
     $updatedCitation->setAssocType(ASSOC_TYPE_ARTICLE);
     $updatedCitation->setAssocId(999998);
     $updatedCitation->setEditedCitation('another edited citation');
     $updatedCitation->setParseScore(50);
     $updatedCitation->injectMetadata($citationDescription);
     $this->citationDAO->updateCitation($updatedCitation);
     $citationAfterUpdate = $this->citationDAO->getCitation($citationId);
     $citationAfterUpdate->getMetadataFieldNames();
     // Initializes internal state for comparison.
     self::assertEquals($updatedCitation, $citationAfterUpdate);
     // Delete citation
     $this->citationDAO->deleteCitationsByAssocId(ASSOC_TYPE_ARTICLE, 999998);
     self::assertNull($this->citationDAO->getCitation($citationId));
 }
 /**
  * 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();
 }