Skip to content

Commit

Permalink
Citations return type as object (class) instead of array
Browse files Browse the repository at this point in the history
  • Loading branch information
GaziYucel committed May 21, 2024
1 parent d3a3cad commit a2235b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
9 changes: 3 additions & 6 deletions classes/Db/PluginDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ public function getCitations(Publication|null $publication): array
true
);

if (empty($citationsIn) || json_last_error() !== JSON_ERROR_NONE)
return [];
if (empty($citationsIn) || json_last_error() !== JSON_ERROR_NONE) return [];

$citationsOut = [];

foreach ($citationsIn as $citation) {
if (!empty($citation) && (is_object($citation) || is_array($citation))) {
$citationsOut[] =
ClassHelper::getClassAsArrayWithValuesAssigned(new CitationModel(), $citation);
}
if (!empty($citation) && (is_object($citation) || is_array($citation)))
$citationsOut[] = ClassHelper::getClassWithValuesAssigned(new CitationModel(), $citation);
}

return $citationsOut;
Expand Down
12 changes: 6 additions & 6 deletions classes/FrontEnd/ArticleView.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ public function getCitationsAsHtml(int $publicationId): string

$count = count($citations);
for ($i = 0; $i < $count; $i++) {
$citationOut = $this->getCitationWithLinks($citations[$i]['raw']);
$citationOut = $this->getCitationWithLinks($citations[$i]->raw);

if ($citations[$i]['isProcessed']) $citationOut = $this->getSingleCitationAsHtml($citations[$i]);
if ($citations[$i]->isProcessed) $citationOut = $this->getSingleCitationAsHtml($citations[$i]);

$output .= '<p>' . $citationOut . '</p>';
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public function getSingleCitationAsHtml($citation): string

// authors
$orcidUrl = "<a href='" . Orcid::prefix . "/{orcid}' target='_blank' class=''><span>{name}</span></a>";
foreach ($citation['authors'] as $author) {
foreach ($citation->authors as $author) {
if (!empty($author['orcid_id'])) {
$out .= " " . str_replace(
['{orcid}', '{name}'],
Expand All @@ -198,9 +198,9 @@ public function getSingleCitationAsHtml($citation): string
$wikiDataUrl = "<a href='" . Wikidata::prefix . "/{wikidata_id}' target='_blank' class='citationManager-Button citationManager-ButtonGreen'><span>Wikidata</span></a>";
$openAlexUrl = "<a href='" . OpenAlex::prefix . "/{openalex_id}' target='_blank' class='citationManager-Button citationManager-ButtonGreen'><span>OpenAlex</span></a>";

if (!empty($citation['doi'])) $out .= " " . str_replace('{doi}', $citation['doi'], $doiUrl);
if (!empty($citation['wikidata_id'])) $out .= " " . str_replace('{wikidata_id}', $citation['wikidata_id'], $wikiDataUrl);
if (!empty($citation['openalex_id'])) $out .= " " . str_replace('{openalex_id}', $citation['openalex_id'], $openAlexUrl);
if (!empty($citation->doi)) $out .= " " . str_replace('{doi}', $citation->doi, $doiUrl);
if (!empty($citation->wikidata_id)) $out .= " " . str_replace('{wikidata_id}', $citation->wikidata_id, $wikiDataUrl);
if (!empty($citation->openalex_id)) $out .= " " . str_replace('{openalex_id}', $citation->openalex_id, $openAlexUrl);

$out .= '<!-- structured -->';

Expand Down

0 comments on commit a2235b5

Please sign in to comment.