Open Preprint Systems  3.3.0
SectionsHandler.inc.php
1 <?php
2 
17 import('classes.handler.Handler');
18 
19 class SectionsHandler extends Handler {
21  var $sections;
22 
26  function authorize($request, &$args, $roleAssignments) {
27 
28  import('lib.pkp.classes.security.authorization.ContextRequiredPolicy');
29  $this->addPolicy(new ContextRequiredPolicy($request));
30 
31  import('classes.security.authorization.OpsServerMustPublishPolicy');
32  $this->addPolicy(new OpsServerMustPublishPolicy($request));
33 
34  return parent::authorize($request, $args, $roleAssignments);
35  }
36 
47  function section($args, $request) {
48  $sectionPath = isset($args[0]) ? $args[0] : null;
49  $page = isset($args[1]) && ctype_digit((string) $args[1]) ? (int) $args[1] : 1;
50  $context = $request->getContext();
51  $contextId = $context ? $context->getId() : CONTEXT_ID_NONE;
52 
53  // The page $arg can only contain an integer that's not 1. The first page
54  // URL does not include page $arg
55  if (isset($args[1]) && (!ctype_digit((string) $args[1]) || $args[1] == 1)) {
56  $request->getDispatcher()->handle404();
57  exit;
58  }
59 
60  if (!$sectionPath || !$contextId) {
61  $request->getDispatcher()->handle404();
62  exit;
63  }
64 
65  $sectionDao = DAORegistry::getDAO('SectionDAO');
66  $sections = $sectionDao->getByContextId($contextId);
67 
68  $sectionExists = false;
69  while ($section = $sections->next()) {
70  if ($section->getData('path') === $sectionPath) {
71  $sectionExists = true;
72  break;
73  }
74  }
75 
76  if (!$sectionExists) {
77  $request->getDispatcher()->handle404();
78  exit;
79  }
80 
81  import('classes.submission.Submission'); // Import status constants
82 
83  $params = [
84  'contextId' => $contextId,
85  'count' => $context->getData('itemsPerPage'),
86  'offset' => $page ? ($page - 1) * $context->getData('itemsPerPage') : 0,
87  'orderBy' => 'datePublished',
88  'sectionIds' => [(int) $section->getId()],
89  'status' => STATUS_PUBLISHED,
90  ];
91 
92  $result = Services::get('submission')->getMany($params);
93  $total = Services::get('submission')->getMax($params);
94 
95  if ($page > 1 && !$result->valid()) {
96  $request->getDispatcher()->handle404();
97  exit;
98  }
99 
100  $submissions = [];
101  foreach ($result as $submission) {
102  $submissions[] = $submission;
103  }
104 
105  $showingStart = $params['offset'] + 1;
106  $showingEnd = min($params['offset'] + $params['count'], $params['offset'] + count($submissions));
107  $nextPage = $total > $showingEnd ? $page + 1 : null;
108  $prevPage = $showingStart > 1 ? $page - 1 : null;
109 
110  $templateMgr = TemplateManager::getManager($request);
111  $templateMgr->assign(array(
112  'section' => $section,
113  'sectionPath' => $sectionPath,
114  'preprints' => $submissions,
115  'showingStart' => $showingStart,
116  'showingEnd' => $showingEnd,
117  'total' => $total,
118  'nextPage' => $nextPage,
119  'prevPage' => $prevPage,
120  ));
121 
122  $templateMgr->display('frontend/pages/sections.tpl');
123 
124  }
125 
126 
127 }
OpsServerMustPublishPolicy
Access policy to limit access to servers that do not publish online.
Definition: OpsServerMustPublishPolicy.inc.php:18
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
SectionsHandler
Handle requests for sections functions.
Definition: SectionsHandler.inc.php:19
SectionsHandler\$sections
$sections
Definition: SectionsHandler.inc.php:21
SectionsHandler\section
section($args, $request)
Definition: SectionsHandler.inc.php:47
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1226
SectionsHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: SectionsHandler.inc.php:26
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
Handler
Base request handler application class.
Definition: Handler.inc.php:18
ContextRequiredPolicy
Policy to deny access if a context cannot be found in the request.
Definition: ContextRequiredPolicy.inc.php:17
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49