Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
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 $_monograph;
30 
32  var $_publicationFormat;
33 
38  parent::GridHandler();
39  $this->addRoleAssignment(
40  array(ROLE_ID_MANAGER),
41  array('fetchGrid', 'fetchRow', 'addCode', 'editCode',
42  'updateCode', 'deleteCode'));
43  }
44 
45 
46  //
47  // Getters/Setters
48  //
53  function getMonograph() {
54  return $this->_monograph;
55  }
56 
61  function setMonograph($monograph) {
62  $this->_monograph = $monograph;
63  }
64 
69  function getPublicationFormat() {
70  return $this->_publicationFormat;
71  }
72 
77  function setPublicationFormat($publicationFormat) {
78  $this->_publicationFormat = $publicationFormat;
79  }
80 
81  //
82  // Overridden methods from PKPHandler
83  //
90  function authorize($request, &$args, $roleAssignments) {
91  import('classes.security.authorization.SubmissionAccessPolicy');
92  $this->addPolicy(new SubmissionAccessPolicy($request, $args, $roleAssignments));
93  return parent::authorize($request, $args, $roleAssignments);
94  }
95 
96  /*
97  * Configure the grid
98  * @param $request PKPRequest
99  */
100  function initialize($request) {
101  parent::initialize($request);
102 
103  // Retrieve the authorized monograph.
104  $this->setMonograph($this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH));
105  $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
106  $publicationFormatId = null;
107 
108  // Retrieve the associated publication format for this grid.
109  $identificationCodeId = (int) $request->getUserVar('identificationCodeId'); // set if editing or deleting a code
110 
111  if ($identificationCodeId != '') {
112  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO');
113  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $this->getMonograph()->getId());
114  if ($identificationCode) {
115  $publicationFormatId = $identificationCode->getPublicationFormatId();
116  }
117  } else { // empty form for new Code
118  $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
119  }
120 
121  $publicationFormat = $publicationFormatDao->getById($publicationFormatId, $this->getMonograph()->getId());
122 
123  if ($publicationFormat) {
124  $this->setPublicationFormat($publicationFormat);
125  } else {
126  fatalError('The publication format is not assigned to authorized monograph!');
127  }
128 
129  // Load submission-specific translations
131  LOCALE_COMPONENT_APP_SUBMISSION,
132  LOCALE_COMPONENT_PKP_SUBMISSION,
133  LOCALE_COMPONENT_PKP_USER,
134  LOCALE_COMPONENT_APP_DEFAULT,
135  LOCALE_COMPONENT_PKP_DEFAULT
136  );
137 
138  // Basic grid configuration
139  $this->setTitle('monograph.publicationFormat.productIdentifierType');
140 
141  // Grid actions
142  $router = $request->getRouter();
143  $actionArgs = $this->getRequestArgs();
144  $this->addAction(
145  new LinkAction(
146  'addCode',
147  new AjaxModal(
148  $router->url($request, null, null, 'addCode', null, $actionArgs),
149  __('grid.action.addCode'),
150  'modal_add_item'
151  ),
152  __('grid.action.addCode'),
153  'add_item'
154  )
155  );
156 
157  // Columns
158  $cellProvider = new IdentificationCodeGridCellProvider();
159  $this->addColumn(
160  new GridColumn(
161  'value',
162  'grid.catalogEntry.identificationCodeValue',
163  null,
164  'controllers/grid/gridCell.tpl',
165  $cellProvider,
166  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
167  )
168  );
169  $this->addColumn(
170  new GridColumn(
171  'code',
172  'grid.catalogEntry.identificationCodeType',
173  null,
174  'controllers/grid/gridCell.tpl',
175  $cellProvider
176  )
177  );
178  }
179 
180 
181  //
182  // Overridden methods from GridHandler
183  //
188  function getRowInstance() {
189  return new IdentificationCodeGridRow($this->getMonograph());
190  }
191 
197  function getRequestArgs() {
198  $monograph = $this->getMonograph();
199  $publicationFormat = $this->getPublicationFormat();
200 
201  return array(
202  'submissionId' => $monograph->getId(),
203  'publicationFormatId' => $publicationFormat->getId()
204  );
205  }
206 
210  function loadData($request, $filter = null) {
211  $publicationFormat = $this->getPublicationFormat();
212  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO');
213  $data = $identificationCodeDao->getByPublicationFormatId($publicationFormat->getId());
214  return $data->toArray();
215  }
217 
218  //
219  // Public Identification Code Grid Actions
220  //
221 
222  function addCode($args, $request) {
223  return $this->editCode($args, $request);
224  }
225 
232  function editCode($args, $request) {
233  // Identify the code to be updated
234  $identificationCodeId = (int) $request->getUserVar('identificationCodeId');
235  $monograph = $this->getMonograph();
236 
237  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO');
238  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $monograph->getId());
239 
240  // Form handling
241  import('controllers.grid.catalogEntry.form.IdentificationCodeForm');
242  $identificationCodeForm = new IdentificationCodeForm($monograph, $identificationCode);
243  $identificationCodeForm->initData();
244 
245  $json = new JSONMessage(true, $identificationCodeForm->fetch($request));
246  return $json->getString();
247  }
248 
255  function updateCode($args, $request) {
256  // Identify the code to be updated
257  $identificationCodeId = $request->getUserVar('identificationCodeId');
258  $monograph = $this->getMonograph();
259 
260  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO');
261  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $monograph->getId());
262 
263  // Form handling
264  import('controllers.grid.catalogEntry.form.IdentificationCodeForm');
265  $identificationCodeForm = new IdentificationCodeForm($monograph, $identificationCode);
266  $identificationCodeForm->readInputData();
267  if ($identificationCodeForm->validate()) {
268  $identificationCodeId = $identificationCodeForm->execute();
269 
270  if(!isset($identificationCode)) {
271  // This is a new code
272  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $monograph->getId());
273  // New added code action notification content.
274  $notificationContent = __('notification.addedIdentificationCode');
275  } else {
276  // code edit action notification content.
277  $notificationContent = __('notification.editedIdentificationCode');
278  }
279 
280  // Create trivial notification.
281  $currentUser = $request->getUser();
282  $notificationMgr = new NotificationManager();
283  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
284 
285  // Prepare the grid row data
286  $row = $this->getRowInstance();
287  $row->setGridId($this->getId());
288  $row->setId($identificationCodeId);
289  $row->setData($identificationCode);
290  $row->initialize($request);
291 
292  // Render the row into a JSON response
293  return DAO::getDataChangedEvent();
294 
295  } else {
296  $json = new JSONMessage(true, $identificationCodeForm->fetch($request));
297  return $json->getString();
298  }
299  }
300 
307  function deleteCode($args, $request) {
308 
309  // Identify the code to be deleted
310  $identificationCodeId = $request->getUserVar('identificationCodeId');
311 
312  $identificationCodeDao = DAORegistry::getDAO('IdentificationCodeDAO');
313  $identificationCode = $identificationCodeDao->getById($identificationCodeId, $this->getMonograph()->getId());
314  if ($identificationCode != null) { // authorized
315 
316  $result = $identificationCodeDao->deleteObject($identificationCode);
317 
318  if ($result) {
319  $currentUser = $request->getUser();
320  $notificationMgr = new NotificationManager();
321  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedIdentificationCode')));
322  return DAO::getDataChangedEvent();
323  } else {
324  $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
325  return $json->getString();
326  }
327  }
328  }
329 }
330 
331 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
Form for adding/editing an identification code.
static requireComponents()
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
authorize($request, &$args, $roleAssignments)
Class defining basic operations for handling HTML grids.
addRoleAssignment($roleIds, $operations)
Class to control (write) access to submissions and (read) access to submission details in OMP...
A modal that retrieves its content from via AJAX.
Class to represent a JSON (Javascript Object Notation) message.
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
Identification Code grid row definition.
Handle publication format grid requests for identification codes.
Base class for a cell provider that can retrieve labels for identification codes. ...
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
& getAuthorizedContextObject($assocType)
Base class defining an action that can be performed by the user in the user interface.