Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PublicationDateGridHandler.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.PublicationDateGridCellProvider');
22 import('controllers.grid.catalogEntry.PublicationDateGridRow');
23 
24 // Link action & modal classes
25 import('lib.pkp.classes.linkAction.request.AjaxModal');
26 
29  var $_monograph;
30 
32  var $_publicationFormat;
33 
37  function PublicationDateGridHandler() {
38  parent::GridHandler();
39  $this->addRoleAssignment(
40  array(ROLE_ID_MANAGER),
41  array('fetchGrid', 'fetchRow', 'addDate', 'editDate',
42  'updateDate', 'deleteDate'));
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  $publicationDateId = (int) $request->getUserVar('publicationDateId'); // set if editing or deleting a date
110 
111  if ($publicationDateId != '') {
112  $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO');
113  $publicationDate = $publicationDateDao->getById($publicationDateId, $this->getMonograph()->getId());
114  if ($publicationDate) {
115  $publicationFormatId = $publicationDate->getPublicationFormatId();
116  }
117  } else { // empty form for new Date
118  $publicationFormatId = (int) $request->getUserVar('publicationFormatId');
119  }
120 
121  $monograph = $this->getMonograph();
122  $publicationFormat = $publicationFormatDao->getById($publicationFormatId, $monograph->getId());
123 
124  if ($publicationFormat) {
125  $this->setPublicationFormat($publicationFormat);
126  } else {
127  fatalError('The publication format is not assigned to authorized monograph!');
128  }
129 
130  // Load submission-specific translations
132  LOCALE_COMPONENT_APP_SUBMISSION,
133  LOCALE_COMPONENT_PKP_SUBMISSION,
134  LOCALE_COMPONENT_PKP_USER,
135  LOCALE_COMPONENT_APP_DEFAULT,
136  LOCALE_COMPONENT_PKP_DEFAULT
137  );
138 
139  // Basic grid configuration
140  $this->setTitle('grid.catalogEntry.publicationDates');
141 
142  // Grid actions
143  $router = $request->getRouter();
144  $actionArgs = $this->getRequestArgs();
145  $this->addAction(
146  new LinkAction(
147  'addDate',
148  new AjaxModal(
149  $router->url($request, null, null, 'addDate', null, $actionArgs),
150  __('grid.action.addDate'),
151  'modal_add_item'
152  ),
153  __('grid.action.addDate'),
154  'add_item'
155  )
156  );
157 
158  // Columns
159  $cellProvider = new PublicationDateGridCellProvider();
160  $this->addColumn(
161  new GridColumn(
162  'value',
163  'grid.catalogEntry.dateValue',
164  null,
165  'controllers/grid/gridCell.tpl',
166  $cellProvider,
167  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
168  )
169  );
170  $this->addColumn(
171  new GridColumn(
172  'code',
173  'grid.catalogEntry.dateRole',
174  null,
175  'controllers/grid/gridCell.tpl',
176  $cellProvider
177  )
178  );
179  }
180 
181 
182  //
183  // Overridden methods from GridHandler
184  //
189  function getRowInstance() {
190  return new PublicationDateGridRow($this->getMonograph());
191  }
192 
198  function getRequestArgs() {
199  $monograph = $this->getMonograph();
200  $publicationFormat = $this->getPublicationFormat();
201 
202  return array(
203  'submissionId' => $monograph->getId(),
204  'publicationFormatId' => $publicationFormat->getId()
205  );
206  }
207 
211  function loadData($request, $filter = null) {
212  $publicationFormat = $this->getPublicationFormat();
213  $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO');
214  $data = $publicationDateDao->getByPublicationFormatId($publicationFormat->getId());
215  return $data->toArray();
216  }
218 
219  //
220  // Public Date Grid Actions
221  //
222 
223  function addDate($args, $request) {
224  return $this->editDate($args, $request);
225  }
226 
233  function editDate($args, $request) {
234  // Identify the date to be updated
235  $publicationDateId = (int) $request->getUserVar('publicationDateId');
236  $monograph = $this->getMonograph();
237 
238  $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO');
239  $publicationDate = $publicationDateDao->getById($publicationDateId, $monograph->getId());
240 
241  // Form handling
242  import('controllers.grid.catalogEntry.form.PublicationDateForm');
243  $publicationDateForm = new PublicationDateForm($monograph, $publicationDate);
244  $publicationDateForm->initData();
245 
246  $json = new JSONMessage(true, $publicationDateForm->fetch($request));
247  return $json->getString();
248  }
249 
256  function updateDate($args, $request) {
257  // Identify the code to be updated
258  $publicationDateId = $request->getUserVar('publicationDateId');
259  $monograph = $this->getMonograph();
260 
261  $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO');
262  $publicationDate = $publicationDateDao->getById($publicationDateId, $monograph->getId());
263 
264  // Form handling
265  import('controllers.grid.catalogEntry.form.PublicationDateForm');
266  $publicationDateForm = new PublicationDateForm($monograph, $publicationDate);
267  $publicationDateForm->readInputData();
268  if ($publicationDateForm->validate()) {
269  $publicationDateId = $publicationDateForm->execute();
270 
271  if(!isset($publicationDate)) {
272  // This is a new code
273  $publicationDate = $publicationDateDao->getById($publicationDateId, $monograph->getId());
274  // New added code action notification content.
275  $notificationContent = __('notification.addedPublicationDate');
276  } else {
277  // code edit action notification content.
278  $notificationContent = __('notification.editedPublicationDate');
279  }
280 
281  // Create trivial notification.
282  $currentUser = $request->getUser();
283  $notificationMgr = new NotificationManager();
284  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
285 
286  // Prepare the grid row data
287  $row = $this->getRowInstance();
288  $row->setGridId($this->getId());
289  $row->setId($publicationDateId);
290  $row->setData($publicationDate);
291  $row->initialize($request);
292 
293  // Render the row into a JSON response
294  return DAO::getDataChangedEvent();
295 
296  } else {
297  $json = new JSONMessage(true, $publicationDateForm->fetch($request));
298  return $json->getString();
299  }
300  }
301 
308  function deleteDate($args, $request) {
309 
310  // Identify the code to be deleted
311  $publicationDateId = $request->getUserVar('publicationDateId');
312 
313  $publicationDateDao = DAORegistry::getDAO('PublicationDateDAO');
314  $publicationDate = $publicationDateDao->getById($publicationDateId, $this->getMonograph()->getId());
315  if ($publicationDate != null) { // authorized
316 
317  $result = $publicationDateDao->deleteObject($publicationDate);
318 
319  if ($result) {
320  $currentUser = $request->getUser();
321  $notificationMgr = new NotificationManager();
322  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedPublicationDate')));
323  return DAO::getDataChangedEvent();
324  } else {
325  $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
326  return $json->getString();
327  }
328  }
329  }
330 }
331 
332 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
static requireComponents()
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
authorize($request, &$args, $roleAssignments)
addColumn($column)
Class defining basic operations for handling HTML grids.
addRoleAssignment($roleIds, $operations)
Publication Date grid row definition.
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
Base class for a cell provider that can retrieve labels for publication dates.
Form for adding/editing a publication date.
Handle publication format grid requests for publication dates.
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.