Open Monograph Press  3.3.0
IdentificationCodeGridHandler.inc.php
1 <?php
2 
16 // import grid base classes
17 import('lib.pkp.classes.controllers.grid.GridHandler');
18 
19 
20 // import format grid specific classes
21 import('controllers.grid.catalogEntry.IdentificationCodeGridCellProvider');
22 import('controllers.grid.catalogEntry.IdentificationCodeGridRow');
23 
24 // Link action & modal classes
25 import('lib.pkp.classes.linkAction.request.AjaxModal');
26 
29  var $_submission;
30 
33 
36 
40  function __construct() {
41  parent::__construct();
42  $this->addRoleAssignment(
43  array(ROLE_ID_MANAGER),
44  array('fetchGrid', 'fetchRow', 'addCode', 'editCode',
45  'updateCode', 'deleteCode'));
46  }
47 
48 
49  //
50  // Getters/Setters
51  //
56  function getSubmission() {
57  return $this->_submission;
58  }
59 
64  function setSubmission($submission) {
65  $this->_submission = $submission;
66  }
67 
72  function getPublication() {
74  }
75 
80  function setPublication($publication) {
81  $this->_publication = $publication;
82  }
83 
88  function getPublicationFormat() {
90  }
91 
96  function setPublicationFormat($publicationFormat) {
97  $this->_publicationFormat = $publicationFormat;
98  }
99 
100  //
101  // Overridden methods from PKPHandler
102  //
109  function authorize($request, &$args, $roleAssignments) {
110  import('lib.pkp.classes.security.authorization.PublicationAccessPolicy');
111  $this->addPolicy(new PublicationAccessPolicy($request, $args, $roleAssignments));
112  return parent::authorize($request, $args, $roleAssignments);
113  }
114 
118  function initialize($request, $args = null) {
119  parent::initialize($request, $args);
120 
121  // Retrieve the authorized submission.
122  $this->setSubmission($this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION));
123  $this->setPublication($this->getAuthorizedContextObject(ASSOC_TYPE_PUBLICATION));
124  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); /* @var $publicationFormatDao PublicationFormatDAO */
125  $representationId = null;
126 
127  // Retrieve the associated publication format for this grid.
128  $identificationCodeId = (int) $request->getUserVar('identificationCodeId'); // set if editing or deleting a code
129 
130  if ($identificationCodeId != '') {
131  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO'); /* @var $identificationCodeDao IdentificationCodeDAO */
132  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $this->getPublication()->getId());
133  if ($identificationCode) {
134  $representationId = $identificationCode->getPublicationFormatId();
135  }
136  } else { // empty form for new Code
137  $representationId = (int) $request->getUserVar('representationId');
138  }
139 
140  $publicationFormat = $publicationFormatDao->getById($representationId, $this->getPublication()->getId());
141 
142  if ($publicationFormat) {
143  $this->setPublicationFormat($publicationFormat);
144  } else {
145  fatalError('The publication format is not assigned to authorized submission!');
146  }
147 
148  // Load submission-specific translations
150  LOCALE_COMPONENT_APP_SUBMISSION,
151  LOCALE_COMPONENT_PKP_SUBMISSION,
152  LOCALE_COMPONENT_PKP_USER,
153  LOCALE_COMPONENT_APP_DEFAULT,
154  LOCALE_COMPONENT_PKP_DEFAULT
155  );
156 
157  // Basic grid configuration
158  $this->setTitle('submission.publicationFormat.productIdentifierType');
159 
160  // Grid actions
161  $router = $request->getRouter();
162  $actionArgs = $this->getRequestArgs();
163  $this->addAction(
164  new LinkAction(
165  'addCode',
166  new AjaxModal(
167  $router->url($request, null, null, 'addCode', null, $actionArgs),
168  __('grid.action.addCode'),
169  'modal_add_item'
170  ),
171  __('grid.action.addCode'),
172  'add_item'
173  )
174  );
175 
176  // Columns
177  $cellProvider = new IdentificationCodeGridCellProvider();
178  $this->addColumn(
179  new GridColumn(
180  'value',
181  'grid.catalogEntry.identificationCodeValue',
182  null,
183  null,
184  $cellProvider,
185  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
186  )
187  );
188  $this->addColumn(
189  new GridColumn(
190  'code',
191  'grid.catalogEntry.identificationCodeType',
192  null,
193  null,
194  $cellProvider
195  )
196  );
197  }
198 
199 
200  //
201  // Overridden methods from GridHandler
202  //
207  function getRowInstance() {
208  return new IdentificationCodeGridRow($this->getSubmission());
209  }
210 
216  function getRequestArgs() {
217  return [
218  'submissionId' => $this->getSubmission()->getId(),
219  'publicationId' => $this->getPublication()->getId(),
220  'representationId' => $this->getPublicationFormat()->getId()
221  ];
222  }
223 
227  function loadData($request, $filter = null) {
228  $publicationFormat = $this->getPublicationFormat();
229  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO'); /* @var $identificationCodeDao IdentificationCodeDAO */
230  $data = $identificationCodeDao->getByPublicationFormatId($publicationFormat->getId());
231  return $data->toArray();
232  }
233 
234 
235  //
236  // Public Identification Code Grid Actions
237  //
244  function addCode($args, $request) {
245  return $this->editCode($args, $request);
246  }
247 
254  function editCode($args, $request) {
255  // Identify the code to be updated
256  $identificationCodeId = (int) $request->getUserVar('identificationCodeId');
257  $submission = $this->getSubmission();
258 
259  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO'); /* @var $identificationCodeDao IdentificationCodeDAO */
260  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $this->getPublication()->getId());
261 
262  // Form handling
263  import('controllers.grid.catalogEntry.form.IdentificationCodeForm');
264  $identificationCodeForm = new IdentificationCodeForm($submission, $this->getPublication(), $identificationCode);
265  $identificationCodeForm->initData();
266 
267  return new JSONMessage(true, $identificationCodeForm->fetch($request));
268  }
269 
276  function updateCode($args, $request) {
277  // Identify the code to be updated
278  $identificationCodeId = $request->getUserVar('identificationCodeId');
279  $submission = $this->getSubmission();
280 
281  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO'); /* @var $identificationCodeDao IdentificationCodeDAO */
282  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $this->getPublication()->getId());
283 
284  // Form handling
285  import('controllers.grid.catalogEntry.form.IdentificationCodeForm');
286  $identificationCodeForm = new IdentificationCodeForm($submission, $this->getPublication(), $identificationCode);
287  $identificationCodeForm->readInputData();
288  if ($identificationCodeForm->validate()) {
289  $identificationCodeId = $identificationCodeForm->execute();
290 
291  if(!isset($identificationCode)) {
292  // This is a new code
293  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $this->getPublication()->getId());
294  // New added code action notification content.
295  $notificationContent = __('notification.addedIdentificationCode');
296  } else {
297  // code edit action notification content.
298  $notificationContent = __('notification.editedIdentificationCode');
299  }
300 
301  // Create trivial notification.
302  $currentUser = $request->getUser();
303  $notificationMgr = new NotificationManager();
304  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
305 
306  // Prepare the grid row data
307  $row = $this->getRowInstance();
308  $row->setGridId($this->getId());
309  $row->setId($identificationCodeId);
310  $row->setData($identificationCode);
311  $row->initialize($request);
312 
313  // Render the row into a JSON response
314  return DAO::getDataChangedEvent();
315 
316  } else {
317  return new JSONMessage(true, $identificationCodeForm->fetch($request));
318  }
319  }
320 
327  function deleteCode($args, $request) {
328 
329  // Identify the code to be deleted
330  $identificationCodeId = $request->getUserVar('identificationCodeId');
331 
332  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO'); /* @var $identificationCodeDao IdentificationCodeDAO */
333  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $this->getPublication()->getId());
334  if ($identificationCode != null) { // authorized
335 
336  $result = $identificationCodeDao->deleteObject($identificationCode);
337 
338  if ($result) {
339  $currentUser = $request->getUser();
340  $notificationMgr = new NotificationManager();
341  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedIdentificationCode')));
342  return DAO::getDataChangedEvent();
343  } else {
344  return new JSONMessage(false, __('manager.setup.errorDeletingItem'));
345  }
346  }
347  }
348 }
349 
350 
PKPHandler\addRoleAssignment
addRoleAssignment($roleIds, $operations)
Definition: PKPHandler.inc.php:213
IdentificationCodeGridHandler\editCode
editCode($args, $request)
Definition: IdentificationCodeGridHandler.inc.php:263
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
IdentificationCodeForm
Form for adding/editing an identification code.
Definition: IdentificationCodeForm.inc.php:18
IdentificationCodeGridHandler\getRequestArgs
getRequestArgs()
Definition: IdentificationCodeGridHandler.inc.php:225
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
IdentificationCodeGridHandler
Handle publication format grid requests for identification codes.
Definition: IdentificationCodeGridHandler.inc.php:27
PKPHandler\getId
getId()
Definition: PKPHandler.inc.php:107
IdentificationCodeGridCellProvider
Base class for a cell provider that can retrieve labels for identification codes.
Definition: IdentificationCodeGridCellProvider.inc.php:18
IdentificationCodeGridHandler\$_publication
$_publication
Definition: IdentificationCodeGridHandler.inc.php:38
GridHandler\addAction
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
Definition: GridHandler.inc.php:266
IdentificationCodeGridHandler\setPublicationFormat
setPublicationFormat($publicationFormat)
Definition: IdentificationCodeGridHandler.inc.php:105
GridHandler\addColumn
addColumn($column)
Definition: GridHandler.inc.php:335
IdentificationCodeGridHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: IdentificationCodeGridHandler.inc.php:118
IdentificationCodeGridHandler\initialize
initialize($request, $args=null)
Definition: IdentificationCodeGridHandler.inc.php:127
DAO\getDataChangedEvent
static getDataChangedEvent($elementId=null, $parentElementId=null, $content='')
Definition: DAO.inc.php:647
IdentificationCodeGridHandler\setSubmission
setSubmission($submission)
Definition: IdentificationCodeGridHandler.inc.php:73
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
IdentificationCodeGridRow
Identification Code grid row definition.
Definition: IdentificationCodeGridRow.inc.php:18
LinkAction
Base class defining an action that can be performed by the user in the user interface.
Definition: LinkAction.inc.php:22
GridHandler\setTitle
setTitle($title)
Definition: GridHandler.inc.php:215
IdentificationCodeGridHandler\$_publicationFormat
$_publicationFormat
Definition: IdentificationCodeGridHandler.inc.php:44
PKPHandler\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: PKPHandler.inc.php:174
IdentificationCodeGridHandler\deleteCode
deleteCode($args, $request)
Definition: IdentificationCodeGridHandler.inc.php:336
IdentificationCodeGridHandler\loadData
loadData($request, $filter=null)
Definition: IdentificationCodeGridHandler.inc.php:236
IdentificationCodeGridHandler\updateCode
updateCode($args, $request)
Definition: IdentificationCodeGridHandler.inc.php:285
IdentificationCodeGridHandler\getRowInstance
getRowInstance()
Definition: IdentificationCodeGridHandler.inc.php:216
GridHandler
This class defines basic operations for handling HTML grids. Grids are used to implement a standardiz...
Definition: GridHandler.inc.php:58
IdentificationCodeGridHandler\$_submission
$_submission
Definition: IdentificationCodeGridHandler.inc.php:32
NotificationManager
Definition: NotificationManager.inc.php:19
IdentificationCodeGridHandler\__construct
__construct()
Definition: IdentificationCodeGridHandler.inc.php:49
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
IdentificationCodeGridHandler\getSubmission
getSubmission()
Definition: IdentificationCodeGridHandler.inc.php:65
fatalError
if(!function_exists('import')) fatalError($reason)
Definition: functions.inc.php:32
IdentificationCodeGridHandler\setPublication
setPublication($publication)
Definition: IdentificationCodeGridHandler.inc.php:89
IdentificationCodeGridHandler\getPublication
getPublication()
Definition: IdentificationCodeGridHandler.inc.php:81
IdentificationCodeGridHandler\addCode
addCode($args, $request)
Definition: IdentificationCodeGridHandler.inc.php:253
IdentificationCodeGridHandler\getPublicationFormat
getPublicationFormat()
Definition: IdentificationCodeGridHandler.inc.php:97