Open Preprint Systems  3.3.0
ArticleGalleyGridHandler.inc.php
1 <?php
2 
16 // import grid base classes
17 import('lib.pkp.classes.controllers.grid.GridHandler');
18 
19 // Link action & modal classes
20 import('lib.pkp.classes.linkAction.request.AjaxModal');
21 
23 
25  var $_request;
26 
30  function __construct() {
31  parent::__construct();
32  $this->addRoleAssignment(
33  array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT, ROLE_ID_AUTHOR),
34  array('fetchGrid', 'fetchRow', 'addGalley', 'editGalley', 'editGalleyTab', 'updateGalley', 'deleteGalley', 'identifiers', 'updateIdentifiers', 'clearPubId', 'saveSequence'));
35  }
36 
37 
38  //
39  // Getters/Setters
40  //
45  function getSubmission() {
46  return $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
47  }
48 
53  function getPublication() {
54  return $this->getAuthorizedContextObject(ASSOC_TYPE_PUBLICATION);
55  }
56 
61  function getGalley() {
62  return $this->getAuthorizedContextObject(ASSOC_TYPE_REPRESENTATION);
63  }
64 
65 
66  //
67  // Overridden methods from PKPHandler.
68  //
72  public function getJSHandler() {
73  return '$.pkp.controllers.grid.articleGalleys.ArticleGalleyGridHandler';
74  }
75 
79  function authorize($request, &$args, $roleAssignments) {
80  $this->_request = $request;
81 
82  import('lib.pkp.classes.security.authorization.WorkflowStageAccessPolicy');
83  $this->addPolicy(new WorkflowStageAccessPolicy($request, $args, $roleAssignments, 'submissionId', WORKFLOW_STAGE_ID_PRODUCTION));
84 
85  import('lib.pkp.classes.security.authorization.PublicationAccessPolicy');
86  $this->addPolicy(new PublicationAccessPolicy($request, $args, $roleAssignments));
87 
88  if ($request->getUserVar('representationId')) {
89  import('lib.pkp.classes.security.authorization.internal.RepresentationRequiredPolicy');
90  $this->addPolicy(new RepresentationRequiredPolicy($request, $args));
91  }
92 
93  return parent::authorize($request, $args, $roleAssignments);
94  }
95 
99  function initialize($request, $args = null) {
100  parent::initialize($request, $args);
101  $this->setTitle('submission.layout.galleys');
102 
103  // Load pkp-lib translations
105  LOCALE_COMPONENT_PKP_SUBMISSION,
106  LOCALE_COMPONENT_PKP_USER,
107  LOCALE_COMPONENT_PKP_EDITOR,
108  LOCALE_COMPONENT_APP_EDITOR
109  );
110 
111  import('controllers.grid.articleGalleys.ArticleGalleyGridCellProvider');
112  $cellProvider = new ArticleGalleyGridCellProvider($this->getSubmission(), $this->getPublication(), $this->canEdit());
113 
114  // Columns
115  $this->addColumn(new GridColumn(
116  'label',
117  'common.name',
118  null,
119  null,
120  $cellProvider
121  ));
122 
123 
124  if ($this->canEdit()) {
125  $this->addAction(new LinkAction(
126  'addGalley',
127  new AjaxModal(
128  $request->getRouter()->url($request, null, null, 'addGalley', null, $this->getRequestArgs()),
129  __('submission.layout.newGalley'),
130  'modal_add_item'
131  ),
132  __('grid.action.addGalley'),
133  'add_item'
134  ));
135  }
136 
137  }
138 
139  //
140  // Overridden methods from GridHandler
141  //
145  function initFeatures($request, $args) {
146  if ($this->canEdit()) {
147  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
148  return array(new OrderGridItemsFeature());
149  }
150 
151  return array();
152  }
153 
157  function getDataElementSequence($row) {
158  return $row->getSequence();
159  }
160 
164  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
165  $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
166  $galley = $galleyDao->getById($rowId);
167  $galley->setSequence($newSequence);
168  $galleyDao->updateObject($galley);
169  }
170 
171  //
172  // Overridden methods from GridHandler
173  //
178  function getRowInstance() {
179  import('controllers.grid.articleGalleys.ArticleGalleyGridRow');
180  return new ArticleGalleyGridRow(
181  $this->getSubmission(),
182  $this->getPublication(),
183  $this->canEdit()
184  );
185  }
186 
192  function getRequestArgs() {
193  return array(
194  'submissionId' => $this->getSubmission()->getId(),
195  'publicationId' => $this->getPublication()->getId(),
196  );
197  }
198 
202  function loadData($request, $filter = null) {
203  $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
204  return $galleyDao->getByPublicationId($this->getPublication()->getId());
205  }
206 
207  //
208  // Public Galley Grid Actions
209  //
216  function identifiers($args, $request) {
217  $representationDao = Application::getRepresentationDAO();
218  $representation = $representationDao->getById($request->getUserVar('representationId'));
219  import('controllers.tab.pubIds.form.PublicIdentifiersForm');
220  $form = new PublicIdentifiersForm($representation);
221  $form->initData();
222  return new JSONMessage(true, $form->fetch($request));
223  }
224 
231  function updateIdentifiers($args, $request) {
232  $representationDao = Application::getRepresentationDAO();
233  $representation = $representationDao->getById($request->getUserVar('representationId'));
234  import('controllers.tab.pubIds.form.PublicIdentifiersForm');
235  $form = new PublicIdentifiersForm($representation, null, array_merge($this->getRequestArgs(), ['representationId' => $representation->getId()]));
236  $form->readInputData();
237  if ($form->validate()) {
238  $form->execute();
239  return DAO::getDataChangedEvent();
240  } else {
241  return new JSONMessage(true, $form->fetch($request));
242  }
243  }
244 
251  function clearPubId($args, $request) {
252  if (!$request->checkCSRF()) return new JSONMessage(false);
253 
254  $submission = $this->getSubmission();
255  $representationDao = Application::getRepresentationDAO();
256  $representation = $representationDao->getById($request->getUserVar('representationId'));
257  import('controllers.tab.pubIds.form.PublicIdentifiersForm');
258  $form = new PublicIdentifiersForm($representation);
259  $form->clearPubId($request->getUserVar('pubIdPlugIn'));
260  return new JSONMessage(true);
261  }
262 
269  function addGalley($args, $request) {
270  import('controllers.grid.articleGalleys.form.ArticleGalleyForm');
271  $galleyForm = new ArticleGalleyForm(
272  $request,
273  $this->getSubmission(),
274  $this->getPublication()
275  );
276  $galleyForm->initData();
277  return new JSONMessage(true, $galleyForm->fetch($request));
278  }
279 
286  function deleteGalley($args, $request) {
287  $galley = $this->getGalley();
288  if (!$galley || !$request->checkCSRF()) return new JSONMessage(false);
289 
290  $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
291  $galleyDao->deleteObject($galley);
292 
293  if ($galley->getFileId()) {
294  import('lib.pkp.classes.submission.SubmissionFile'); // Import constants
295  $publication = Services::get('publication')->get($galley->getData('publicationId'));
296 
297  // Delete dependent files if no other galley uses them
298  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
299  $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $articleGalleyDao ArticleGalleyDAO */
300  $galleyFiles = $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_GALLEY, $galley->getId(), $publication->getData('submissionId'), SUBMISSION_FILE_PROOF);
301  foreach ($galleyFiles as $file) {
302  $sharedFileGalleys = $articleGalleyDao->getByFileId($file->getFileId())->toArray();
303  if (empty($sharedFileGalleys)) {
304  $submissionFileDao->deleteAllRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $file->getFileId(), SUBMISSION_FILE_DEPENDENT);
305  }
306  }
307 
308  // Delete main galley file if no other galley uses it
309  $sharedFileGalleys = $articleGalleyDao->getByFileId($galley->getFileId())->toArray();
310  if (empty($sharedFileGalleys)) {
311  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
312  $submissionFileDao->deleteAllRevisionsById($galley->getFileId());
313  }
314  }
315 
316  $notificationDao = DAORegistry::getDAO('NotificationDAO');
317  $notificationDao->deleteByAssoc(ASSOC_TYPE_REPRESENTATION, $galley->getId());
318 
319  if ($this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_EDITING ||
320  $this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_PRODUCTION) {
321 
322  $notificationMgr = new NotificationManager();
323  $notificationMgr->updateNotification(
324  $request,
325  array(NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER, NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS),
326  null,
327  ASSOC_TYPE_SUBMISSION,
328  $this->getSubmission()->getId()
329  );
330  }
331 
332  //inform search index that file has been deleted
333  $articleSearchIndex = Application::getSubmissionSearchIndex();
334  $articleSearchIndex->submissionFileDeleted($this->getSubmission()->getId());
335  $articleSearchIndex->submissionChangesFinished();
336 
337  return DAO::getDataChangedEvent($galley->getId());
338  }
339 
346  function editGalley($args, $request) {
347  $galley = $this->getGalley();
348 
349  // Check if this is a remote galley
350  $templateMgr = TemplateManager::getManager($request);
351  $templateMgr->assign(array(
352  'submissionId' => $this->getSubmission()->getId(),
353  'publicationId' => $this->getPublication()->getId(),
354  'representationId' => $galley->getId(),
355  ));
356  $publisherIdEnabled = in_array('galley', (array) $request->getContext()->getData('enablePublisherId'));
357  $pubIdsEnabled = false;
358  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true, $request->getContext()->getId());
359  foreach ($pubIdPlugins as $pubIdPlugin) {
360  if ($pubIdPlugin->isObjectTypeEnabled('Representation', $request->getContext()->getId())) {
361  $pubIdsEnabled = true;
362  break;
363  }
364  }
365  if ($publisherIdEnabled || $pubIdsEnabled) {
366  $templateMgr->assign('enableIdentifiers', true);
367  }
368  return new JSONMessage(true, $templateMgr->fetch('controllers/grid/articleGalleys/editFormat.tpl'));
369  }
370 
377  function editGalleyTab($args, $request) {
378  // Form handling
379  import('controllers.grid.articleGalleys.form.ArticleGalleyForm');
380  $galleyForm = new ArticleGalleyForm(
381  $request,
382  $this->getSubmission(),
383  $this->getPublication(),
384  $this->getGalley()
385  );
386  $galleyForm->initData();
387  return new JSONMessage(true, $galleyForm->fetch($request));
388  }
389 
396  function updateGalley($args, $request) {
397  $galley = $this->getGalley();
398 
399  import('controllers.grid.articleGalleys.form.ArticleGalleyForm');
400  $galleyForm = new ArticleGalleyForm($request, $this->getSubmission(), $this->getPublication(), $galley);
401  $galleyForm->readInputData();
402 
403  if ($galleyForm->validate()) {
404  $galley = $galleyForm->execute();
405 
406  if ($this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_EDITING ||
407  $this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_PRODUCTION) {
408 
409  $notificationMgr = new NotificationManager();
410  $notificationMgr->updateNotification(
411  $request,
412  array(NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER, NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS),
413  null,
414  ASSOC_TYPE_SUBMISSION,
415  $this->getSubmission()->getId()
416  );
417  }
418 
419  return DAO::getDataChangedEvent($galley->getId());
420  }
421  return new JSONMessage(true, $galleyForm->fetch($request));
422  }
423 
427  function fetchRow($args, $request) {
428  $json = parent::fetchRow($args, $request);
429  if ($row = $this->getRequestedRow($request, $args)) {
430  $galley = $row->getData();
431  if ($galley->getRemoteUrl()=='' && !$galley->getFileId()) {
432  $json->setEvent('uploadFile', $galley->getId());
433  }
434  }
435 
436  return $json;
437  }
438 
448  public function canEdit() {
449  $request = Application::get()->getRequest();
450  $user = $request->getUser();
451  $publication = $this->getPublication();
452  $submission = $this->getSubmission();
453  $userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
454 
455  if ($publication->getData('status') === STATUS_PUBLISHED) {
456  return false;
457  }
458 
459  if (in_array(ROLE_ID_SITE_ADMIN, $userRoles)) {
460  return true;
461  }
462 
463  if ($submission->getDateSubmitted() == null) return true;
464 
465  if (Services::get('submission')->canEditPublication($submission->getId(), $user->getId())) {
466  return true;
467  }
468 
469  // Default: Read-only.
470  return false;
471  }
472 }
473 
474 
PKPHandler\addRoleAssignment
addRoleAssignment($roleIds, $operations)
Definition: PKPHandler.inc.php:213
GridColumn
The GridColumn class represents a column within a grid. It is used to format the data presented in a ...
Definition: GridColumn.inc.php:27
PublicationAccessPolicy
Class to control access to a publication.
Definition: PublicationAccessPolicy.inc.php:20
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
ArticleGalleyGridHandler\getJSHandler
getJSHandler()
Definition: ArticleGalleyGridHandler.inc.php:75
ArticleGalleyGridHandler\getDataElementSequence
getDataElementSequence($row)
Definition: ArticleGalleyGridHandler.inc.php:160
ArticleGalleyGridHandler\editGalley
editGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:349
Application\getRepresentationDAO
static getRepresentationDAO()
Definition: Application.inc.php:143
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
ArticleGalleyGridHandler\getSubmission
getSubmission()
Definition: ArticleGalleyGridHandler.inc.php:48
ArticleGalleyGridHandler\initialize
initialize($request, $args=null)
Definition: ArticleGalleyGridHandler.inc.php:102
ArticleGalleyGridHandler\getPublication
getPublication()
Definition: ArticleGalleyGridHandler.inc.php:56
PublicIdentifiersForm
Displays a pub ids form.
Definition: PublicIdentifiersForm.inc.php:18
ArticleGalleyGridHandler\getRowInstance
getRowInstance()
Definition: ArticleGalleyGridHandler.inc.php:181
RepresentationRequiredPolicy
Policy that ensures that the request contains a valid representation.
Definition: RepresentationRequiredPolicy.inc.php:17
PKPHandler\getId
getId()
Definition: PKPHandler.inc.php:107
ArticleGalleyGridHandler
Handle article galley grid requests.
Definition: ArticleGalleyGridHandler.inc.php:22
ArticleGalleyGridHandler\editGalleyTab
editGalleyTab($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:380
ArticleGalleyGridHandler\getGalley
getGalley()
Definition: ArticleGalleyGridHandler.inc.php:64
ArticleGalleyGridHandler\$_request
$_request
Definition: ArticleGalleyGridHandler.inc.php:28
GridHandler\addAction
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
Definition: GridHandler.inc.php:266
GridHandler\addColumn
addColumn($column)
Definition: GridHandler.inc.php:335
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
DAO\getDataChangedEvent
static getDataChangedEvent($elementId=null, $parentElementId=null, $content='')
Definition: DAO.inc.php:647
ArticleGalleyGridHandler\canEdit
canEdit()
Definition: ArticleGalleyGridHandler.inc.php:451
ArticleGalleyGridHandler\addGalley
addGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:272
ArticleGalleyGridHandler\updateGalley
updateGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:399
ArticleGalleyGridCellProvider
Base class for a cell provider for article galleys.
Definition: ArticleGalleyGridCellProvider.inc.php:18
JSONMessage
Class to represent a JSON (Javascript Object Notation) message.
Definition: JSONMessage.inc.php:18
AjaxModal
A modal that retrieves its content from via AJAX.
Definition: AjaxModal.inc.php:18
OrderGridItemsFeature
Implements grid ordering functionality.
Definition: OrderGridItemsFeature.inc.php:19
LinkAction
Base class defining an action that can be performed by the user in the user interface.
Definition: LinkAction.inc.php:22
GridHandler\getRequestedRow
getRequestedRow($request, $args)
Definition: GridHandler.inc.php:539
ArticleGalleyGridHandler\loadData
loadData($request, $filter=null)
Definition: ArticleGalleyGridHandler.inc.php:205
ArticleGalleyGridHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: ArticleGalleyGridHandler.inc.php:82
GridHandler\setTitle
setTitle($title)
Definition: GridHandler.inc.php:215
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1226
ArticleGalleyGridHandler\initFeatures
initFeatures($request, $args)
Definition: ArticleGalleyGridHandler.inc.php:148
ArticleGalleyGridHandler\__construct
__construct()
Definition: ArticleGalleyGridHandler.inc.php:33
ArticleGalleyGridHandler\clearPubId
clearPubId($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:254
ArticleGalleyGridHandler\updateIdentifiers
updateIdentifiers($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:234
ArticleGalleyForm
Article galley editing form.
Definition: ArticleGalleyForm.inc.php:19
PKPHandler\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: PKPHandler.inc.php:174
WorkflowStageAccessPolicy
Class to control access to OMP's submission workflow stage components.
Definition: WorkflowStageAccessPolicy.inc.php:19
ArticleGalleyGridHandler\identifiers
identifiers($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:219
GridHandler
This class defines basic operations for handling HTML grids. Grids are used to implement a standardiz...
Definition: GridHandler.inc.php:58
ArticleGalleyGridHandler\getRequestArgs
getRequestArgs()
Definition: ArticleGalleyGridHandler.inc.php:195
NotificationManager
Definition: NotificationManager.inc.php:19
Application\getSubmissionSearchIndex
static getSubmissionSearchIndex()
Definition: Application.inc.php:150
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
ArticleGalleyGridHandler\setDataElementSequence
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
Definition: ArticleGalleyGridHandler.inc.php:167
ArticleGalleyGridRow
Representation of an article galley grid row.
Definition: ArticleGalleyGridRow.inc.php:18
ArticleGalleyGridHandler\deleteGalley
deleteGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:289
ArticleGalleyGridHandler\fetchRow
fetchRow($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:430
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49