Open Journal 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_AUTHOR, ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT),
34  array('fetchGrid', 'fetchRow'));
35  $this->addRoleAssignment(
36  array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT),
37  array('addGalley', 'editGalley', 'editGalleyTab', 'updateGalley', 'deleteGalley', 'identifiers', 'updateIdentifiers', 'clearPubId', 'saveSequence'));
38  }
39 
40 
41  //
42  // Getters/Setters
43  //
48  function getSubmission() {
49  return $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
50  }
51 
56  function getPublication() {
57  return $this->getAuthorizedContextObject(ASSOC_TYPE_PUBLICATION);
58  }
59 
64  function getGalley() {
65  return $this->getAuthorizedContextObject(ASSOC_TYPE_REPRESENTATION);
66  }
67 
68 
69  //
70  // Overridden methods from PKPHandler.
71  //
75  public function getJSHandler() {
76  return '$.pkp.controllers.grid.articleGalleys.ArticleGalleyGridHandler';
77  }
78 
82  function authorize($request, &$args, $roleAssignments) {
83  $this->_request = $request;
84 
85  import('lib.pkp.classes.security.authorization.WorkflowStageAccessPolicy');
86  $this->addPolicy(new WorkflowStageAccessPolicy($request, $args, $roleAssignments, 'submissionId', WORKFLOW_STAGE_ID_PRODUCTION));
87 
88  import('lib.pkp.classes.security.authorization.PublicationAccessPolicy');
89  $this->addPolicy(new PublicationAccessPolicy($request, $args, $roleAssignments));
90 
91  if ($request->getUserVar('representationId')) {
92  import('lib.pkp.classes.security.authorization.internal.RepresentationRequiredPolicy');
93  $this->addPolicy(new RepresentationRequiredPolicy($request, $args));
94  }
95 
96  return parent::authorize($request, $args, $roleAssignments);
97  }
98 
102  function initialize($request, $args = null) {
103  parent::initialize($request, $args);
104  $this->setTitle('submission.layout.galleys');
105 
106  // Load pkp-lib translations
108  LOCALE_COMPONENT_PKP_SUBMISSION,
109  LOCALE_COMPONENT_PKP_USER,
110  LOCALE_COMPONENT_PKP_EDITOR,
111  LOCALE_COMPONENT_APP_EDITOR
112  );
113 
114  import('controllers.grid.articleGalleys.ArticleGalleyGridCellProvider');
115  $cellProvider = new ArticleGalleyGridCellProvider($this->getSubmission(), $this->getPublication(), $this->canEdit());
116 
117  // Columns
118  $this->addColumn(new GridColumn(
119  'label',
120  'common.name',
121  null,
122  null,
123  $cellProvider
124  ));
125 
126  if ($this->canEdit()) {
127  $this->addAction(new LinkAction(
128  'addGalley',
129  new AjaxModal(
130  $request->getRouter()->url($request, null, null, 'addGalley', null, $this->getRequestArgs()),
131  __('submission.layout.newGalley'),
132  'modal_add_item'
133  ),
134  __('grid.action.addGalley'),
135  'add_item'
136  ));
137  }
138  }
139 
140  //
141  // Overridden methods from GridHandler
142  //
146  function initFeatures($request, $args) {
147  if ($this->canEdit()) {
148  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
149  return array(new OrderGridItemsFeature());
150  }
151 
152  return array();
153  }
154 
158  function getDataElementSequence($row) {
159  return $row->getSequence();
160  }
161 
165  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
166  $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $galleyDao ArticleGalleyDAO */
167  $galley = $galleyDao->getById($rowId);
168  $galley->setSequence($newSequence);
169  $galleyDao->updateObject($galley);
170  }
171 
172  //
173  // Overridden methods from GridHandler
174  //
179  function getRowInstance() {
180  import('controllers.grid.articleGalleys.ArticleGalleyGridRow');
181  return new ArticleGalleyGridRow(
182  $this->getSubmission(),
183  $this->getPublication(),
184  $this->canEdit()
185  );
186  }
187 
193  function getRequestArgs() {
194  return array(
195  'submissionId' => $this->getSubmission()->getId(),
196  'publicationId' => $this->getPublication()->getId(),
197  );
198  }
199 
203  function loadData($request, $filter = null) {
204  $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $galleyDao ArticleGalleyDAO */
205  return $galleyDao->getByPublicationId($this->getPublication()->getId());
206  }
207 
208  //
209  // Public Galley Grid Actions
210  //
217  function identifiers($args, $request) {
218  $representationDao = Application::getRepresentationDAO();
219  $representation = $representationDao->getById($request->getUserVar('representationId'));
220  import('controllers.tab.pubIds.form.PublicIdentifiersForm');
221  $form = new PublicIdentifiersForm($representation);
222  $form->initData();
223  return new JSONMessage(true, $form->fetch($request));
224  }
225 
232  function updateIdentifiers($args, $request) {
233  $representationDao = Application::getRepresentationDAO();
234  $representation = $representationDao->getById($request->getUserVar('representationId'));
235  import('controllers.tab.pubIds.form.PublicIdentifiersForm');
236  $form = new PublicIdentifiersForm($representation, null, array_merge($this->getRequestArgs(), ['representationId' => $representation->getId()]));
237  $form->readInputData();
238  if ($form->validate()) {
239  $form->execute();
240  return DAO::getDataChangedEvent();
241  } else {
242  return new JSONMessage(true, $form->fetch($request));
243  }
244  }
245 
252  function clearPubId($args, $request) {
253  if (!$request->checkCSRF()) return new JSONMessage(false);
254 
255  $submission = $this->getSubmission();
256  $representationDao = Application::getRepresentationDAO();
257  $representation = $representationDao->getById($request->getUserVar('representationId'));
258  import('controllers.tab.pubIds.form.PublicIdentifiersForm');
259  $form = new PublicIdentifiersForm($representation);
260  $form->clearPubId($request->getUserVar('pubIdPlugIn'));
261  return new JSONMessage(true);
262  }
263 
270  function addGalley($args, $request) {
271  import('controllers.grid.articleGalleys.form.ArticleGalleyForm');
272  $galleyForm = new ArticleGalleyForm(
273  $request,
274  $this->getSubmission(),
275  $this->getPublication()
276  );
277  $galleyForm->initData();
278  return new JSONMessage(true, $galleyForm->fetch($request));
279  }
280 
287  function deleteGalley($args, $request) {
288  $galley = $this->getGalley();
289  if (!$galley || !$request->checkCSRF()) return new JSONMessage(false);
290 
291  $galleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $galleyDao ArticleGalleyDAO */
292  $galleyDao->deleteObject($galley);
293 
294  if ($galley->getFileId()) {
295  import('lib.pkp.classes.submission.SubmissionFile'); // Import constants
296  $publication = Services::get('publication')->get($galley->getData('publicationId'));
297 
298  // Delete dependent files if no other galley uses them
299  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
300  $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); /* @var $articleGalleyDao ArticleGalleyDAO */
301  $galleyFiles = $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_GALLEY, $galley->getId(), $publication->getData('submissionId'), SUBMISSION_FILE_PROOF);
302  foreach ($galleyFiles as $file) {
303  $sharedFileGalleys = $articleGalleyDao->getByFileId($file->getFileId())->toArray();
304  if (empty($sharedFileGalleys)) {
305  $submissionFileDao->deleteAllRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $file->getFileId(), SUBMISSION_FILE_DEPENDENT);
306  }
307  }
308 
309  // Delete main galley file if no other galley uses it
310  $sharedFileGalleys = $articleGalleyDao->getByFileId($galley->getFileId())->toArray();
311  if (empty($sharedFileGalleys)) {
312  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
313  $submissionFileDao->deleteAllRevisionsById($galley->getFileId());
314  }
315  }
316 
317  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
318  $notificationDao->deleteByAssoc(ASSOC_TYPE_REPRESENTATION, $galley->getId());
319 
320  if ($this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_EDITING ||
321  $this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_PRODUCTION) {
322 
323  $notificationMgr = new NotificationManager();
324  $notificationMgr->updateNotification(
325  $request,
326  array(NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER, NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS),
327  null,
328  ASSOC_TYPE_SUBMISSION,
329  $this->getSubmission()->getId()
330  );
331  }
332 
333  //inform search index that file has been deleted
334  $articleSearchIndex = Application::getSubmissionSearchIndex();
335  $articleSearchIndex->submissionFileDeleted($this->getSubmission()->getId());
336  $articleSearchIndex->submissionChangesFinished();
337 
338  return DAO::getDataChangedEvent($galley->getId());
339  }
340 
347  function editGalley($args, $request) {
348  $galley = $this->getGalley();
349 
350  // Check if this is a remote galley
351  $templateMgr = TemplateManager::getManager($request);
352  $templateMgr->assign(array(
353  'submissionId' => $this->getSubmission()->getId(),
354  'publicationId' => $this->getPublication()->getId(),
355  'representationId' => $galley->getId(),
356  ));
357  $publisherIdEnabled = in_array('galley', (array) $request->getContext()->getData('enablePublisherId'));
358  $pubIdsEnabled = false;
359  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true, $request->getContext()->getId());
360  foreach ($pubIdPlugins as $pubIdPlugin) {
361  if ($pubIdPlugin->isObjectTypeEnabled('Representation', $request->getContext()->getId())) {
362  $pubIdsEnabled = true;
363  break;
364  }
365  }
366  if ($publisherIdEnabled || $pubIdsEnabled) {
367  $templateMgr->assign('enableIdentifiers', true);
368  }
369  return new JSONMessage(true, $templateMgr->fetch('controllers/grid/articleGalleys/editFormat.tpl'));
370  }
371 
378  function editGalleyTab($args, $request) {
379  // Form handling
380  import('controllers.grid.articleGalleys.form.ArticleGalleyForm');
381  $galleyForm = new ArticleGalleyForm(
382  $request,
383  $this->getSubmission(),
384  $this->getPublication(),
385  $this->getGalley()
386  );
387  $galleyForm->initData();
388  return new JSONMessage(true, $galleyForm->fetch($request));
389  }
390 
397  function updateGalley($args, $request) {
398  $galley = $this->getGalley();
399 
400  import('controllers.grid.articleGalleys.form.ArticleGalleyForm');
401  $galleyForm = new ArticleGalleyForm($request, $this->getSubmission(), $this->getPublication(), $galley);
402  $galleyForm->readInputData();
403 
404  if ($galleyForm->validate()) {
405  $galley = $galleyForm->execute();
406 
407  if ($this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_EDITING ||
408  $this->getSubmission()->getStageId() == WORKFLOW_STAGE_ID_PRODUCTION) {
409 
410  $notificationMgr = new NotificationManager();
411  $notificationMgr->updateNotification(
412  $request,
413  array(NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER, NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS),
414  null,
415  ASSOC_TYPE_SUBMISSION,
416  $this->getSubmission()->getId()
417  );
418  }
419 
420  return DAO::getDataChangedEvent($galley->getId());
421  }
422  return new JSONMessage(true, $galleyForm->fetch($request));
423  }
424 
428  function fetchRow($args, $request) {
429  $json = parent::fetchRow($args, $request);
430  if ($row = $this->getRequestedRow($request, $args)) {
431  $galley = $row->getData();
432  if ($galley->getRemoteUrl()=='' && !$galley->getFileId()) {
433  $json->setEvent('uploadFile', $galley->getId());
434  }
435  }
436 
437  return $json;
438  }
439 
449  public function canEdit() {
450  return $this->getPublication()->getData('status') !== STATUS_PUBLISHED &&
451  Services::get('user')->canUserAccessStage(
452  WORKFLOW_STAGE_ID_PRODUCTION,
453  WORKFLOW_TYPE_EDITORIAL,
454  $this->getAuthorizedContextObject(ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES),
455  $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES)
456  );
457  }
458 }
459 
460 
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:78
ArticleGalleyGridHandler\getDataElementSequence
getDataElementSequence($row)
Definition: ArticleGalleyGridHandler.inc.php:161
ArticleGalleyGridHandler\editGalley
editGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:350
Application\getRepresentationDAO
static getRepresentationDAO()
Definition: Application.inc.php:162
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
ArticleGalleyGridHandler\getSubmission
getSubmission()
Definition: ArticleGalleyGridHandler.inc.php:51
ArticleGalleyGridHandler\initialize
initialize($request, $args=null)
Definition: ArticleGalleyGridHandler.inc.php:105
ArticleGalleyGridHandler\getPublication
getPublication()
Definition: ArticleGalleyGridHandler.inc.php:59
PublicIdentifiersForm
Displays a pub ids form.
Definition: PublicIdentifiersForm.inc.php:18
ArticleGalleyGridHandler\getRowInstance
getRowInstance()
Definition: ArticleGalleyGridHandler.inc.php:182
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:381
ArticleGalleyGridHandler\getGalley
getGalley()
Definition: ArticleGalleyGridHandler.inc.php:67
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:452
ArticleGalleyGridHandler\addGalley
addGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:273
ArticleGalleyGridHandler\updateGalley
updateGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:400
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:206
ArticleGalleyGridHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: ArticleGalleyGridHandler.inc.php:85
GridHandler\setTitle
setTitle($title)
Definition: GridHandler.inc.php:215
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
ArticleGalleyGridHandler\initFeatures
initFeatures($request, $args)
Definition: ArticleGalleyGridHandler.inc.php:149
ArticleGalleyGridHandler\__construct
__construct()
Definition: ArticleGalleyGridHandler.inc.php:33
ArticleGalleyGridHandler\clearPubId
clearPubId($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:255
ArticleGalleyGridHandler\updateIdentifiers
updateIdentifiers($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:235
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:220
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:196
NotificationManager
Definition: NotificationManager.inc.php:19
Application\getSubmissionSearchIndex
static getSubmissionSearchIndex()
Definition: Application.inc.php:169
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
ArticleGalleyGridHandler\setDataElementSequence
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
Definition: ArticleGalleyGridHandler.inc.php:168
ArticleGalleyGridRow
Representation of an article galley grid row.
Definition: ArticleGalleyGridRow.inc.php:18
ArticleGalleyGridHandler\deleteGalley
deleteGalley($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:290
ArticleGalleyGridHandler\fetchRow
fetchRow($args, $request)
Definition: ArticleGalleyGridHandler.inc.php:431
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49