Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPAuthorGridHandler.inc.php
1 <?php
2 
16 // import grid base classes
17 import('lib.pkp.classes.controllers.grid.GridHandler');
18 import('lib.pkp.controllers.grid.users.author.PKPAuthorGridCellProvider');
19 
20 
21 // Link action & modal classes
22 import('lib.pkp.classes.linkAction.request.AjaxModal');
23 
26  var $_submission;
27 
29  var $_readOnly;
30 
34  function PKPAuthorGridHandler() {
35  parent::GridHandler();
36  }
37 
38 
39  //
40  // Getters/Setters
41  //
46  function getSubmission() {
47  return $this->_submission;
48  }
49 
54  function setSubmission($submission) {
55  $this->_submission = $submission;
56  }
57 
62  function getReadOnly() {
63  return $this->_readOnly;
64  }
65 
70  function setReadOnly($readOnly) {
71  $this->_readOnly = $readOnly;
72  }
73 
74 
75  //
76  // Overridden methods from PKPHandler.
77  //
81  function authorize($request, &$args, $roleAssignments) {
82  return parent::authorize($request, $args, $roleAssignments);
83  }
84 
85  /*
86  * Configure the grid
87  * @param $request PKPRequest
88  */
89  function initialize($request) {
90  parent::initialize($request);
91 
92  // Retrieve the authorized submission.
93  $this->setSubmission($this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION));
94 
95  $this->setTitle('submission.contributors');
96  $this->setInstructions('submission.contributorsDescription');
97 
98  // Load pkp-lib translations
100  LOCALE_COMPONENT_PKP_SUBMISSION,
101  LOCALE_COMPONENT_PKP_USER,
102  LOCALE_COMPONENT_PKP_DEFAULT
103  );
104 
105  if ($this->canAdminister()) {
106  $this->setReadOnly(false);
107  // Grid actions
108  $router = $request->getRouter();
109  $actionArgs = $this->getRequestArgs();
110  $this->addAction(
111  new LinkAction(
112  'addAuthor',
113  new AjaxModal(
114  $router->url($request, null, null, 'addAuthor', null, $actionArgs),
115  __('grid.action.addContributor'),
116  'modal_add_user'
117  ),
118  __('grid.action.addContributor'),
119  'add_user'
120  )
121  );
122  } else {
123  $this->setReadOnly(true);
124  }
125 
126  // Columns
127  $cellProvider = new PKPAuthorGridCellProvider();
128  $this->addColumn(
129  new GridColumn(
130  'name',
131  'author.users.contributor.name',
132  null,
133  'controllers/grid/gridCell.tpl',
134  $cellProvider,
135  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
136  )
137  );
138  $this->addColumn(
139  new GridColumn(
140  'email',
141  'author.users.contributor.email',
142  null,
143  'controllers/grid/gridCell.tpl',
144  $cellProvider
145  )
146  );
147  $this->addColumn(
148  new GridColumn(
149  'role',
150  'author.users.contributor.role',
151  null,
152  'controllers/grid/gridCell.tpl',
153  $cellProvider
154  )
155  );
156  $this->addColumn(
157  new GridColumn(
158  'principalContact',
159  'author.users.contributor.principalContact',
160  null,
161  'controllers/grid/users/author/primaryContact.tpl',
162  $cellProvider
163  )
164  );
165  }
166 
167 
168  //
169  // Overridden methods from GridHandler
170  //
174  function initFeatures($request, $args) {
175  $features = parent::initFeatures($request, $args);
176  if ($this->canAdminister()) {
177  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
178  $features[] = new OrderGridItemsFeature();
179  }
180  return $features;
181  }
182 
186  function getDataElementSequence($row) {
187  return $row->getSequence();
188  }
189 
193  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
194  $authorDao = DAORegistry::getDAO('AuthorDAO');
195  $submission = $this->getSubmission();
196  $author = $authorDao->getById($rowId, $submission->getId());
197  $author->setSequence($newSequence);
198  $authorDao->updateObject($author);
199  }
200 
205  function getRowInstance() {
206  return new AuthorGridRow($this->getSubmission(), $this->getReadOnly());
207  }
208 
214  function getRequestArgs() {
215  $submission = $this->getSubmission();
216  return array(
217  'submissionId' => $submission->getId()
218  );
219  }
226  function canAdminister() {
227  return false;
228  }
229 
236  function getRequestedSubmissionId($request) {
237  return $request->getUserVar('submissionId');
238  }
239 
243  function loadData($request, $filter = null) {
244  $submission = $this->getSubmission();
245  $authorDao = DAORegistry::getDAO('AuthorDAO');
246  return $authorDao->getBySubmissionId($submission->getId(), true);
247  }
248 
249  //
250  // Public Author Grid Actions
251  //
257  function addAuthor($args, $request) {
258  // Calling editAuthor() with an empty row id will add
259  // a new author.
260  return $this->editAuthor($args, $request);
261  }
262 
269  function editAuthor($args, $request) {
270  // Identify the author to be updated
271  $authorId = $request->getUserVar('authorId');
272  $submission = $this->getSubmission();
273 
274  $authorDao = DAORegistry::getDAO('AuthorDAO');
275  $author = $authorDao->getById($authorId, $submission->getId());
276 
277  // Form handling
278  import('lib.pkp.controllers.grid.users.author.form.AuthorForm');
279  $authorForm = new AuthorForm($submission, $author, 'submissionId');
280  $authorForm->initData();
281 
282  $json = new JSONMessage(true, $authorForm->fetch($request));
283  return $json->getString();
284  }
285 
292  function updateAuthor($args, $request) {
293  // Identify the author to be updated
294  $authorId = $request->getUserVar('authorId');
295  $submission = $this->getSubmission();
296 
297  $authorDao = DAORegistry::getDAO('AuthorDAO');
298  $author = $authorDao->getById($authorId, $submission->getId());
299 
300  // Form handling
301  import('lib.pkp.controllers.grid.users.author.form.AuthorForm');
302  $authorForm = new AuthorForm($submission, $author, 'submissionId');
303  $authorForm->readInputData();
304  if ($authorForm->validate()) {
305  $authorId = $authorForm->execute();
306 
307  if(!isset($author)) {
308  // This is a new contributor
309  $author = $authorDao->getById($authorId, $submission->getId());
310  // New added author action notification content.
311  $notificationContent = __('notification.addedAuthor');
312  } else {
313  // Author edition action notification content.
314  $notificationContent = __('notification.editedAuthor');
315  }
316 
317  // Create trivial notification.
318  $currentUser = $request->getUser();
319  $notificationMgr = new NotificationManager();
320  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
321 
322  // Prepare the grid row data
323  $row = $this->getRowInstance();
324  $row->setGridId($this->getId());
325  $row->setId($authorId);
326  $row->setData($author);
327  $row->initialize($request);
328 
329  // Render the row into a JSON response
330  if($author->getPrimaryContact()) {
331  // If this is the primary contact, redraw the whole grid
332  // so that it takes the checkbox off other rows.
333  return DAO::getDataChangedEvent();
334  } else {
335  return DAO::getDataChangedEvent($authorId);
336  }
337  } else {
338  $json = new JSONMessage(true, $authorForm->fetch($request));
339  return $json->getString();
340  }
341  }
342 
349  function deleteAuthor($args, $request) {
350  // Identify the submission Id
351  $submissionId = $this->getRequestedSubmissionId($request);
352  // Identify the author to be deleted
353  $authorId = $request->getUserVar('authorId');
354 
355  $authorDao = DAORegistry::getDAO('AuthorDAO');
356  $result = $authorDao->deleteById($authorId, $submissionId);
357 
358  if ($result) {
359  return DAO::getDataChangedEvent($authorId);
360  } else {
361  $json = new JSONMessage(false, __('submission.submit.errorDeletingAuthor'));
362  return $json->getString();
363  }
364  }
365 
372  function addUser($args, $request) {
373  // Identify the author Id.
374  $authorId = $request->getUserVar('authorId');
375 
376  $authorDao = DAORegistry::getDAO('AuthorDAO');
377  $userDao = DAORegistry::getDAO('UserDAO');
378  $author = $authorDao->getById($authorId);
379 
380  if ($author !== null && $userDao->userExistsByEmail($author->getEmail())) {
381  // We don't have administrative rights over this user.
382  $json = new JSONMessage(false, __('grid.user.cannotAdminister'));
383  } else {
384  // Form handling.
385  import('lib.pkp.controllers.grid.settings.user.form.UserDetailsForm');
386  $userForm = new UserDetailsForm($request, null, $author);
387  $userForm->initData($args, $request);
388 
389  $json = new JSONMessage(true, $userForm->display($args, $request));
390  }
391  return $json->getString();
392  }
393 }
394 
395 ?>
static & getDAO($name, $dbconn=null)
static requireComponents()
Form for adding/editing a author.
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
Class defining basic operations for handling HTML grids.
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
Author grid row definition.
authorize($request, &$args, $roleAssignments)
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
Implements grid ordering functionality.
Form for editing user profiles.
setInstructions($instructions)
base PKP class to handle author grid requests.
loadData($request, $filter=null)
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.