Skip to content

Commit

Permalink
#24 Save raw citations
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Aug 27, 2020
1 parent e5e2163 commit 0434f6a
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions JatsParserPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function register($category, $path, $mainContextId = null) {
HookRegistry::register('TemplateManager::display', array($this, 'themeSpecificStyles'));
HookRegistry::register('Form::config::before', array($this, 'addCitationsFormFields'));
HookRegistry::register('Publication::edit', array($this, 'editPublicationReferences'));
HookRegistry::register('citationdao::getAdditionalFieldNames', array($this, 'citationFieldNames'));

return true;
}
Expand Down Expand Up @@ -656,42 +655,21 @@ function editPublicationReferences(string $hookname, array $args) {
* @param HTMLDocument $htmlDocument
* @param Publication $newPublication
* @return void
* @brief used instead of CitationDAO::importCitations
* @brief saves parsed citeproc references as raw citations
*/
private function _importCitations(HTMLDocument $htmlDocument, Publication $newPublication): void {
$refs = $htmlDocument->getRawReferences();
$publicationId = $newPublication->getId();
$citationDao = DAORegistry::getDAO('CitationDAO'); /** @var $citationDao CitationDAO */

$citationDao->deleteByPublicationId($publicationId);
$cslRefs = $htmlDocument->citeProcReferences;
$idColumn = array_column($cslRefs, 'id');
$seq = 0;
$rawCitations = '';

foreach ($refs as $key => $ref) {
$citation = new Citation($ref);
$citation->setData('publicationId', $publicationId);
$citation->setSequence(++$seq);

$cslKey = array_search($key, $idColumn);
if ($cslKey !== false) {
$citation->setData('jatsParser::csl', $cslRefs[$cslKey]);
}

$citationDao->insertObject($citation);
$rawCitations .= $ref . "\n";
}
}

/**
* @param $hookname string
* @param $args array
* @return bool
*/
function citationFieldNames($hookname, $args) {
$fields =& $args[1];
$fields[] = 'jatsParser::csl';

return false;
$newPublication->setData('citationsRaw', $rawCitations);
}

/**
Expand Down

0 comments on commit 0434f6a

Please sign in to comment.