Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AnnouncementGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.grid.GridHandler');
17 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
18 import('lib.pkp.classes.controllers.grid.DateGridCellProvider');
19 
25  parent::GridHandler();
26  }
27 
28 
29  //
30  // Overridden template methods
31  //
36  function authorize($request, &$args, $roleAssignments, $requireAnnouncementsEnabled = true) {
37 
38  import('lib.pkp.classes.security.authorization.ContextRequiredPolicy');
39  $this->addPolicy(new ContextRequiredPolicy($request));
40 
41  $returner = parent::authorize($request, $args, $roleAssignments);
42 
43  // Ensure announcements are enabled.
44  $context = $request->getContext();
45  if ($requireAnnouncementsEnabled && !$context->getSetting('enableAnnouncements')) {
46  return false;
47  }
48 
49  $announcementId = $request->getUserVar('announcementId');
50  if ($announcementId) {
51  // Ensure announcement is valid and for this context
52  $announcementDao = DAORegistry::getDAO('AnnouncementDAO'); /* @var $announcementDao AnnouncementDAO */
53  if ($announcementDao->getAnnouncementAssocType($announcementId) != $context->getAssocType() &&
54  $announcementDao->getAnnouncementAssocId($announcementId) != $context->getId()) {
55  return false;
56  }
57  }
58 
59  return $returner;
60  }
61 
65  function initialize($request) {
66  parent::initialize($request);
67 
68  // Set the no items row text
69  $this->setEmptyRowText('announcement.noneExist');
70 
71  $context = $request->getContext();
72 
73  // Columns
74  import('lib.pkp.controllers.grid.announcements.AnnouncementGridCellProvider');
75  $announcementCellProvider = new AnnouncementGridCellProvider();
76  $this->addColumn(
77  new GridColumn('title',
78  'common.title',
79  null,
80  'controllers/grid/gridCell.tpl',
81  $announcementCellProvider,
82  array('width' => 60)
83  )
84  );
85 
86  $this->addColumn(
87  new GridColumn('type',
88  'common.type',
89  null,
90  'controllers/grid/gridCell.tpl',
91  $announcementCellProvider
92  )
93  );
94 
95  $dateCellProvider = new DateGridCellProvider(
97  Config::getVar('general', 'date_format_short')
98  );
99  $this->addColumn(
100  new GridColumn(
101  'datePosted',
102  'announcement.posted',
103  null,
104  'controllers/grid/gridCell.tpl',
105  $dateCellProvider
106  )
107  );
108  }
109 
113  function loadData($request, $filter) {
114  $context = $request->getContext();
115  $announcementDao = DAORegistry::getDAO('AnnouncementDAO');
116  $rangeInfo = $this->getGridRangeInfo($request, $this->getId());
117  $announcements = $announcementDao->getAnnouncementsNotExpiredByAssocId($context->getAssocType(), $context->getId(), $rangeInfo);
118 
119  return $announcements;
120  }
121 
122 
123  //
124  // Public grid actions.
125  //
132  function moreInformation($args, $request) {
133  $announcementId = (int)$request->getUserVar('announcementId');
134  $context = $request->getContext();
135  $contextId = $context->getId();
136 
137  import('controllers.grid.announcements.form.AnnouncementForm');
138  $announcementForm = new AnnouncementForm($contextId, $announcementId, true);
139 
140  $announcementForm->initData($args, $request);
141 
142  $json = new JSONMessage(true, $announcementForm->fetch($request));
143  return $json->getString();
144  }
145 }
146 
147 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
Handle announcements grid requests.
Cell provider for title column of a announcement grid.
Policy to deny access if a context cannot be found in the request.
setEmptyRowText($emptyRowText)
addColumn($column)
Class defining basic operations for handling HTML grids.
Class to represent a JSON (Javascript Object Notation) message.
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
Base class for a cell provider that can retrieve simple labels from DataObjects. If you need more com...
Wraps date formatting support around a provided DataProvider.
getGridRangeInfo($request, $rangeName, $contextData=null)
Form for to read/create/edit announcements.
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
authorize($request, &$args, $roleAssignments, $requireAnnouncementsEnabled=true)