| Server IP : 127.0.1.1 / Your IP : 216.73.216.60 Web Server : Apache/2.4.58 (Ubuntu) System : Linux nepub 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/public_html/plugins/generic/dataverse/classes/ |
Upload File : |
<?php
class APACitation
{
private $locale;
public function getCitationAsMarkupByStudy(DataverseStudy $study): string
{
$href = '<a href="'. $study->getPersistentUri() .'">'. $study->getPersistentUri() .'</a>';
return str_replace($study->getPersistentUri(), $href, strip_tags($study->getDataCitation()));
}
public function getFormattedCitationBySubmission(Submission $submission): string
{
$this->locale = $submission->getLocale();
$journalDao = DAORegistry::getDAO('JournalDAO');
$journal = $journalDao->getById($submission->getContextId());
$publication = $submission->getCurrentPublication();
$authors = $publication->getData('authors');
$submittedDate = new DateTime($submission->getDateSubmitted());
$submissionCitation = $this->createAuthorsCitationAPA($authors) . ' ';
$submissionCitation .= '(' . date_format($submittedDate, 'Y') . '). ';
$submissionCitation .= '<em>' . $submission->getLocalizedTitle($submission->getLocale()) . '</em>. ';
$submissionCitation .= $journal->getLocalizedName();
return $submissionCitation;
}
public function createAuthorsCitationAPA(array $authors): string
{
$authorsCitation = '';
$authorsNumbers = count($authors);
if ($authorsNumbers > 5) {
$authorsCitation .= $this->getAuthorCitation($authors[0]) . ' et al.';
} else {
foreach ($authors as $key => $author) {
if ($key == 0) {
$authorsCitation .= $this->getAuthorCitation($author);
}
if ($authorsNumbers > 1) {
if ($key != 0 && $key < ($authorsNumbers - 1)) {
$authorsCitation .= ', ' . $this->getAuthorCitation($author);
}
if ($key == ($authorsNumbers - 1)) {
$authorsCitation .= ', & ' . $this->getAuthorCitation($author);
}
}
}
}
return $authorsCitation;
}
private function getAuthorCitation(Author $author): string
{
$familyName = $author->getLocalizedFamilyName($this->locale);
$givenName = $author->getLocalizedGivenName($this->locale);
if (is_array($familyName)) {
$familyName = $familyName[$this->locale];
}
if (is_array($givenName)) {
$givenName = $givenName[$this->locale];
}
return $familyName . ', ' . mb_substr($givenName, 0, 1) . ".";
}
}