Open Journal Systems  3.0.0
 All Data Structures 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  // Elements to be displayed in the grid
55  $sectionDao = DAORegistry::getDAO('SectionDAO');
56  $subEditorsDao = DAORegistry::getDAO('SubEditorsDAO');
57  $sectionIterator = $sectionDao->getByJournalId($journal->getId());
58 
59  $gridData = array();
60  while ($section = $sectionIterator->next()) {
61  // Get the section editors data for the row
62  $assignedSubEditors = $subEditorsDao->getBySectionId($section->getId(), $journal->getId());
63  if(empty($assignedSubEditors)) {
64  $editorsString = __('common.none');
65  } else {
66  $editors = array();
67  foreach ($assignedSubEditors as $subEditor) {
68  $editors[] = $subEditor->getLastName();
69  }
70  $editorsString = implode(', ', $editors);
71  }
72 
73  $sectionId = $section->getId();
74  $gridData[$sectionId] = array(
75  'title' => $section->getLocalizedTitle(),
76  'editors' => $editorsString,
77  'seq' => $section->getSequence()
78  );
79  }
80  uasort($gridData, create_function('$a,$b', 'return $a[\'seq\']-$b[\'seq\'];'));
81 
82  $this->setGridDataElements($gridData);
83 
84  // Add grid-level actions
85  $router = $request->getRouter();
86  import('lib.pkp.classes.linkAction.request.AjaxModal');
87  $this->addAction(
88  new LinkAction(
89  'addSection',
90  new AjaxModal(
91  $router->url($request, null, null, 'addSection', null, array('gridId' => $this->getId())),
92  __('manager.sections.create'),
93  'modal_manage'
94  ),
95  __('manager.sections.create'),
96  'add_section'
97  )
98  );
99 
100  // Columns
101  $this->addColumn(
102  new GridColumn(
103  'title',
104  'common.title'
105  )
106  );
107  $this->addColumn(new GridColumn('editors', 'user.role.editors'));
108  }
109 
110  //
111  // Overridden methods from GridHandler
112  //
116  function initFeatures($request, $args) {
117  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
118  return array(new OrderGridItemsFeature());
119  }
120 
125  protected function getRowInstance() {
126  return new SectionGridRow();
127  }
128 
132  function getDataElementSequence($row) {
133  return $row['seq'];
134  }
135 
139  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
140  $sectionDao = DAORegistry::getDAO('SectionDAO');
141  $journal = $request->getJournal();
142  $section = $sectionDao->getById($rowId, $journal->getId());
143  $section->setSequence($newSequence);
144  $sectionDao->updateObject($section);
145  }
146 
147  //
148  // Public Section Grid Actions
149  //
155  function addSection($args, $request) {
156  // Calling editSection with an empty ID will add
157  // a new section.
158  return $this->editSection($args, $request);
159  }
160 
168  function editSection($args, $request) {
169  $sectionId = isset($args['sectionId']) ? $args['sectionId'] : null;
170  $this->setupTemplate($request);
171 
172  import('controllers.grid.settings.sections.form.SectionForm');
173  $sectionForm = new SectionForm($request, $sectionId);
174  $sectionForm->initData($args, $request);
175  return new JSONMessage(true, $sectionForm->fetch($request));
176  }
177 
184  function updateSection($args, $request) {
185  $sectionId = $request->getUserVar('sectionId');
186 
187  import('controllers.grid.settings.sections.form.SectionForm');
188  $sectionForm = new SectionForm($request, $sectionId);
189  $sectionForm->readInputData();
190 
191  if ($sectionForm->validate()) {
192  $sectionForm->execute($args, $request);
193  return DAO::getDataChangedEvent($sectionForm->getSectionId());
194  }
195  return new JSONMessage(false);
196  }
197 
204  function deleteSection($args, $request) {
205  $journal = $request->getJournal();
206 
207  $sectionDao = DAORegistry::getDAO('SectionDAO');
208  $section = $sectionDao->getById(
209  $request->getUserVar('sectionId'),
210  $journal->getId()
211  );
212 
213  if (isset($section)) {
214  $sectionDao->deleteObject($section);
215  return DAO::getDataChangedEvent($section->getId());
216  }
217  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER); // manager.setup.errorDeletingItem
218  return new JSONMessage(false, __('manager.setup.errorDeletingItem'));
219  }
220 }
221 
222 ?>
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.
deleteSection($args, $request)
Implements grid ordering functionality.
Handle section grid requests.
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 section grid row requests.
editSection($args, $request)
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:633
Form for adding/editing a section.
Base class defining an action that can be performed by the user in the user interface.