Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SponsorGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.settings.SetupGridHandler');
17 import('lib.pkp.controllers.grid.settings.sponsor.SponsorGridRow');
18 import('lib.pkp.classes.linkAction.request.AjaxModal');
19 
24  function SponsorGridHandler() {
25  parent::SetupGridHandler();
26  $this->addRoleAssignment(array(ROLE_ID_MANAGER),
27  array('fetchGrid', 'fetchRow', 'addSponsor', 'editSponsor', 'updateSponsor', 'deleteSponsor'));
28  }
29 
30  //
31  // Overridden template methods
32  //
33  /*
34  * Configure the grid
35  * @param $request PKPRequest
36  */
37  function initialize($request) {
38  parent::initialize($request);
39 
40  // Elements to be displayed in the grid
41  $router = $request->getRouter();
42  $context = $router->getContext($request);
43  $sponsors = $context->getSetting('sponsors');
44  $sponsors = isset($sponsors) ? $sponsors : array();
45  $this->setGridDataElements($sponsors);
46 
47  // Add grid-level actions
48  $router = $request->getRouter();
49  $this->addAction(
50  new LinkAction(
51  'addSponsor',
52  new AjaxModal(
53  $router->url($request, null, null, 'addSponsor', null, array('gridId' => $this->getId())),
54  __('grid.action.addSponsor'),
55  'modal_add_user',
56  true
57  ),
58  __('grid.action.addSponsor'),
59  'add_user')
60  );
61 
62  // Columns
63  $this->addColumn(
64  new GridColumn(
65  'institution',
66  'grid.columns.institution',
67  null,
68  'controllers/grid/gridCell.tpl',
69  null,
70  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
71  )
72  );
73  $this->addColumn(
74  new GridColumn(
75  'url',
76  'grid.columns.url',
77  null,
78  'controllers/grid/gridCell.tpl',
79  null,
80  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
81  )
82  );
83  }
84 
85  //
86  // Overridden methods from GridHandler
87  //
92  function getRowInstance() {
93  return new SponsorGridRow();
94  }
95 
96  //
97  // Public Sponsor Grid Actions
98  //
104  function addSponsor($args, $request) {
105  // Calling editSponsor with an empty row id will add
106  // a new sponsor.
107  return $this->editSponsor($args, $request);
108  }
109 
116  function editSponsor($args, $request) {
117  $sponsorId = isset($args['rowId'])?$args['rowId']:null;
118 
119  import('lib.pkp.controllers.grid.settings.sponsor.form.SponsorForm');
120  $sponsorForm = new SponsorForm($sponsorId);
121 
122  if ($sponsorForm->isLocaleResubmit()) {
123  $sponsorForm->readInputData();
124  } else {
125  $sponsorForm->initData($args, $request);
126  }
127 
128  $json = new JSONMessage(true, $sponsorForm->fetch($request));
129  return $json->getString();
130  }
131 
138  function updateSponsor($args, $request) {
139  // -> sponsorId must be present and valid
140  // -> htmlId must be present and valid
141  $sponsorId = isset($args['rowId'])?$args['rowId']:null;
142 
143  import('lib.pkp.controllers.grid.settings.sponsor.form.SponsorForm');
144  $sponsorForm = new SponsorForm($sponsorId);
145  $sponsorForm->readInputData();
146 
147  if ($sponsorForm->validate()) {
148  $sponsorForm->execute($request);
149 
150  // prepare the grid row data
151  $row = $this->getRowInstance();
152  $row->setGridId($this->getId());
153  $row->setId($sponsorForm->sponsorId);
154  $rowData = array('institution' => $sponsorForm->getData('institution'),
155  'url' => $sponsorForm->getData('url'));
156  $row->setData($rowData);
157  $row->initialize($request);
158  return DAO::getDataChangedEvent($sponsorForm->sponsorId);
159  } else {
160  return new JSONMessage(false);
161  }
162  }
163 
170  function deleteSponsor($args, $request) {
171  $sponsorId = isset($args['rowId'])?$args['rowId']:null;
172  $router = $request->getRouter();
173  $context = $router->getContext($request);
174  $contextSettingsDao = $context->getSettingsDAO();
175 
176  // get all of the sponsors
177  $sponsors = $contextSettingsDao->getSetting($context->getId(), 'sponsors');
178 
179  if (isset($sponsors[$sponsorId])) {
180  unset($sponsors[$sponsorId]);
181  $contextSettingsDao->updateSetting($context->getId(), 'sponsors', $sponsors, 'object');
182  return DAO::getDataChangedEvent($sponsorId);
183  } else {
184  return new JSONMessage(false, __('manager.setup.errorDeletingItem'));
185  }
186  }
187 }
188 
189 ?>
deleteSponsor($args, $request)
updateSponsor($args, $request)
Form for adding/edditing a sponsor stores/retrieves from an associative array.
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
setGridDataElements($data)
addRoleAssignment($roleIds, $operations)
A modal that retrieves its content from via AJAX.
Class to represent a JSON (Javascript Object Notation) message.
Handle sponsor grid row requests.
editSponsor($args, $request)
Handle sponsor grid requests.
Base class for setup grid handlers.
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.