Open Journal Systems  3.0.0
 All Data Structures 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  // Add grid-level actions
62  $router = $request->getRouter();
63  $actionArgs = array('gridId' => $this->getId());
64 
65  import('lib.pkp.classes.linkAction.request.AjaxModal');
66  $this->addAction(
67  new LinkAction(
68  'addGenre',
69  new AjaxModal(
70  $router->url($request, null, null, 'addGenre', null, $actionArgs),
71  __('grid.action.addGenre'),
72  'modal_add_item',
73  true),
74  __('grid.action.addGenre'),
75  'add_item')
76  );
77 
78  import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
79  $this->addAction(
80  new LinkAction(
81  'restoreGenres',
83  __('grid.action.restoreDefaults.confirm'),
84  null,
85  $router->url($request, null, null, 'restoreGenres', null, $actionArgs), 'modal_delete'),
86  __('grid.action.restoreDefaults'),
87  'reset_default')
88  );
89 
90  // Columns
91  $cellProvider = new DataObjectGridCellProvider();
92  $cellProvider->setLocale(AppLocale::getLocale());
93  $this->addColumn(
94  new GridColumn('name',
95  'common.name',
96  null,
97  null,
98  $cellProvider,
99  array('width' => 90)
100  )
101  );
102 
103  $this->addColumn(
104  new GridColumn(
105  'designation',
106  'common.designation',
107  null,
108  null,
109  $cellProvider
110  )
111  );
112  }
113 
117  protected function loadData($request, $filter) {
118  // Elements to be displayed in the grid
119  $context = $request->getContext();
120  $genreDao = DAORegistry::getDAO('GenreDAO');
121  return $genreDao->getEnabledByContextId($context->getId(), self::getRangeInfo($request, $this->getId()));
122  }
123 
124  //
125  // Overridden methods from GridHandler
126  //
130  function initFeatures($request, $args) {
131  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
132  return array(new OrderGridItemsFeature());
133  }
134 
139  protected function getRowInstance() {
140  return new GenreGridRow();
141  }
142 
146  function getDataElementSequence($row) {
147  return $row->getSequence();
148  }
149 
153  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
154  $genreDao = DAORegistry::getDAO('GenreDAO');
155  $context = $request->getContext();
156  $genre = $genreDao->getById($rowId, $context->getId());
157  $genre->setSequence($newSequence);
158  $genreDao->updateObject($genre);
159  }
160 
161  //
162  // Public Genre Grid Actions
163  //
169  function addGenre($args, $request) {
170  // Calling editGenre with an empty row id will add a new Genre.
171  return $this->editGenre($args, $request);
172  }
173 
180  function editGenre($args, $request) {
181  $genreId = isset($args['genreId']) ? (int) $args['genreId'] : null;
182 
183  $this->setupTemplate($request);
184 
185  import('lib.pkp.controllers.grid.settings.genre.form.GenreForm');
186  $genreForm = new GenreForm($genreId);
187 
188  $genreForm->initData($args, $request);
189 
190  return new JSONMessage(true, $genreForm->fetch($request));
191  }
192 
199  function updateGenre($args, $request) {
200  $genreId = isset($args['genreId']) ? (int) $args['genreId'] : null;
201  $context = $request->getContext();
202 
203  import('lib.pkp.controllers.grid.settings.genre.form.GenreForm');
204  $genreForm = new GenreForm($genreId);
205  $genreForm->readInputData();
206 
207  $router = $request->getRouter();
208 
209  if ($genreForm->validate()) {
210  $genreForm->execute($args, $request);
211  return DAO::getDataChangedEvent($genreForm->getGenreId());
212  } else {
213  return new JSONMessage(false);
214  }
215  }
216 
223  function deleteGenre($args, $request) {
224  // Identify the Genre to be deleted
225  $genre =& $this->_getGenreFromArgs($request, $args);
226 
227  $genreDao = DAORegistry::getDAO('GenreDAO');
228  $result = $genreDao->deleteObject($genre);
229 
230  if ($result) {
231  return DAO::getDataChangedEvent($genre->getId());
232  } else {
233  return new JSONMessage(false, __('manager.setup.errorDeletingItem'));
234  }
235  }
236 
244  function restoreGenres($args, $request) {
245  $context = $request->getContext();
246 
247  // Restore all the genres in this context form the registry XML file
248  $genreDao = DAORegistry::getDAO('GenreDAO');
249  $genreDao->installDefaults($context->getId(), $context->getSupportedLocales());
250  return DAO::getDataChangedEvent();
251  }
252 
253  //
254  // Private helper function
255  //
264  function &_getGenreFromArgs($request, $args) {
265  // Identify the Genre Id and retrieve the
266  // corresponding element from the grid's data source.
267  if (!isset($args['genreId'])) {
268  fatalError('Missing Genre Id!');
269  } else {
270  $genre =& $this->getRowDataElement($request, $args['genreId']);
271  if (is_null($genre)) fatalError('Invalid Genre Id!');
272  }
273  return $genre;
274  }
275 }
276 
277 ?>
static & getDAO($name, $dbconn=null)
addGenre($args, $request)
getRowDataElement($request, &$rowId)
static requireComponents()
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...
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:633
updateGenre($args, $request)
Base class defining an action that can be performed by the user in the user interface.
initFeatures($request, $args)