Skip to content

Commit

Permalink
pkp/pkp-lib#2163 Handle issue and article cover images in entity props.
Browse files Browse the repository at this point in the history
- Moves coverImage props into OJS service classes.
- Delivers full URLs to cover images.
  • Loading branch information
NateWr committed Oct 19, 2017
1 parent 42fb1a4 commit 63e10ef
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
24 changes: 24 additions & 0 deletions classes/article/Article.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,30 @@ function getLocalizedCoverImageUrl() {

return $request->getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($this->getContextId()) . '/' . $coverImage;
}

/**
* Get full URLs all cover images
*
* @return array
*/
function getCoverImageUrls() {
$coverImages = $this->getCoverImage(null);
if (empty($coverImages)) {
return array();
}

$request = Application::getRequest();
import('classes.file.PublicFileManager');
$publicFileManager = new PublicFileManager();

$urls = array();

foreach ($coverImages as $locale => $coverImage) {
$urls[$locale] = sprintf('%s/%s/%s', $request->getBaseUrl(), $publicFileManager->getJournalFilesPath($this->getJournalId()), $coverImage);
}

return $urls;
}
}

?>
24 changes: 24 additions & 0 deletions classes/issue/Issue.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ function getLocalizedCoverImageUrl() {
return $request->getBaseUrl() . '/' . $publicFileManager->getJournalFilesPath($this->getJournalId()) . '/' . $coverImage;
}

/**
* Get the full URL to all localized cover images
*
* @return array
*/
function getCoverImageUrls() {
$coverImages = $this->getCoverImage(null);
if (empty($coverImages)) {
return array();
}

$request = Application::getRequest();
import('classes.file.PublicFileManager');
$publicFileManager = new PublicFileManager();

$urls = array();

foreach ($coverImages as $locale => $coverImage) {
$urls[$locale] = sprintf('%s/%s/%s', $request->getBaseUrl(), $publicFileManager->getJournalFilesPath($this->getJournalId()), $coverImage);
}

return $urls;
}

/**
* Set issue cover image alternate text
* @param $coverImageAltText string
Expand Down
2 changes: 1 addition & 1 deletion classes/services/IssueService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function getProperties($issue, $props, $args = null) {
}
break;
case 'coverImageUrl':
$values[$prop] = $issue->getCoverImage(null);
$values[$prop] = $issue->getCoverImageUrls(null);
break;
case 'coverImageAltText':
$values[$prop] = $issue->getCoverImageAltText(null);
Expand Down
11 changes: 10 additions & 1 deletion classes/services/SubmissionService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function modifyProperties($hookName, $args) {

$props[] = 'issueSummary';
$props[] = 'sectionSummary';
$props[] = 'coverImageUrl';
$props[] = 'coverImageAltText';

return $props;
}

/**
Expand Down Expand Up @@ -162,7 +166,6 @@ public function modifyPropertyValues($hookName, $args) {

$issue = null;
if ($publishedArticle) {
$articleId = $publishedArticle->getId();
$issueDao = \DAORegistry::getDAO('IssueDAO');
$issue = $issueDao->getById(
$publishedArticle->getIssueId(),
Expand All @@ -183,6 +186,12 @@ public function modifyPropertyValues($hookName, $args) {
$submission->getBestArticleId()
);
break;
case 'coverImageUrl':
$values[$prop] = $submission->getCoverImageUrls(null);
break;
case 'coverImageAltText':
$values[$prop] = $submission->getCoverImageAltText(null);
break;
case 'issue':
case 'issueSummary':
$values['issue'] = null;
Expand Down

0 comments on commit 63e10ef

Please sign in to comment.