Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
NotificationsGridHandler.inc.php
1 <?php
2 
16 // Import UI base classes.
17 import('lib.pkp.classes.controllers.grid.GridHandler');
18 
19 // Other classes associated with this grid
20 import('lib.pkp.controllers.grid.notifications.NotificationsGridCellProvider');
21 
25 
29  function NotificationsGridHandler() {
30  parent::GridHandler();
31  }
32 
33 
37  function initialize($request, $args = null) {
38  parent::initialize($request);
39  AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION, LOCALE_COMPONENT_PKP_SUBMISSION);
40 
41  $this->_selectedNotificationIds = (array) $request->getUserVar('selectedNotificationIds');
42 
43  $cellProvider = new NotificationsGridCellProvider();
44  $this->addColumn(
45  new GridColumn(
46  'task',
47  'common.tasks',
48  null,
49  'controllers/grid/gridCell.tpl',
50  $cellProvider,
51  array('html' => true,
52  'alignment' => COLUMN_ALIGNMENT_LEFT)
53  )
54  );
55 
56  // Set the no items row text
57  $this->setEmptyRowText('grid.noItems');
58 
59  import('lib.pkp.classes.linkAction.request.NullAction');
60  $this->addAction(
61  new LinkAction(
62  'markNew',
63  new NullAction(),
64  __('grid.action.markNew'),
65  'edit' // FIXME: Icon
66  ),
67  GRID_ACTION_POSITION_BELOW
68  );
69  $this->addAction(
70  new LinkAction(
71  'markRead',
72  new NullAction(),
73  __('grid.action.markRead'),
74  'edit' // FIXME: Icon
75  ),
76  GRID_ACTION_POSITION_BELOW
77  );
78 
79  $router = $request->getRouter();
80  $this->addAction(
81  new LinkAction(
82  'deleteNotifications',
83  new NullAction(),
84  __('grid.action.delete'),
85  'delete'
86  ),
87  GRID_ACTION_POSITION_BELOW
88  );
89  }
90 
91 
92  //
93  // Overridden methods from GridHandler
94  //
98  public function getJSHandler() {
99  return '$.pkp.controllers.grid.notifications.NotificationsGridHandler';
100  }
105  function setUrls($request) {
106  $router = $request->getRouter();
107  parent::setUrls($request, array(
108  'markNewUrl' => $router->url($request, null, null, 'markNew', null, $this->getRequestArgs()),
109  'markReadUrl' => $router->url($request, null, null, 'markRead', null, $this->getRequestArgs()),
110  'deleteUrl' => $router->url($request, null, null, 'deleteNotifications', null, $this->getRequestArgs()),
111  ));
112  }
113 
119  function getPublishChangeEvents() {
120  return array('updateUnreadNotificationsCount');
121  }
126  function initFeatures($request, $args) {
127  import('lib.pkp.classes.controllers.grid.feature.selectableItems.SelectableItemsFeature');
128  import('lib.pkp.classes.controllers.grid.feature.PagingFeature');
129  return array(new SelectableItemsFeature(), new PagingFeature());
130  }
131 
135  function getSelectName() {
136  return 'selectedNotifications';
137  }
142  function isDataElementSelected($gridDataElement) {
143  return in_array($gridDataElement->getId(), $this->_selectedNotificationIds);
144  }
150  protected function loadData($request, $filter) {
151  $user = $request->getUser();
152 
153  // Get all level task notifications.
154  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
155  $notifications = $notificationDao->getByUserId($user->getId(), NOTIFICATION_LEVEL_TASK);
156  $rowData = $notifications->toAssociativeArray();
157 
158  // Remove not listable task types.
159  $notListableTaskTypes = $this->getNotListableTaskTypes();
160  foreach ($rowData as $key => $notification) {
161  if (in_array($notification->getType(), $notListableTaskTypes)) {
162  unset($rowData[$key]);
163  }
164  }
165 
166  return $rowData;
167  }
168 
169 
170  //
171  // Public methods
172  //
179  function markNew($args, $request) {
180  $notificationDao = DAORegistry::getDAO('NotificationDAO');
181  $user = $request->getUser();
183  $selectedElements = (array) $request->getUserVar('selectedElements');
184  foreach ($selectedElements as $notificationId) {
185  if ($notification = $notificationDao->getById($notificationId, $user->getId())) {
186  $notificationDao->setDateRead($notificationId, null);
187  }
188  }
189  return DAO::getDataChangedEvent(null, null, $selectedElements);
190  }
191 
198  function markRead($args, $request) {
199  $notificationDao = DAORegistry::getDAO('NotificationDAO');
200  $user = $request->getUser();
202  $selectedElements = (array) $request->getUserVar('selectedElements');
203  foreach ($selectedElements as $notificationId) {
204  if ($notification = $notificationDao->getById($notificationId, $user->getId())) {
205  $notificationDao->setDateRead($notificationId, Core::getCurrentDate());
206  }
207  }
208  if ($request->getUserVar('redirect')) {
209  // In this case, the user has clicked on a notification
210  // and wants to view it. Mark it read first and redirect
211  $notificationMgr = new NotificationManager();
212  return $request->redirectUrlJson($notificationMgr->getNotificationUrl($request, $notification));
213  } else {
214  // The notification has been marked read explicitly.
215  // Update its status in the grid.
216  return DAO::getDataChangedEvent(null, null, $selectedElements);
217  }
218  }
219 
226  function deleteNotifications($args, $request) {
227  $notificationDao = DAORegistry::getDAO('NotificationDAO');
228  $user = $request->getUser();
230  $selectedElements = (array) $request->getUserVar('selectedElements');
231  foreach ($selectedElements as $notificationId) {
232  if ($notification = $notificationDao->getById($notificationId, $user->getId())) {
233  $notificationDao->deleteObject($notification);
234  }
235  }
236  return DAO::getDataChangedEvent();
237  }
238 
245  function getUnreadNotificationsCount($args, $request) {
246  $notificationDao = DAORegistry::getDAO('NotificationDAO');
247  $user = $request->getUser();
248  $json = new JSONMessage(true, $notificationDao->getNotificationCount(false, $user->getId(), null, NOTIFICATION_LEVEL_TASK, $this->getNotListableTaskTypes()));
249  return $json->getString();
250  }
251 
256  static function getNotListableTaskTypes() {
257  return array(NOTIFICATION_TYPE_SIGNOFF_COPYEDIT, NOTIFICATION_TYPE_SIGNOFF_PROOF);
258  }
259 }
260 
261 ?>
static & getDAO($name, $dbconn=null)
Implements grid widgets selectable items functionality.
static requireComponents()
setEmptyRowText($emptyRowText)
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
This class defines basic operations for handling HTML grids. Grids are used to implement a standardiz...
Class to represent a JSON (Javascript Object Notation) message.
Add paging functionality to grids.
Handle the display of notifications for a given user.
Class for a cell provider that can retrieve labels from notifications.
The GridColumn class represents a column within a grid. It is used to format the data presented in a ...
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:632
Base class defining an action that can be performed by the user in the user interface.
This action does nothing.
static getCurrentDate($ts=null)
Definition: Core.inc.php:95