Open Journal Systems  3.3.0
QueryNotesGridHandler.inc.php
1 <?php
2 
16 // import grid base classes
17 import('lib.pkp.classes.controllers.grid.GridHandler');
18 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
19 
20 // Link action & modal classes
21 import('lib.pkp.classes.linkAction.request.AjaxModal');
22 
25  var $_user;
26 
30  function __construct() {
31  parent::__construct();
32  $this->addRoleAssignment(
33  array(ROLE_ID_MANAGER, ROLE_ID_REVIEWER, ROLE_ID_AUTHOR, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT),
34  array('fetchGrid', 'fetchRow', 'addNote', 'insertNote', 'deleteNote'));
35  }
36 
37 
38  //
39  // Getters/Setters
40  //
45  function getSubmission() {
46  return $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
47  }
48 
53  function getQuery() {
54  return $this->getAuthorizedContextObject(ASSOC_TYPE_QUERY);
55  }
56 
61  function getStageId() {
62  return $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
63  }
64 
65  //
66  // Overridden methods from PKPHandler.
67  // Note: this is subclassed in application-specific grids.
68  //
72  function authorize($request, &$args, $roleAssignments) {
73  $stageId = $request->getUserVar('stageId'); // This is being validated in WorkflowStageAccessPolicy
74 
75  // Get the access policy
76  import('lib.pkp.classes.security.authorization.QueryAccessPolicy');
77  $this->addPolicy(new QueryAccessPolicy($request, $args, $roleAssignments, $stageId));
78  return parent::authorize($request, $args, $roleAssignments);
79  }
80 
84  function initialize($request, $args = null) {
85  parent::initialize($request, $args);
86  $this->setTitle('submission.query.messages');
87 
88  // Load pkp-lib translations
90  LOCALE_COMPONENT_PKP_SUBMISSION,
91  LOCALE_COMPONENT_PKP_USER,
92  LOCALE_COMPONENT_PKP_EDITOR
93  );
94 
95  import('lib.pkp.controllers.grid.queries.QueryNotesGridCellProvider');
96  $cellProvider = new QueryNotesGridCellProvider($this->getSubmission());
97 
98  // Columns
99  $this->addColumn(
100  new GridColumn(
101  'contents',
102  'common.note',
103  null,
104  null,
105  $cellProvider,
106  array('width' => 80, 'html' => true)
107  )
108  );
109  $this->addColumn(
110  new GridColumn(
111  'from',
112  'submission.query.from',
113  null,
114  null,
115  $cellProvider,
116  array('html' => true)
117  )
118  );
119 
120  $this->_user = $request->getUser();
121  }
122 
123 
124  //
125  // Overridden methods from GridHandler
126  //
131  function getRowInstance() {
132  import('lib.pkp.controllers.grid.queries.QueryNotesGridRow');
133  return new QueryNotesGridRow($this->getRequestArgs(), $this->getQuery(), $this);
134  }
135 
141  function getRequestArgs() {
142  return array(
143  'submissionId' => $this->getSubmission()->getId(),
144  'stageId' => $this->getStageId(),
145  'queryId' => $this->getQuery()->getId(),
146  );
147  }
148 
152  function loadData($request, $filter = null) {
153  return $this->getQuery()->getReplies(null, NOTE_ORDER_DATE_CREATED, SORT_DIRECTION_ASC, $this->getCanManage(null));
154  }
155 
156  //
157  // Public Query Notes Grid Actions
158  //
164  function addNote($args, $request) {
165  import('lib.pkp.controllers.grid.queries.form.QueryNoteForm');
166  $queryNoteForm = new QueryNoteForm($this->getRequestArgs(), $this->getQuery(), $request->getUser());
167  $queryNoteForm->initData();
168  return new JSONMessage(true, $queryNoteForm->fetch($request));
169  }
170 
176  function insertNote($args, $request) {
177  import('lib.pkp.controllers.grid.queries.form.QueryNoteForm');
178  $queryNoteForm = new QueryNoteForm($this->getRequestArgs(), $this->getQuery(), $request->getUser(), $request->getUserVar('noteId'));
179  $queryNoteForm->readInputData();
180  if ($queryNoteForm->validate()) {
181  $note = $queryNoteForm->execute();
182  return DAO::getDataChangedEvent($this->getQuery()->getId());
183  } else {
184  return new JSONMessage(true, $queryNoteForm->fetch($request));
185  }
186  }
187 
193  function getCanManage($note) {
194  $isAdmin = (0 != count(array_intersect(
195  $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES),
196  array(ROLE_ID_MANAGER, ROLE_ID_ASSISTANT, ROLE_ID_SUB_EDITOR)
197  )));
198 
199  if ($note === null) {
200  return $isAdmin;
201  } else {
202  return ($note->getUserId() == $this->_user->getId() || $isAdmin);
203  }
204  }
205 
212  function deleteNote($args, $request) {
213  $query = $this->getQuery();
214  $noteDao = DAORegistry::getDAO('NoteDAO'); /* @var $noteDao NoteDAO */
215  $note = $noteDao->getById($request->getUserVar('noteId'));
216  $user = $request->getUser();
217 
218  if (!$request->checkCSRF() || !$note || $note->getAssocType() != ASSOC_TYPE_QUERY || $note->getAssocId() != $query->getId()) {
219  // The note didn't exist or has the wrong assoc info.
220  return new JSONMessage(false);
221  }
222 
223  if (!$this->getCanManage($note)) {
224  // The user doesn't own the note and isn't priveleged enough to delete it.
225  return new JSONMessage(false);
226  }
227 
228  $noteDao->deleteObject($note);
229  return DAO::getDataChangedEvent($note->getId());
230  }
231 
232 }
233 
234 
PKPHandler\addRoleAssignment
addRoleAssignment($roleIds, $operations)
Definition: PKPHandler.inc.php:213
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
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
QueryNotesGridHandler\$_user
$_user
Definition: QueryNotesGridHandler.inc.php:28
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
QueryNotesGridHandler\initialize
initialize($request, $args=null)
Definition: QueryNotesGridHandler.inc.php:87
PKPHandler\getId
getId()
Definition: PKPHandler.inc.php:107
QueryNotesGridCellProvider
Base class for a cell provider that can retrieve query note info.
Definition: QueryNotesGridCellProvider.inc.php:18
QueryNotesGridHandler\deleteNote
deleteNote($args, $request)
Definition: QueryNotesGridHandler.inc.php:215
QueryNotesGridHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: QueryNotesGridHandler.inc.php:75
QueryAccessPolicy
Class to control access to queries.
Definition: QueryAccessPolicy.inc.php:18
GridHandler\addColumn
addColumn($column)
Definition: GridHandler.inc.php:335
QueryNotesGridHandler\loadData
loadData($request, $filter=null)
Definition: QueryNotesGridHandler.inc.php:155
QueryNotesGridHandler\getStageId
getStageId()
Definition: QueryNotesGridHandler.inc.php:64
DAO\getDataChangedEvent
static getDataChangedEvent($elementId=null, $parentElementId=null, $content='')
Definition: DAO.inc.php:647
JSONMessage
Class to represent a JSON (Javascript Object Notation) message.
Definition: JSONMessage.inc.php:18
QueryNotesGridHandler\getRequestArgs
getRequestArgs()
Definition: QueryNotesGridHandler.inc.php:144
QueryNotesGridHandler\__construct
__construct()
Definition: QueryNotesGridHandler.inc.php:33
Seboettg\Collection\count
count()
Definition: ArrayListTrait.php:253
QueryNotesGridHandler\getCanManage
getCanManage($note)
Definition: QueryNotesGridHandler.inc.php:196
QueryNotesGridHandler\getRowInstance
getRowInstance()
Definition: QueryNotesGridHandler.inc.php:134
GridHandler\setTitle
setTitle($title)
Definition: GridHandler.inc.php:215
PKPHandler\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: PKPHandler.inc.php:174
QueryNotesGridHandler\getSubmission
getSubmission()
Definition: QueryNotesGridHandler.inc.php:48
QueryNoteForm
Form for adding/editing a new query note.
Definition: QueryNoteForm.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
QueryNotesGridHandler\insertNote
insertNote($args, $request)
Definition: QueryNotesGridHandler.inc.php:179
QueryNotesGridHandler\getQuery
getQuery()
Definition: QueryNotesGridHandler.inc.php:56
QueryNotesGridHandler\addNote
addNote($args, $request)
Definition: QueryNotesGridHandler.inc.php:167
QueryNotesGridHandler
base PKP class to handle query grid requests.
Definition: QueryNotesGridHandler.inc.php:23
QueryNotesGridRow
Base class for query grid row definition.
Definition: QueryNotesGridRow.inc.php:18
PKPHandler\addPolicy
addPolicy($authorizationPolicy, $addToTop=false)
Definition: PKPHandler.inc.php:157