Open Journal Systems  3.3.0
AuthorGridHandler.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 import('lib.pkp.controllers.grid.users.author.AuthorGridRow');
20 
21 // Link action & modal classes
22 import('lib.pkp.classes.linkAction.request.AjaxModal');
23 
26  var $_readOnly;
27 
29  var $_version;
30 
34  function __construct() {
35  parent::__construct();
36  $this->addRoleAssignment(
37  array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT, ROLE_ID_AUTHOR),
38  array('fetchGrid', 'fetchRow', 'addAuthor', 'editAuthor',
39  'updateAuthor', 'deleteAuthor', 'saveSequence'));
40  $this->addRoleAssignment(ROLE_ID_REVIEWER, array('fetchGrid', 'fetchRow'));
41  $this->addRoleAssignment(array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT), array('addUser'));
42  }
43 
44 
45  //
46  // Getters/Setters
47  //
52  function getSubmission() {
53  return $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
54  }
55 
60  function getPublication() {
61  return $this->getAuthorizedContextObject(ASSOC_TYPE_PUBLICATION);
62  }
63 
68  function getReadOnly() {
69  return $this->_readOnly;
70  }
71 
76  function setReadOnly($readOnly) {
77  $this->_readOnly = $readOnly;
78  }
79 
80  //
81  // Overridden methods from PKPHandler.
82  //
86  function authorize($request, &$args, $roleAssignments) {
87  import('lib.pkp.classes.security.authorization.PublicationAccessPolicy');
88  $this->addPolicy(new PublicationAccessPolicy($request, $args, $roleAssignments));
89  return parent::authorize($request, $args, $roleAssignments);
90  }
91 
95  function initialize($request, $args = null) {
96  parent::initialize($request, $args);
97 
98  $this->setTitle('submission.contributors');
99 
100  // Load pkp-lib translations
102  LOCALE_COMPONENT_APP_SUBMISSION,
103  LOCALE_COMPONENT_APP_DEFAULT,
104  LOCALE_COMPONENT_PKP_SUBMISSION,
105  LOCALE_COMPONENT_PKP_USER,
106  LOCALE_COMPONENT_PKP_DEFAULT
107  );
108 
109  if ($this->getSubmission()->getData('submissionProgress') || $this->canAdminister($request->getUser())) {
110  $this->setReadOnly(false);
111  // Grid actions
112  $router = $request->getRouter();
113  $actionArgs = $this->getRequestArgs();
114 
115  $this->addAction(
116  new LinkAction(
117  'addAuthor',
118  new AjaxModal(
119  $router->url($request, null, null, 'addAuthor', null, $actionArgs),
120  __('grid.action.addContributor'),
121  'modal_add_user'
122  ),
123  __('grid.action.addContributor'),
124  'add_user'
125  )
126  );
127  } else {
128  $this->setReadOnly(true);
129  }
130 
131  // Columns
132  $cellProvider = new PKPAuthorGridCellProvider($this->getPublication());
133  $this->addColumn(
134  new GridColumn(
135  'name',
136  'author.users.contributor.name',
137  null,
138  null,
139  $cellProvider,
140  array('width' => 40, 'alignment' => COLUMN_ALIGNMENT_LEFT)
141  )
142  );
143  $this->addColumn(
144  new GridColumn(
145  'email',
146  'author.users.contributor.email',
147  null,
148  null,
149  $cellProvider
150  )
151  );
152  $this->addColumn(
153  new GridColumn(
154  'role',
155  'author.users.contributor.role',
156  null,
157  null,
158  $cellProvider
159  )
160  );
161  $this->addColumn(
162  new GridColumn(
163  'principalContact',
164  'author.users.contributor.principalContact',
165  null,
166  'controllers/grid/users/author/primaryContact.tpl',
167  $cellProvider
168  )
169  );
170  $this->addColumn(
171  new GridColumn(
172  'includeInBrowse',
173  'author.users.contributor.includeInBrowse',
174  null,
175  'controllers/grid/users/author/includeInBrowse.tpl',
176  $cellProvider
177  )
178  );
179  }
180 
181 
182  //
183  // Overridden methods from GridHandler
184  //
188  function initFeatures($request, $args) {
189  $features = parent::initFeatures($request, $args);
190  if ($this->canAdminister($request->getUser())) {
191  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
192  $features[] = new OrderGridItemsFeature();
193  }
194  return $features;
195  }
196 
200  function getDataElementSequence($gridDataElement) {
201  return $gridDataElement->getSequence();
202  }
203 
207  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
208  if (!$this->canAdminister($request->getUser())) return;
209  $authorDao = DAORegistry::getDAO('AuthorDAO'); /* @var $authorDao AuthorDAO */
210  $author = $authorDao->getById($rowId);
211  $author->setSequence($newSequence);
212  $authorDao->updateObject($author);
213  }
214 
219  protected function getRowInstance() {
220  return new AuthorGridRow($this->getSubmission(), $this->getPublication(), $this->getReadOnly());
221  }
222 
228  function getRequestArgs() {
229  $submission = $this->getSubmission();
230  $publication = $this->getPublication();
231  return array(
232  'submissionId' => $submission->getId(),
233  'publicationId' => $publication->getId()
234  );
235  }
236 
242  function canAdminister($user) {
243  $publication = $this->getPublication();
244  $submission = $this->getSubmission();
245  $userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
246 
247  if ($publication->getData('status') === STATUS_PUBLISHED) {
248  return false;
249  }
250 
251  if (in_array(ROLE_ID_SITE_ADMIN, $userRoles)) {
252  return true;
253  }
254 
255  // Incomplete submissions can be edited. (Presumably author.)
256  if ($submission->getDateSubmitted() == null) return true;
257 
258  // The user may not be allowed to edit the metadata
259  if (Services::get('submission')->canEditPublication($submission->getId(), $user->getId())) {
260  return true;
261  }
262 
263  // Default: Read-only.
264  return false;
265  }
266 
270  protected function loadData($request, $filter = null) {
271  $authorDao = DAORegistry::getDAO('AuthorDAO'); /* @var $authorDao AuthorDAO */
272  return $authorDao->getByPublicationId($this->getPublication()->getId(), true, false);
273  }
274 
275  //
276  // Public Author Grid Actions
277  //
283  function addAuthor($args, $request) {
284  if (!$this->canAdminister($request->getUser())) return new JSONMessage(false);
285  // Calling editAuthor() with an empty row id will add
286  // a new author.
287  return $this->editAuthor($args, $request);
288  }
289 
296  function editAuthor($args, $request) {
297  if (!$this->canAdminister($request->getUser())) return new JSONMessage(false);
298  // Identify the author to be updated
299  $authorId = (int) $request->getUserVar('authorId');
300 
301  $authorDao = DAORegistry::getDAO('AuthorDAO'); /* @var $authorDao AuthorDAO */
302  $author = $authorDao->getById($authorId);
303 
304  // Form handling
305  import('controllers.grid.users.author.form.AuthorForm');
306  $authorForm = new AuthorForm($this->getPublication(), $author);
307  $authorForm->initData();
308 
309  return new JSONMessage(true, $authorForm->fetch($request));
310  }
311 
318  function updateAuthor($args, $request) {
319  if (!$this->canAdminister($request->getUser())) return new JSONMessage(false);
320  // Identify the author to be updated
321  $authorId = (int) $request->getUserVar('authorId');
322  $publication = $this->getPublication();
323 
324  $author = Services::get('author')->get($authorId);
325 
326  // Form handling
327  import('controllers.grid.users.author.form.AuthorForm');
328  $authorForm = new AuthorForm($publication, $author);
329  $authorForm->readInputData();
330  if ($authorForm->validate()) {
331  $authorId = $authorForm->execute();
332 
333  if(!isset($author)) {
334  // This is a new contributor
335  $author = Services::get('author')->get($authorId);
336  // New added author action notification content.
337  $notificationContent = __('notification.addedAuthor');
338  } else {
339  // Author edition action notification content.
340  $notificationContent = __('notification.editedAuthor');
341  }
342 
343  // Create trivial notification.
344  $currentUser = $request->getUser();
345  $notificationMgr = new NotificationManager();
346  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
347 
348  // Prepare the grid row data
349  $row = $this->getRowInstance();
350  $row->setGridId($this->getId());
351  $row->setId($authorId);
352  $row->setData($author);
353  $row->initialize($request);
354 
355  // Render the row into a JSON response
356  if($author->getPrimaryContact()) {
357  // If this is the primary contact, redraw the whole grid
358  // so that it takes the checkbox off other rows.
359  $json = DAO::getDataChangedEvent();
360  } else {
361  $json = DAO::getDataChangedEvent($authorId);
362  }
363  $json->setGlobalEvent('authorsUpdated');
364  return $json;
365  } else {
366  return new JSONMessage(true, $authorForm->fetch($request));
367  }
368  }
369 
376  function deleteAuthor($args, $request) {
377  if (!$request->checkCSRF()) return new JSONMessage(false);
378  if (!$this->canAdminister($request->getUser())) return new JSONMessage(false);
379 
380  $authorId = (int) $request->getUserVar('authorId');
381 
382  $authorDao = DAORegistry::getDAO('AuthorDAO'); /* @var $authorDao AuthorDAO */
383  $authorDao->deleteById($authorId);
384  $json = DAO::getDataChangedEvent($authorId);
385  $json->setGlobalEvent('authorsUpdated');
386  return $json;
387  }
388 
395  function addUser($args, $request) {
396  // Identify the author Id.
397  $authorId = (int) $request->getUserVar('authorId');
398 
399  $authorDao = DAORegistry::getDAO('AuthorDAO'); /* @var $authorDao AuthorDAO */
400  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
401  $author = $authorDao->getById($authorId);
402 
403  if ($author !== null && $userDao->userExistsByEmail($author->getEmail())) {
404  // We don't have administrative rights over this user.
405  return new JSONMessage(false, __('grid.user.cannotAdminister'));
406  } else {
407  // Form handling.
408  import('lib.pkp.controllers.grid.settings.user.form.UserDetailsForm');
409  $userForm = new UserDetailsForm($request, null, $author);
410  $userForm->initData();
411 
412  return new JSONMessage(true, $userForm->display($request));
413  }
414  }
415 }
PKPHandler\addRoleAssignment
addRoleAssignment($roleIds, $operations)
Definition: PKPHandler.inc.php:213
AuthorGridHandler\setReadOnly
setReadOnly($readOnly)
Definition: AuthorGridHandler.inc.php:82
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
AuthorGridHandler\getDataElementSequence
getDataElementSequence($gridDataElement)
Definition: AuthorGridHandler.inc.php:206
PublicationAccessPolicy
Class to control access to a publication.
Definition: PublicationAccessPolicy.inc.php:20
AuthorGridHandler\getPublication
getPublication()
Definition: AuthorGridHandler.inc.php:66
AuthorGridHandler
base PKP class to handle author grid requests.
Definition: AuthorGridHandler.inc.php:24
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PKPAuthorGridCellProvider
Definition: PKPAuthorGridCellProvider.inc.php:18
AuthorGridHandler\$_version
$_version
Definition: AuthorGridHandler.inc.php:35
AuthorGridHandler\loadData
loadData($request, $filter=null)
Definition: AuthorGridHandler.inc.php:276
AuthorGridHandler\addAuthor
addAuthor($args, $request)
Definition: AuthorGridHandler.inc.php:289
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKPHandler\getId
getId()
Definition: PKPHandler.inc.php:107
AuthorGridHandler\addUser
addUser($args, $request)
Definition: AuthorGridHandler.inc.php:401
AuthorGridHandler\editAuthor
editAuthor($args, $request)
Definition: AuthorGridHandler.inc.php:302
AuthorGridHandler\getRequestArgs
getRequestArgs()
Definition: AuthorGridHandler.inc.php:234
AuthorGridHandler\canAdminister
canAdminister($user)
Definition: AuthorGridHandler.inc.php:248
GridHandler\addAction
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
Definition: GridHandler.inc.php:266
GridHandler\addColumn
addColumn($column)
Definition: GridHandler.inc.php:335
AuthorGridHandler\getRowInstance
getRowInstance()
Definition: AuthorGridHandler.inc.php:225
AuthorGridHandler\$_readOnly
$_readOnly
Definition: AuthorGridHandler.inc.php:29
AuthorGridHandler\updateAuthor
updateAuthor($args, $request)
Definition: AuthorGridHandler.inc.php:324
DAO\getDataChangedEvent
static getDataChangedEvent($elementId=null, $parentElementId=null, $content='')
Definition: DAO.inc.php:647
AuthorGridHandler\setDataElementSequence
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
Definition: AuthorGridHandler.inc.php:213
AuthorGridHandler\deleteAuthor
deleteAuthor($args, $request)
Definition: AuthorGridHandler.inc.php:382
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
AuthorGridHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: AuthorGridHandler.inc.php:92
AuthorGridHandler\initialize
initialize($request, $args=null)
Definition: AuthorGridHandler.inc.php:101
GridHandler\setTitle
setTitle($title)
Definition: GridHandler.inc.php:215
AuthorGridHandler\getSubmission
getSubmission()
Definition: AuthorGridHandler.inc.php:58
AuthorGridHandler\__construct
__construct()
Definition: AuthorGridHandler.inc.php:40
PKPHandler\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: PKPHandler.inc.php:174
AuthorGridHandler\getReadOnly
getReadOnly()
Definition: AuthorGridHandler.inc.php:74
UserDetailsForm
Form for editing user profiles.
Definition: UserDetailsForm.inc.php:18
GridHandler
This class defines basic operations for handling HTML grids. Grids are used to implement a standardiz...
Definition: GridHandler.inc.php:58
NotificationManager
Definition: NotificationManager.inc.php:19
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157
AuthorForm
Form for adding/editing a author.
Definition: AuthorForm.inc.php:18
AuthorGridHandler\initFeatures
initFeatures($request, $args)
Definition: AuthorGridHandler.inc.php:194
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49
AuthorGridRow
Base class for author grid row definition.
Definition: AuthorGridRow.inc.php:18