Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SectionGridHandler.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.settings.SetupGridHandler');
17 import('controllers.grid.settings.sections.SectionGridRow');
18 
23  function SectionGridHandler() {
24  parent::SetupGridHandler();
25  $this->addRoleAssignment(
26  array(ROLE_ID_MANAGER),
27  array('fetchGrid', 'fetchRow', 'addSection', 'editSection', 'updateSection', 'deleteSection', 'saveSequence')
28  );
29  }
30 
31 
32  //
33  // Overridden template methods
34  //
35  /*
36  * Configure the grid
37  * @param $request PKPRequest
38  */
39  function initialize($request) {
40  parent::initialize($request);
41  $journal = $request->getJournal();
42 
43  // FIXME are these all required?
45  LOCALE_COMPONENT_APP_MANAGER,
46  LOCALE_COMPONENT_PKP_COMMON,
47  LOCALE_COMPONENT_PKP_USER,
48  LOCALE_COMPONENT_APP_COMMON
49  );
50 
51  // Set the grid title.
52  $this->setTitle('section.sections');
53 
54  $this->setInstructions('manager.setup.section.description');
55 
56  // Elements to be displayed in the grid
57  $sectionDao = DAORegistry::getDAO('SectionDAO');
58  $sectionEditorsDao = DAORegistry::getDAO('SectionEditorsDAO');
59  $sectionIterator = $sectionDao->getByJournalId($journal->getId());
60 
61  $gridData = array();
62  while ($section = $sectionIterator->next()) {
63  // Get the section editors data for the row
64  $assignedSectionEditors = $sectionEditorsDao->getEditorsBySectionId($section->getId(), $journal->getId());
65  if(empty($assignedSectionEditors)) {
66  $editorsString = __('common.none');
67  } else {
68  $editors = array();
69  foreach ($assignedSectionEditors as $sectionEditor) {
70  $user = $sectionEditor['user'];
71  $editors[] = $user->getLastName();
72  }
73  $editorsString = implode(', ', $editors);
74  }
75 
76  $sectionId = $section->getId();
77  $gridData[$sectionId] = array(
78  'title' => $section->getLocalizedTitle(),
79  'editors' => $editorsString,
80  'seq' => $section->getSequence()
81  );
82  }
83  uasort($gridData, create_function('$a,$b', 'return $a[\'seq\']-$b[\'seq\'];'));
84 
85  $this->setGridDataElements($gridData);
86 
87  // Add grid-level actions
88  $router = $request->getRouter();
89  import('lib.pkp.classes.linkAction.request.AjaxModal');
90  $this->addAction(
91  new LinkAction(
92  'addSection',
93  new AjaxModal(
94  $router->url($request, null, null, 'addSection', null, array('gridId' => $this->getId())),
95  __('manager.sections.create'),
96  'modal_manage'
97  ),
98  __('manager.sections.create'),
99  'add_section'
100  )
101  );
102 
103  // Columns
104  $this->addColumn(
105  new GridColumn(
106  'title',
107  'common.title',
108  null,
109  'controllers/grid/gridCell.tpl'
110  )
111  );
112  $this->addColumn(new GridColumn('editors', 'user.role.editors'));
113  }
114 
115  //
116  // Overridden methods from GridHandler
117  //
121  function initFeatures($request, $args) {
122  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
123  return array(new OrderGridItemsFeature());
124  }
125 
130  function getRowInstance() {
131  return new SectionGridRow();
132  }
133 
137  function getDataElementSequence($row) {
138  return $row['seq'];
139  }
140 
144  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
145  $sectionDao = DAORegistry::getDAO('SectionDAO');
146  $journal = $request->getJournal();
147  $section = $sectionDao->getById($rowId, $journal->getId());
148  $section->setSequence($newSequence);
149  $sectionDao->updateObject($section);
150  }
151 
152  //
153  // Public Section Grid Actions
154  //
160  function addSection($args, $request) {
161  // Calling editSection with an empty ID will add
162  // a new section.
163  return $this->editSection($args, $request);
164  }
165 
172  function editSection($args, $request) {
173  $sectionId = isset($args['sectionId']) ? $args['sectionId'] : null;
174  $this->setupTemplate($request);
175 
176  import('controllers.grid.settings.sections.form.SectionForm');
177  $sectionForm = new SectionForm($request, $sectionId);
178  $sectionForm->initData($args, $request);
179  $json = new JSONMessage(true, $sectionForm->fetch($request));
180  return $json->getString();
181  }
182 
189  function updateSection($args, $request) {
190  $sectionId = $request->getUserVar('sectionId');
191  $journal = $request->getJournal();
192 
193  import('controllers.grid.settings.sections.form.SectionForm');
194  $sectionForm = new SectionForm($request, $sectionId);
195  $sectionForm->readInputData();
196 
197  if ($sectionForm->validate()) {
198  $sectionForm->execute($args, $request);
199  return DAO::getDataChangedEvent($sectionForm->getSectionId());
200  } else {
201  $json = new JSONMessage(false);
202  return $json->getString();
203  }
204  }
205 
212  function deleteSection($args, $request) {
213  $journal = $request->getJournal();
214 
215  $sectionDao = DAORegistry::getDAO('SectionDAO');
216  $section = $sectionDao->getById(
217  $request->getUserVar('sectionId'),
218  $journal->getId()
219  );
220 
221  if (isset($section)) {
222  $sectionDao->deleteObject($section);
223  return DAO::getDataChangedEvent($section->getId());
224  } else {
225  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER); // manager.setup.errorDeletingItem
226  $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
227  }
228  return $json->getString();
229  }
230 }
231 
232 ?>
static & getDAO($name, $dbconn=null)
setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
static requireComponents()
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
addColumn($column)
setupTemplate($request)
setGridDataElements($data)
updateSection($args, $request)
addRoleAssignment($roleIds, $operations)
initFeatures($request, $args)
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
deleteSection($args, $request)
Implements grid ordering functionality.
Handle section grid requests.
setInstructions($instructions)
Base class for setup grid handlers.
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
Handle section grid row requests.
editSection($args, $request)
Form for adding/edditing a section stores/retrieves from an associative array.
Base class defining an action that can be performed by the user in the user interface.