Open Journal Systems  3.3.0
IssueService.inc.php
1 <?php
2 
16 namespace APP\Services;
17 
18 use \Journal;
19 use \Services;
20 use \DBResultRange;
21 use \DAORegistry;
22 use \DAOResultFactory;
23 use \PKP\Services\interfaces\EntityPropertyInterface;
24 use \PKP\Services\interfaces\EntityReadInterface;
25 use \APP\Services\QueryBuilders\IssueQueryBuilder;
26 
27 class IssueService implements EntityPropertyInterface, EntityReadInterface {
28 
32  public function get($issueId) {
33  $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
34  return $issueDao->getById($issueId);
35  }
36 
40  public function getCount($args = []) {
41  return $this->getQueryBuilder($args)->getCount();
42  }
43 
47  public function getIds($args = []) {
48  return $this->getQueryBuilder($args)->getIds();
49  }
50 
71  public function getMany($args = []) {
72  $range = null;
73  if (isset($args['count'])) {
74  import('lib.pkp.classes.db.DBResultRange');
75  $range = new \DBResultRange($args['count'], null, isset($args['offset']) ? $args['offset'] : 0);
76  }
77  // Pagination is handled by the DAO, so don't pass count and offset
78  // arguments to the QueryBuilder.
79  if (isset($args['count'])) unset($args['count']);
80  if (isset($args['offset'])) unset($args['offset']);
81  $issueListQO = $this->getQueryBuilder($args)->getQuery();
82  $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
83  $result = $issueDao->retrieveRange($issueListQO->toSql(), $issueListQO->getBindings(), $range);
84  $queryResults = new DAOResultFactory($result, $issueDao, '_fromRow');
85 
86  return $queryResults->toIterator();
87  }
88 
92  public function getMax($args = []) {
93  // Don't accept args to limit the results
94  if (isset($args['count'])) unset($args['count']);
95  if (isset($args['offset'])) unset($args['offset']);
96  return $this->getQueryBuilder($args)->getCount();
97  }
98 
103  public function getQueryBuilder($args = []) {
104 
105  $defaultArgs = array(
106  'contextId' => CONTEXT_ID_NONE,
107  'orderBy' => 'datePublished',
108  'orderDirection' => 'DESC',
109  'isPublished' => null,
110  'volumes' => null,
111  'numbers' => null,
112  'years' => null,
113  'searchPhrase' => '',
114  );
115 
116  $args = array_merge($defaultArgs, $args);
117 
118  $issueListQB = new IssueQueryBuilder();
119  $issueListQB
120  ->filterByContext($args['contextId'])
121  ->orderBy($args['orderBy'], $args['orderDirection'])
122  ->filterByPublished($args['isPublished'])
123  ->filterByVolumes($args['volumes'])
124  ->filterByNumbers($args['numbers'])
125  ->filterByYears($args['years'])
126  ->searchPhrase($args['searchPhrase']);
127 
128  if (isset($args['count'])) {
129  $issueListQB->limitTo($args['count']);
130  }
131 
132  if (isset($args['offset'])) {
133  $issueListQB->offsetBy($args['count']);
134  }
135 
136  \HookRegistry::call('Issue::getMany::queryBuilder', array($issueListQB, $args));
137 
138  return $issueListQB;
139  }
140 
149  public function userHasAccessToGalleys(\Journal $journal, \Issue $issue) {
150  import('classes.issue.IssueAction');
151  $issueAction = new \IssueAction();
152 
153  $subscriptionRequired = $issueAction->subscriptionRequired($issue, $journal);
154  $subscribedUser = $issueAction->subscribedUser($journal, $issue);
155  $subscribedDomain = $issueAction->subscribedDomain($journal, $issue);
156 
157  return !$subscriptionRequired || $issue->getAccessStatus() == ISSUE_ACCESS_OPEN || $subscribedUser || $subscribedDomain;
158  }
159 
166  public function determineAccessStatus(Journal $journal) {
167  import('classes.issue.Issue');
168  $accessStatus = null;
169 
170  switch ($journal->getData('publishingMode')) {
171  case PUBLISHING_MODE_SUBSCRIPTION:
172  case PUBLISHING_MODE_NONE:
173  $accessStatus = ISSUE_ACCESS_SUBSCRIPTION;
174  break;
175  case PUBLISHING_MODE_OPEN:
176  default:
177  $accessStatus = ISSUE_ACCESS_OPEN;
178  break;
179  }
180 
181  return $accessStatus;
182  }
183 
187  public function getProperties($issue, $props, $args = null) {
188  \PluginRegistry::loadCategory('pubIds', true);
189  $request = $args['request'];
190  $context = $request->getContext();
191  $dispatcher = $request->getDispatcher();
192  $router = $request->getRouter();
193  $values = array();
194 
195  foreach ($props as $prop) {
196  switch ($prop) {
197  case 'id':
198  $values[$prop] = (int) $issue->getId();
199  break;
200  case '_href':
201  $values[$prop] = null;
202  if (!empty($args['slimRequest'])) {
203  $route = $args['slimRequest']->getAttribute('route');
204  $arguments = $route->getArguments();
205  $values[$prop] = $dispatcher->url(
206  $args['request'],
207  ROUTE_API,
208  $arguments['contextPath'],
209  'issues/' . $issue->getId()
210  );
211  }
212  break;
213  case 'title':
214  $values[$prop] = $issue->getTitle(null);
215  break;
216  case 'description':
217  $values[$prop] = $issue->getDescription(null);
218  break;
219  case 'identification':
220  $values[$prop] = $issue->getIssueIdentification();
221  break;
222  case 'volume':
223  $values[$prop] = (int) $issue->getVolume();
224  break;
225  case 'number':
226  $values[$prop] = $issue->getNumber();
227  break;
228  case 'year':
229  $values[$prop] = (int) $issue->getYear();
230  break;
231  case 'isCurrent':
232  $values[$prop] = (bool) $issue->getCurrent();
233  break;
234  case 'datePublished':
235  $values[$prop] = $issue->getDatePublished();
236  break;
237  case 'dateNotified':
238  $values[$prop] = $issue->getDateNotified();
239  break;
240  case 'lastModified':
241  $values[$prop] = $issue->getLastModified();
242  break;
243  case 'publishedUrl':
244  $values[$prop] = null;
245  if ($context) {
246  $values[$prop] = $dispatcher->url(
247  $request,
248  ROUTE_PAGE,
249  $context->getPath(),
250  'issue',
251  'view',
252  $issue->getBestIssueId()
253  );
254  }
255  break;
256  case 'articles':
257  $values[$prop] = array();
258  $submissionsIterator = Services::get('submission')->getMany([
259  'contextId' => $issue->getJournalId(),
260  'issueIds' => $issue->getId(),
261  'count' => 1000, // large upper limit
262  ]);
263  foreach ($submissionsIterator as $submission) {
264  $values[$prop][] = \Services::get('submission')->getSummaryProperties($submission, $args);
265  }
266  break;
267  case 'sections':
268  $values[$prop] = array();
269  $sectionDao = \DAORegistry::getDAO('SectionDAO');
270  $sections = $sectionDao->getByIssueId($issue->getId());
271  if (!empty($sections)) {
272  foreach ($sections as $section) {
273  $sectionProperties = \Services::get('section')->getSummaryProperties($section, $args);
274  $customSequence = $sectionDao->getCustomSectionOrder($issue->getId(), $section->getId());
275  if ($customSequence) {
276  $sectionProperties['seq'] = $customSequence;
277  }
278  $values[$prop][] = $sectionProperties;
279  }
280  }
281  break;
282  case 'coverImageUrl':
283  $values[$prop] = $issue->getCoverImageUrls(null);
284  break;
285  case 'coverImageAltText':
286  $values[$prop] = $issue->getCoverImageAltText(null);
287  break;
288  case 'galleys':
289  case 'galleysSummary';
290  $data = array();
291  $issueGalleyDao = \DAORegistry::getDAO('IssueGalleyDAO');
292  $galleys = $issueGalleyDao->getByIssueId($issue->getId());
293  if ($galleys) {
294  $galleyArgs = array_merge($args, array('issue' => $issue));
295  foreach ($galleys as $galley) {
296  $data[] = ($prop === 'galleys')
297  ? \Services::get('galley')->getFullProperties($galley, $galleyArgs)
298  : \Services::get('galley')->getSummaryProperties($galley, $galleyArgs);
299  }
300  }
301  $values['galleys'] = $data;
302  break;
303  }
304  }
305 
306  $values = Services::get('schema')->addMissingMultilingualValues(SCHEMA_ISSUE, $values, $context->getSupportedFormLocales());
307 
308  \HookRegistry::call('Issue::getProperties::values', array(&$values, $issue, $props, $args));
309 
310  ksort($values);
311 
312  return $values;
313  }
314 
318  public function getSummaryProperties($issue, $args = null) {
319  $props = array (
320  'id','_href','title','description','identification','volume','number','year',
321  'datePublished', 'publishedUrl', 'coverImageUrl','coverImageAltText','galleysSummary',
322  );
323 
324  \HookRegistry::call('Issue::getProperties::summaryProperties', array(&$props, $issue, $args));
325 
326  return $this->getProperties($issue, $props, $args);
327  }
328 
332  public function getFullProperties($issue, $args = null) {
333  $props = array (
334  'id','_href','title','description','identification','volume','number','year','isPublished',
335  'isCurrent','datePublished','dateNotified','lastModified','publishedUrl','coverImageUrl',
336  'coverImageAltText','articles','sections','tableOfContetnts','galleysSummary',
337  );
338 
339  \HookRegistry::call('Issue::getProperties::fullProperties', array(&$props, $issue, $args));
340 
341  return $this->getProperties($issue, $props, $args);
342  }
343 }
APP\Services\IssueService\getIds
getIds($args=[])
Definition: IssueService.inc.php:47
DataObject\getData
& getData($key, $locale=null)
Definition: DataObject.inc.php:100
APP\Services\IssueService\getMany
getMany($args=[])
Definition: IssueService.inc.php:71
APP\Services\IssueService\getMax
getMax($args=[])
Definition: IssueService.inc.php:92
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
APP\Services\IssueService
Definition: IssueService.inc.php:27
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
APP\Services\QueryBuilders\IssueQueryBuilder
Definition: IssueQueryBuilder.inc.php:21
APP\Services\IssueService\getQueryBuilder
getQueryBuilder($args=[])
Definition: IssueService.inc.php:103
APP\Services\IssueService\getSummaryProperties
getSummaryProperties($issue, $args=null)
Definition: IssueService.inc.php:318
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
APP\Services\IssueService\getFullProperties
getFullProperties($issue, $args=null)
Definition: IssueService.inc.php:332
APP\Services
Definition: ContextService.inc.php:15
APP\Services\IssueService\getCount
getCount($args=[])
Definition: IssueService.inc.php:40
APP\Services\IssueService\determineAccessStatus
determineAccessStatus(Journal $journal)
Definition: IssueService.inc.php:166
APP\Services\IssueService\userHasAccessToGalleys
userHasAccessToGalleys(\Journal $journal, \Issue $issue)
Definition: IssueService.inc.php:149
Journal
Describes basic journal properties.
Definition: Journal.inc.php:30
Issue\getAccessStatus
getAccessStatus()
Definition: Issue.inc.php:207
Issue
Class for Issue.
Definition: Issue.inc.php:25
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
APP\Services\IssueService\getProperties
getProperties($issue, $props, $args=null)
Definition: IssueService.inc.php:187
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49