Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
AdminCategoriesGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.settings.SetupGridHandler');
17 import('lib.pkp.classes.controllers.grid.DataObjectGridCellProvider');
18 
19 import('controllers.grid.admin.categories.AdminCategoriesGridRow');
20 
22 
27  parent::SetupGridHandler();
28  $this->addRoleAssignment(array(ROLE_ID_MANAGER),
29  array('fetchGrid', 'fetchRow', 'addItem', 'editItem', 'updateItem', 'deleteItem'));
30  }
31 
35  function authorize($request, &$args, $roleAssignments) {
36  return parent::authorize($request, $args, $roleAssignments, false);
37  }
38 
39  //
40  // Overridden template methods
41  //
46  function initialize($request) {
47  parent::initialize($request);
48 
49  AppLocale::requireComponents(LOCALE_COMPONENT_APP_ADMIN);
50 
51  // Basic grid configuration
52  $this->setId('adminCategories');
53  $this->setTitle('admin.categories');
54  $this->setInstructions('admin.categories.description');
55 
56 
57  // Add grid-level actions
58  import('lib.pkp.classes.linkAction.request.AjaxModal');
59  $router = $request->getRouter();
60  $this->addAction(
61  new LinkAction(
62  'addItem',
63  new AjaxModal(
64  $router->url($request, null, null, 'addItem', null, array('gridId' => $this->getId())),
65  __('grid.action.addItem'),
66  'modal_add_item',
67  true),
68  __('grid.action.addItem'),
69  'add_item')
70  );
71 
72  // Columns
73  $this->addColumn(
74  new GridColumn(
75  'name',
76  'common.name'
77  )
78  );
79  }
80 
81 
82  //
83  // Overridden methods from GridHandler
84  //
88  function getRowInstance() {
89  return new AdminCategoriesGridRow();
90  }
91 
95  function loadData($request, $filter) {
96  // Elements to be displayed in the grid
97  $categoryDao = DAORegistry::getDAO('CategoryDAO');
98  $categories = array();
99  foreach ($categoryDao->getCategories() as $id => $name) {
100  $categories[$id]['name'] = $name;
101  }
102  return $categories;
103  }
104 
105 
106  //
107  // Public grid actions.
108  //
114  function addItem($args, $request) {
115  // Calling editItem with an empty row id will add
116  // a new category.
117  return $this->editItem($args, $request);
118  }
119 
126  function editItem($args, $request) {
127  import('controllers.grid.admin.categories.form.AdminCategoryForm');
128  $categoryId = isset($args['rowId']) ? $args['rowId'] : null;
129  $categoryForm = new AdminCategoryForm($categoryId);
130 
131  $categoryForm->initData($args, $request);
132 
133  $json = new JSONMessage(true, $categoryForm->fetch($request));
134  return $json->getString();
135  }
136 
143  function updateItem($args, $request) {
144  // -> categoryId must be present and valid
145  // -> htmlId must be present and valid
146 
147  import('controllers.grid.admin.categories.form.AdminCategoryForm');
148  $categoryId = isset($args['rowId']) ? $args['rowId'] : null;
149  $categoryForm = new AdminCategoryForm($categoryId);
150  $categoryForm->readInputData();
151 
152  if ($categoryForm->validate()) {
153  $categoryForm->execute($args, $request);
154  return DAO::getDataChangedEvent($categoryForm->categoryId);
155  } else {
156  $json = new JSONMessage(false);
157  return $json->getString();
158  }
159  }
160 
167  function deleteItem($args, $request) {
168  $rowId = $request->getUserVar('rowId');
169 
170  // Get all categories
171  $categoryDao = DAORegistry::getDAO('CategoryDAO');
172  $entryDao = $categoryDao->getEntryDAO();
173  foreach ($categoryDao->getCategories() as $id => $name) {
174  if ($id == $rowId) {
175  $entryDao->deleteObjectById($id);
176  break;
177  }
178  }
179 
180  $categoryDao->rebuildCache();
181 
182  return DAO::getDataChangedEvent($rowId);
183  }
184 }
185 
186 ?>
static & getDAO($name, $dbconn=null)
authorize($request, &$args, $roleAssignments)
Form for adding/editing a category stores/retrieves from an associative array.
static requireComponents()
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
addRoleAssignment($roleIds, $operations)
A modal that retrieves its content from via AJAX.
Class to represent a JSON (Javascript Object Notation) message.
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 ...
Handle submissionChecklist grid row requests.
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.
Handle category administration grid requests.