Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ContributorGridHandler.inc.php
1 <?php
2 
16 // Import grid base classes
17 import('lib.pkp.controllers.grid.settings.SetupGridHandler');
18 
19 // Import Contributor grid specific classes
20 import('lib.pkp.controllers.grid.settings.contributor.ContributorGridRow');
21 import('lib.pkp.classes.linkAction.request.AjaxModal');
22 
28  parent::SetupGridHandler();
29  $this->addRoleAssignment(array(ROLE_ID_MANAGER),
30  array('fetchGrid', 'addContributor', 'editContributor', 'updateContributor', 'deleteContributor'));
31  }
32 
33  //
34  // Overridden template methods
35  //
36  /*
37  * Configure the grid
38  * @param $request PKPRequest
39  */
40  function initialize($request) {
41  parent::initialize($request);
42 
43  // Elements to be displayed in the grid
44  $router = $request->getRouter();
45  $context = $router->getContext($request);
46  $contributors = $context->getSetting('contributors');
47  $contributors = isset($contributors) ? $contributors : array();
48  $this->setGridDataElements($contributors);
49 
50  // Add grid-level actions
51  $router = $request->getRouter();
52 
53  $this->addAction(
54  new LinkAction(
55  'addContributor',
56  new AjaxModal(
57  $router->url($request, null, null, 'addContributor', null, array('gridId' => $this->getId())),
58  __('grid.action.addContributor'),
59  'modal_add_user',
60  true
61  ),
62  __('grid.action.addContributor'),
63  'add_user')
64  );
65 
66  // Columns
67  $this->addColumn(
68  new GridColumn(
69  'institution',
70  'grid.columns.institution',
71  null,
72  'controllers/grid/gridCell.tpl',
73  null,
74  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
75  )
76  );
77  $this->addColumn(
78  new GridColumn(
79  'url',
80  'grid.columns.url',
81  null,
82  'controllers/grid/gridCell.tpl',
83  null,
84  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
85  )
86  );
87  }
88 
89  //
90  // Overridden methods from GridHandler
91  //
96  function getRowInstance() {
97  return new ContributorGridRow();
98  }
99 
100  //
101  // Public Contributor Grid Actions
102  //
109  function addContributor($args, $request) {
110  // Calling editContributor with an empty row id will add
111  // a new contributor.
112  return $this->editContributor($args, $request);
113  }
114 
121  function editContributor($args, $request) {
122  $contributorId = isset($args['rowId']) ? $args['rowId'] : null;
123  import('lib.pkp.controllers.grid.settings.contributor.form.ContributorForm');
124  $contributorForm = new ContributorForm($contributorId);
125 
126  if ($contributorForm->isLocaleResubmit()) {
127  $contributorForm->readInputData();
128  } else {
129  $contributorForm->initData($args, $request);
130  }
131 
132  $json = new JSONMessage(true, $contributorForm->fetch($request));
133  return $json->getString();
134  }
135 
142  function updateContributor($args, $request) {
143  // -> contributorId must be present and valid
144  // -> htmlId must be present and valid
145  $contributorId = isset($args['rowId']) ? $args['rowId'] : null;
146  import('lib.pkp.controllers.grid.settings.contributor.form.ContributorForm');
147  $contributorForm = new ContributorForm($contributorId);
148  $contributorForm->readInputData();
149 
150  if ($contributorForm->validate()) {
151  $contributorForm->execute($request);
152 
153  // prepare the grid row data
154  $row = $this->getRowInstance();
155  $row->setGridId($this->getId());
156  $row->setId($contributorForm->contributorId);
157  $rowData = array('institution' => $contributorForm->getData('institution'),
158  'url' => $contributorForm->getData('url'));
159  $row->setData($rowData);
160  $row->initialize($request);
161 
162  return DAO::getDataChangedEvent();
163  } else {
164  return new JSONMessage(false);
165  }
166  }
167 
174  function deleteContributor($args, $request) {
175  $contributorId = isset($args['rowId']) ? $args['rowId'] : null;
176  $router = $request->getRouter();
177  $context = $router->getContext($request);
178  $contextSettingsDao = $context->getSettingsDAO();
179 
180  // get all of the contributors
181  $contributors = $contextSettingsDao->getSetting($context->getId(), 'contributors');
182 
183  if ( isset($contributors[$contributorId]) ) {
184  unset($contributors[$contributorId]);
185  $contextSettingsDao->updateSetting($context->getId(), 'contributors', $contributors, 'object');
186  return DAO::getDataChangedEvent();
187  } else {
188  return new JSONMessage(false, __('manager.setup.errorDeletingItem'));
189  }
190  }
191 }
192 
193 ?>
Handle contributor grid requests.
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.
static getDataChangedEvent($elementId=null, $parentElementId=null)
Definition: DAO.inc.php:606
Form for adding/edditing a contributor stores/retrieves from an associative array.
Base class for setup grid handlers.
Handle contributor grid row requests.
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
Base class defining an action that can be performed by the user in the user interface.