Skip to content

Commit

Permalink
pkp/pkp-lib#2163 initial work for new entity properties list support
Browse files Browse the repository at this point in the history
  • Loading branch information
kaschioudi authored and NateWr committed Oct 19, 2017
1 parent 6dc9da9 commit 6cebe21
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 78 deletions.
2 changes: 1 addition & 1 deletion api/v1/galleys/GalleysHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getGalley($slimRequest, $response, $args) {
$submissionFile = $galley->getFile();
$urlData = array(
'submissionId' => $this->getParameter('submissionId'),
'revision' => $submissionFile->getRevision(),
'revision' => $submissionFile->getRevision(),
);

$uri = "/{$contextPath}/api/{$version}/files/{$fileId}?" . http_build_query($urlData);
Expand Down
81 changes: 5 additions & 76 deletions api/v1/submissions/SubmissionHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,84 +260,13 @@ public function getSubmission($slimRequest, $response, $args) {
$journal = $request->getJournal();

$submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
$publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
$publishedArticle = $publishedArticleDao->getPublishedArticleByBestArticleId((int) $journal->getId(), $submission->getId(), true);

// simply return basic metadata for unpublished submissions
if (!isset($publishedArticle)) {
return $response->withJson($this->submissionMetadata($slimRequest, $response, $args), 200);
}

$articleId = $publishedArticle->getId();
$issueDao = DAORegistry::getDAO('IssueDAO');
$issue = $issueDao->getById($publishedArticle->getIssueId(), $publishedArticle->getJournalId(), true);

$sectionDao = DAORegistry::getDAO('SectionDAO');
$section = $sectionDao->getById($publishedArticle->getSectionId(), $journal->getId(), true);

// public identifiers
$pubIdPlugins = PluginRegistry::loadCategory('pubIds', true);
$pubIds = array_map(function($pubIdPlugin) use($issue, $publishedArticle, $journal) {
if ($pubIdPlugin->getPubIdType() != 'doi')
return;
$doiUrl = null;
$pubId = $issue->getPublished() ?
$publishedArticle->getStoredPubId($pubIdPlugin->getPubIdType()) :
$pubIdPlugin->getPubId($publishedArticle);
if($pubId) {
$doiUrl = $pubIdPlugin->getResolvingURL($journal->getId(), $pubId);
}

return array(
'pubId' => $pubId,
'doiUrl' => $doiUrl,
);
}, $pubIdPlugins);

$authors = array_map(function($author) {
return array(
'name' => $author->getFullName(),
'affiliation' => $author->getLocalizedAffiliation(),
'orcid' => $author->getOrcid(),
);
}, $publishedArticle->getAuthors());

$coverImage = $publishedArticle->getLocalizedCoverImage() ?
$publishedArticle->getLocalizedCoverImageUrl() :
$issue->getLocalizedCoverImageUrl();

$galleys = array_map(function($galley) use ($context, $request, $dispatcher, $articleId) {
$url = null;
if ($galley->getRemoteURL()) {
$url = $galley->getRemoteURL();
}
else {
$url = $dispatcher->url($request, ROUTE_PAGE, $context, 'article', 'download',
array($articleId, $galley->getBestGalleyId()));
}
return array(
'id' => $galley->getBestGalleyId(),
'label' => $galley->getGalleyLabel(),
'filetype' => $galley->getFileType(),
'url' => $url,
);
}, $publishedArticle->getGalleys());

$data = array(
'issueId' => $issue->getId(),
'issue' => $issue->getIssueIdentification(),
'section' => $section->getLocalizedTitle(),
'title' => $publishedArticle->getLocalizedTitle(),
'subtitle' => $publishedArticle->getLocalizedSubtitle(),
'authors' => $authors,
'pubIds' => $pubIds,
'abstract' => $publishedArticle->getLocalizedAbstract(),
'citations' => $publishedArticle->getCitations(),
'cover_image' => $coverImage,
'galleys' => $galleys,
'datePublished' => $publishedArticle->getDatePublished(),
import('classes.core.ServicesContainer');
$args = array(
'journal' => $journal,
'slimRequest' => $slimRequest
);

$data = ServicesContainer::instance()->get('submission')->getFullProperties($submission, $args);
return $response->withJson($data, 200);
}
}
29 changes: 29 additions & 0 deletions classes/services/AuthorService.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* @file classes/services/AuthorService.php
*
* Copyright (c) 2014-2017 Simon Fraser University
* Copyright (c) 2000-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class AuthorService
* @ingroup services
*
* @brief Extends the base author helper service class with app-specific
* requirements.
*/

namespace OJS\Services;

use \PKP\Services\PKPAuthorService;

class AuthorService extends PKPAuthorService {

/**
* Constructor
*/
public function __construct() {
parent::__construct();
}
}
90 changes: 90 additions & 0 deletions classes/services/GalleyService.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/**
* @file classes/services/GalleyService.php
*
* Copyright (c) 2014-2017 Simon Fraser University
* Copyright (c) 2000-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class GalleyService
* @ingroup services
*
* @brief Helper class that encapsulates galley business logic
*/

namespace OJS\Services;

use \PKP\Services\EntityProperties\PKPBaseEntityPropertyService;

class GalleyService implements PKPBaseEntityPropertyService {

/**
* Constructor
*/
public function __construct() {
parent::__construct($this);
}

/**
* @copydoc \PKP\Services\EntityProperties\EntityPropertyInterface::getProperties()
*/
public function getProperties($galley, $props, $args = null) {
$values = array();
foreach ($props as $prop) {
switch ($prop) {
case 'id':
$values[$prop] = $galley->getId();
break;
case '_href':
$values[$prop] = $galley->getId();
break;
// case 'parent':
// $values[$prop] = $galley->getId();
// break;
case 'locale':
$values[$prop] = $galley->getId();
break;
case 'label':
$values[$prop] = $galley->getName(null);
break;
case 'remoteUrl':
$values[$prop] = $galley->getRemoteURL();
break;
// case 'publishedUrl':
// $values[$prop] = $galley->getId();
// break;
case 'seq':
case 'sequence':
$values[$prop] = $galley->getSequence();
break;
default:
$this->getUnknownProperty($galley, $prop, $values);
}
}

return $values;
}

/**
* @copydoc \PKP\Services\EntityProperties\EntityPropertyInterface::getSummaryProperties()
*/
public function getSummaryProperties($galley, $args = null) {
$props = array (
'id','_href','parent','locale','label','seq','remoteUrl','publishedUrl'
);
$props = $this->getSummaryPropertyList($galley, $props);
return $this->getProperties($galley, $props);
}

/**
* @copydoc \PKP\Services\EntityProperties\EntityPropertyInterface::getFullProperties()
*/
public function getFullProperties($galley, $args = null) {
$props = array (
'id','_href','parent','locale','label','seq','remoteUrl','publishedUrl'
);
$props = $this->getFullPropertyList($galley, $props);
return $this->getProperties($galley, $props);
}
}
148 changes: 147 additions & 1 deletion classes/services/IssueService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@

namespace OJS\Services;

class IssueService {
use \Journal;
use \PKP\Services\EntityProperties\PKPBaseEntityPropertyService;

class IssueService extends PKPBaseEntityPropertyService {

/**
* Constructor
*/
public function __construct() {
parent::__construct($this);
}

/**
* Determine if a user can access galleys for a specific issue
Expand All @@ -35,4 +45,140 @@ public function userHasAccessToGalleys(\Journal $journal, \Issue $issue) {

return !$subscriptionRequired || $issue->getAccessStatus() == ISSUE_ACCESS_OPEN || $subscribedUser || $subscribedDomain;
}

/**
* Determine issue access status based on journal publishing mode
* @param \Journal $journal
*
* @return int
*/
public function determineAccessStatus(Journal $journal) {
import('classes.issue.Issue');
$accessStatus = null;

switch ($journal->getSetting('publishingMode')) {
case PUBLISHING_MODE_SUBSCRIPTION:
case PUBLISHING_MODE_NONE:
$accessStatus = ISSUE_ACCESS_SUBSCRIPTION;
break;
case PUBLISHING_MODE_OPEN:
default:
$accessStatus = ISSUE_ACCESS_OPEN;
break;
}

return $accessStatus;
}

/**
* @copydoc \PKP\Services\EntityProperties\EntityPropertyInterface::getProperties()
*/
public function getProperties($issue, $props, $args = null) {
$values = array();
foreach ($props as $prop) {
switch ($prop) {
case 'id':
$values[$prop] = (int) $issue->getId();
break;
case '_href':
$values[$prop] = null;
$slimRequest = $args['slimRequest'];
if ($slimRequest) {
$route = $slimRequest->getAttribute('route');
$arguments = $route->getArguments();
$href = "/{$arguments['contextPath']}/api/{$arguments['version']}/issues/" . $issue->getIssue();
$values[$prop] = $href;
}
break;
case 'title':
$values[$prop] = $issue->getTitle(null);
break;
case 'description':
$values[$prop] = $issue->getDescription(null);
break;
case 'identification':
$values[$prop] = $issue->getIssueIdentification();
break;
case 'volume':
$values[$prop] = (int) $issue->getVolume();
break;
case 'number':
$values[$prop] = $issue->getNumber();
break;
case 'year':
$values[$prop] = (int) $issue->getYear();
break;
case 'isPublished':
$values[$prop] = (bool) $issue->isPublished();
break;
case 'isCurrent':
$values[$prop] = (bool) $issue->getCurrent();
break;
case 'datePublished':
$values[$prop] = $issue->getDatePublished();
break;
case 'dateNotified':
$values[$prop] = $issue->getDateNotified();
break;
case 'lastModified':
$values[$prop] = $issue->getLastModified();
break;
// case 'publishedUrl':
// $values[$prop] = (int) $issue->getYear();
// break;
// case 'articles':
// $values[$prop] = $issue->getIssueIdentification();
// break;
// case 'sections':
// $values[$prop] = (int) $issue->getVolume();
// break;
// case 'tableOfContents':
// $values[$prop] = $issue->getNumber();
// break;
// case 'galleys':
// $values[$prop] = (int) $issue->getYear();
// break;
// case 'doi':
// $values[$prop] = $issue->getId();
// break;
case 'coverImageUrl':
$values[$prop] = $issue->getCoverImageUrl(null);
break;
case 'coverImageAltText':
$values[$prop] = $issue->getCoverImageAltText(null);
break;
// case 'galleys':
// case 'galleysSummary':
// $values[$prop] = $issue->getId();
// break;
default:
$this->getUnknownProperty($author, $prop, $values);
}
}

return $values;
}

/**
* @copydoc \PKP\Services\EntityProperties\EntityPropertyInterface::getSummaryProperties()
*/
public function getSummaryProperties($author, $args = null) {
$props = array (
'id','_href','title','description','identification','volume','number','year','doi','coverImageUrl',
'coverImageAltText','galleysSummary'
);
$props = $this->getSummaryPropertyList($author, $props);
return $this->getProperties($author, $props);
}

/**
* @copydoc \PKP\Services\EntityProperties\EntityPropertyInterface::getFullProperties()
*/
public function getFullProperties($author, $args = null) {
$props = array (
'id'
);
$props = $this->getFullPropertyList($author, $props);
return $this->getProperties($author, $props);
}
}
Loading

0 comments on commit 6cebe21

Please sign in to comment.