Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
GenreGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.settings.SetupGridHandler');
17 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
18 import('lib.pkp.controllers.grid.settings.genre.GenreGridRow');
19 
24  function GenreGridHandler() {
25  parent::GridHandler();
26  $this->addRoleAssignment(array(ROLE_ID_MANAGER), array(
27  'fetchGrid', 'fetchRow',
28  'addGenre', 'editGenre', 'updateGenre',
29  'deleteGenre', 'restoreGenres', 'saveSequence'
30  ));
31  }
32 
33 
34  //
35  // Overridden template methods
36  //
37  /*
38  * Configure the grid
39  * @param $request PKPRequest
40  */
41  function initialize($request) {
42  parent::initialize($request);
43 
44  // Load language components
46  LOCALE_COMPONENT_APP_MANAGER,
47  LOCALE_COMPONENT_APP_EDITOR,
48  LOCALE_COMPONENT_PKP_COMMON,
49  LOCALE_COMPONENT_PKP_USER,
50  LOCALE_COMPONENT_APP_COMMON,
51  LOCALE_COMPONENT_PKP_GRID,
52  LOCALE_COMPONENT_APP_SUBMISSION,
53  LOCALE_COMPONENT_PKP_SUBMISSION,
54  LOCALE_COMPONENT_PKP_MANAGER,
55  LOCALE_COMPONENT_APP_DEFAULT
56  );
57 
58  // Set the grid title.
59  $this->setTitle('grid.genres.title');
60 
61  $this->setInstructions('grid.genres.description');
62 
63  // Add grid-level actions
64  $router = $request->getRouter();
65  $actionArgs = array('gridId' => $this->getId());
66 
67  import('lib.pkp.classes.linkAction.request.AjaxModal');
68  $this->addAction(
69  new LinkAction(
70  'addGenre',
71  new AjaxModal(
72  $router->url($request, null, null, 'addGenre', null, $actionArgs),
73  __('grid.action.addGenre'),
74  'modal_add_item',
75  true),
76  __('grid.action.addGenre'),
77  'add_item')
78  );
79 
80  import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
81  $this->addAction(
82  new LinkAction(
83  'restoreGenres',
85  __('grid.action.restoreDefaults.confirm'),
86  null,
87  $router->url($request, null, null, 'restoreGenres', null, $actionArgs), 'modal_delete'),
88  __('grid.action.restoreDefaults'),
89  'reset_default')
90  );
91 
92  // Columns
93  $cellProvider = new DataObjectGridCellProvider();
94  $cellProvider->setLocale(AppLocale::getLocale());
95  $this->addColumn(
96  new GridColumn('name',
97  'common.name',
98  null,
99  'controllers/grid/gridCell.tpl',
100  $cellProvider
101  )
102  );
103 
104  $this->addColumn(
105  new GridColumn(
106  'designation',
107  'common.designation',
108  null,
109  'controllers/grid/gridCell.tpl',
110  $cellProvider
111  )
112  );
113  }
114 
118  function loadData($request, $filter) {
119  // Elements to be displayed in the grid
120  $context = $request->getContext();
121  $genreDao = DAORegistry::getDAO('GenreDAO');
122  return $genreDao->getEnabledByContextId($context->getId(), self::getRangeInfo($request, $this->getId()));
123  }
124 
125  //
126  // Overridden methods from GridHandler
127  //
131  function initFeatures($request, $args) {
132  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
133  return array(new OrderGridItemsFeature());
134  }
135 
140  function getRowInstance() {
141  return new GenreGridRow();
142  }
143 
147  function getDataElementSequence($row) {
148  return $row->getSequence();
149  }
150 
154  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
155  $genreDao = DAORegistry::getDAO('GenreDAO');
156  $context = $request->getContext();
157  $genre = $genreDao->getById($rowId, $context->getId());
158  $genre->setSequence($newSequence);
159  $genreDao->updateObject($genre);
160  }
161 
162  //
163  // Public Genre Grid Actions
164  //
170  function addGenre($args, $request) {
171  // Calling editGenre with an empty row id will add a new Genre.
172  return $this->editGenre($args, $request);
173  }
174 
181  function editGenre($args, $request) {
182  $genreId = isset($args['genreId']) ? (int) $args['genreId'] : null;
183 
184  $this->setupTemplate($request);
185 
186  import('lib.pkp.controllers.grid.settings.genre.form.GenreForm');
187  $genreForm = new GenreForm($genreId);
188 
189  $genreForm->initData($args, $request);
190 
191  $json = new JSONMessage(true, $genreForm->fetch($request));
192  return $json->getString();
193  }
194 
201  function updateGenre($args, $request) {
202  $genreId = isset($args['genreId']) ? (int) $args['genreId'] : null;
203  $context = $request->getContext();
204 
205  import('lib.pkp.controllers.grid.settings.genre.form.GenreForm');
206  $genreForm = new GenreForm($genreId);
207  $genreForm->readInputData();
208 
209  $router = $request->getRouter();
210 
211  if ($genreForm->validate()) {
212  $genreForm->execute($args, $request);
213  return DAO::getDataChangedEvent($genreForm->getGenreId());
214  } else {
215  $json = new JSONMessage(false);
216  return $json->getString();
217  }
218  }
219 
226  function deleteGenre($args, $request) {
227  // Identify the Genre to be deleted
228  $genre =& $this->_getGenreFromArgs($request, $args);
229 
230  $genreDao = DAORegistry::getDAO('GenreDAO');
231  $result = $genreDao->deleteObject($genre);
232 
233  if ($result) {
234  return DAO::getDataChangedEvent($genre->getId());
235  } else {
236  $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
237  }
238  return $json->getString();
239  }
240 
248  function restoreGenres($args, $request) {
249  $context = $request->getContext();
250 
251  // Restore all the genres in this context form the registry XML file
252  $genreDao = DAORegistry::getDAO('GenreDAO');
253  $genreDao->restoreByContextId($context->getId());
254  return DAO::getDataChangedEvent();
255  }
256 
257  //
258  // Private helper function
259  //
268  function &_getGenreFromArgs($request, $args) {
269  // Identify the Genre Id and retrieve the
270  // corresponding element from the grid's data source.
271  if (!isset($args['genreId'])) {
272  fatalError('Missing Genre Id!');
273  } else {
274  $genre =& $this->getRowDataElement($request, $args['genreId']);
275  if (is_null($genre)) fatalError('Invalid Genre Id!');
276  }
277  return $genre;
278  }
279 }
280 
281 ?>
static & getDAO($name, $dbconn=null)
addGenre($args, $request)
static requireComponents()
getRowDataElement($request, $rowId)
loadData($request, $filter)
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
setupTemplate($request)
Handle Genre grid requests.
addRoleAssignment($roleIds, $operations)
A modal that retrieves its content from via AJAX.
Class to represent a JSON (Javascript Object Notation) message.
static getLocale()
& _getGenreFromArgs($request, $args)
editGenre($args, $request)
deleteGenre($args, $request)
Form for adding/editing a Submission File Genre.
Class defining a simple confirmation modal with a remote action and ok/cancel buttons.
restoreGenres($args, $request)
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
Implements grid ordering functionality.
Handle Genre grid row requests.
Base class for a cell provider that can retrieve simple labels from DataObjects. If you need more com...
setInstructions($instructions)
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
updateGenre($args, $request)
Base class defining an action that can be performed by the user in the user interface.
initFeatures($request, $args)