Open Journal Systems  3.0.0
 All Data Structures 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',
48  null,
49  null,
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  }
146 
147  //
148  // Protected methods.
149  //
154  protected function getNotificationsColumnTitle() {
155  return 'common.tasks';
156  }
158 
159  //
160  // Public methods
161  //
168  function markNew($args, $request) {
169  $notificationDao = DAORegistry::getDAO('NotificationDAO');
170  $user = $request->getUser();
172  $selectedElements = (array) $request->getUserVar('selectedElements');
173  foreach ($selectedElements as $notificationId) {
174  if ($notification = $notificationDao->getById($notificationId, $user->getId())) {
175  $notificationDao->setDateRead($notificationId, null);
176  }
177  }
178  return DAO::getDataChangedEvent(null, null, $selectedElements);
179  }
180 
187  function markRead($args, $request) {
188  $notificationDao = DAORegistry::getDAO('NotificationDAO');
189  $user = $request->getUser();
191  $selectedElements = (array) $request->getUserVar('selectedElements');
192  foreach ($selectedElements as $notificationId) {
193  if ($notification = $notificationDao->getById($notificationId, $user->getId())) {
194  $notificationDao->setDateRead($notificationId, Core::getCurrentDate());
195  }
196  }
197  if ($request->getUserVar('redirect')) {
198  // In this case, the user has clicked on a notification
199  // and wants to view it. Mark it read first and redirect
200  $notificationMgr = new NotificationManager();
201  return $request->redirectUrlJson($notificationMgr->getNotificationUrl($request, $notification));
202  } else {
203  // The notification has been marked read explicitly.
204  // Update its status in the grid.
205  return DAO::getDataChangedEvent(null, null, $selectedElements);
206  }
207  }
208 
215  function deleteNotifications($args, $request) {
216  $notificationDao = DAORegistry::getDAO('NotificationDAO');
217  $user = $request->getUser();
219  $selectedElements = (array) $request->getUserVar('selectedElements');
220  foreach ($selectedElements as $notificationId) {
221  if ($notification = $notificationDao->getById($notificationId, $user->getId())) {
222  $notificationDao->deleteObject($notification);
223  }
224  }
225  return DAO::getDataChangedEvent();
226  }
227 
234  function getUnreadNotificationsCount($args, $request) {
235  $notificationDao = DAORegistry::getDAO('NotificationDAO');
236  $user = $request->getUser();
237  return new JSONMessage(true, $notificationDao->getNotificationCount(false, $user->getId(), null, NOTIFICATION_LEVEL_TASK));
238  }
239 }
240 
241 ?>
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:633
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