Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1733 from ojs/hotfix/article-doi
Browse files Browse the repository at this point in the history
If doi is valid, it will be displayed on the article page
Hüseyin Mert authored Jan 5, 2017
2 parents 4076f5d + 65609bf commit 5df75dd
Showing 3 changed files with 45 additions and 8 deletions.
23 changes: 23 additions & 0 deletions src/Ojs/CoreBundle/Service/Twig/OjsExtension.php
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
namespace Ojs\CoreBundle\Service\Twig;

use Doctrine\ORM\EntityManager;
use GuzzleHttp\Client;
use Ojs\CoreBundle\Events\TwigEvent;
use Ojs\CoreBundle\Params\ArticleFileParams;
use Ojs\CoreBundle\Params\IssueDisplayModes;
@@ -136,6 +137,7 @@ public function getFunctions()
new \Twig_SimpleFunction('issueTextGenerate', array($this, 'issueTextGenerate')),
new \Twig_SimpleFunction('getAuthorsInfo', array($this, 'getAuthorsInfo'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('getStrToUpper', array($this, 'getStrToUpper'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('isDoiValid', array($this, 'isDoiValid')),
);
}

@@ -571,4 +573,25 @@ public function getName()
{
return 'ojs_extension';
}

/**
* @param $doi
* @return bool
*/
public function isDoiValid($doi)
{
try {
$client = new Client();
$doi = $client->get('http://doi.org/api/handles/'.$doi);
$doi = json_decode($doi);

if($doi['responseCode'] == 1){
return true;
}
return false;

} catch(\Exception $e) {
return false;
}
}
}
13 changes: 13 additions & 0 deletions src/Ojs/JournalBundle/Entity/Article.php
Original file line number Diff line number Diff line change
@@ -1310,6 +1310,19 @@ public function getDoiStatus()
return $this->doiStatus;
}

/**
* @return boolean
*/
public function isDoiValid()
{
if ($this->getDoiStatus() == DoiStatuses::VALID)
{
return true;
}

return false;
}

/**
* @param int $doiStatus
* @return Article
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends '::ojsbase.html.twig' %}
{% block title %}{{ 'title.article'|trans }} {{ parent() }}{% endblock %}
{% set hideleft = 1 %}
{% set isDoiValid = article.isDoiValid %}

{% block breadcrumb %}
{% if article.issue %}
@@ -157,7 +158,7 @@

<hr/>

{% if article.doi is not empty %}
{% if article.doi is not empty and isDoiValid %}
<div id="doiInfo">
<p class="text-success">
<a href="http://dx.doi.org/{{ article.doi }}">{{ 'doi'|trans }}: {{ article.doi }}</a>
@@ -270,7 +271,7 @@
{{ bibtex_data.title }}.
{{ bibtex_data.journal }}, {% if article.issue %}{{ article.issue.volume }} ({{ article.issue.number }}){% endif %},
{% if article.firstPage is not null and article.lastPage is not null %}{{ article.firstPage }}-{{ article.lastPage }}{% endif %}.
{% if article.doi is not empty %}DOI: {{ article.doi }}{% else %}Retrieved from {{ app.request.schemeAndHttpHost ~ app.request.requestUri }}{% endif %}
{% if article.doi is not empty and isDoiValid %}DOI: {{ article.doi }}{% else %}Retrieved from {{ app.request.schemeAndHttpHost ~ app.request.requestUri }}{% endif %}
</td>
</tr>
<tr>
@@ -313,8 +314,8 @@
{% endif %}
Y1 - {{ article.pubDate|date("Y") }}
PY - {{ article.pubDate|date("Y") }}
N1 - doi: {{ article.doi }}
DO - {{ article.doi }}
N1 - {% if article.doi is not empty and isDoiValid %} doi: {{ article.doi }} {% endif %}
DO - {% if article.doi is not empty and isDoiValid %} {{ article.doi }} {% endif %}
T2 - {{ article.journal }}
JF - Journal
JO - JOR
@@ -323,8 +324,8 @@
VL - {{ article.issue.volume }}
IS - {{ article.issue.number }}
SN - {{ article.journal.issn }}-{{ article.journal.eissn }}
M3 - doi: {{ article.doi }}
UR - http://dx.doi.org/{{ article.doi }}
M3 - {% if article.doi is not empty and isDoiValid %} doi: {{ article.doi }} {% endif %}
UR - {% if article.doi is not empty and isDoiValid %} http://dx.doi.org/{{ article.doi }} {% endif %}
Y2 - {{ article.acceptanceDate|date("Y") }}
ER -

@@ -346,8 +347,8 @@
%P {{ article.journal.issn }}-{{ article.journal.eissn }}
%V {{ article.issue.volume }}
%N {{ article.issue.number }}
%R doi: {{ article.doi }}
%U {{ article.doi }}
%R {% if article.doi is not empty and isDoiValid %} doi: {{ article.doi }} {% endif %}
%U {% if article.doi is not empty and isDoiValid %} {{ article.doi }} {% endif %}
</td>
</tr>
</table>

0 comments on commit 5df75dd

Please sign in to comment.