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->getBySectionId($section->getId(), $journal->getId());
65  if(empty($assignedSectionEditors)) {
66  $editorsString = __('common.none');
67  } else {
68  $editors = array();
69  foreach ($assignedSectionEditors as $sectionEditor) {
70  $editors[] = $sectionEditor->getLastName();
71  }
72  $editorsString = implode(', ', $editors);
73  }
74 
75  $sectionId = $section->getId();
76  $gridData[$sectionId] = array(
77  'title' => $section->getLocalizedTitle(),
78  'editors' => $editorsString,
79  'seq' => $section->getSequence()
80  );
81  }
82  uasort($gridData, create_function('$a,$b', 'return $a[\'seq\']-$b[\'seq\'];'));
83 
84  $this->setGridDataElements($gridData);
85 
86  // Add grid-level actions
87  $router = $request->getRouter();
88  import('lib.pkp.classes.linkAction.request.AjaxModal');
89  $this->addAction(
90  new LinkAction(
91  'addSection',
92  new AjaxModal(
93  $router->url($request, null, null, 'addSection', null, array('gridId' => $this->getId())),
94  __('manager.sections.create'),
95  'modal_manage'
96  ),
97  __('manager.sections.create'),
98  'add_section'
99  )
100  );
101 
102  // Columns
103  $this->addColumn(
104  new GridColumn(
105  'title',
106  'common.title',
107  null,
108  'controllers/grid/gridCell.tpl'
109  )
110  );
111  $this->addColumn(new GridColumn('editors', 'user.role.editors'));
112  }
113 
114  //
115  // Overridden methods from GridHandler
116  //
120  function initFeatures($request, $args) {
121  import('lib.pkp.classes.controllers.grid.feature.OrderGridItemsFeature');
122  return array(new OrderGridItemsFeature());
123  }
124 
129  function getRowInstance() {
130  return new SectionGridRow();
131  }
132 
136  function getDataElementSequence($row) {
137  return $row['seq'];
138  }
139 
143  function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence) {
144  $sectionDao = DAORegistry::getDAO('SectionDAO');
145  $journal = $request->getJournal();
146  $section = $sectionDao->getById($rowId, $journal->getId());
147  $section->setSequence($newSequence);
148  $sectionDao->updateObject($section);
149  }
150 
151  //
152  // Public Section Grid Actions
153  //
159  function addSection($args, $request) {
160  // Calling editSection with an empty ID will add
161  // a new section.
162  return $this->editSection($args, $request);
163  }
164 
171  function editSection($args, $request) {
172  $sectionId = isset($args['sectionId']) ? $args['sectionId'] : null;
173  $this->setupTemplate($request);
174 
175  import('controllers.grid.settings.sections.form.SectionForm');
176  $sectionForm = new SectionForm($request, $sectionId);
177  $sectionForm->initData($args, $request);
178  $json = new JSONMessage(true, $sectionForm->fetch($request));
179  return $json->getString();
180  }
181 
188  function updateSection($args, $request) {
189  $sectionId = $request->getUserVar('sectionId');
190 
191  import('controllers.grid.settings.sections.form.SectionForm');
192  $sectionForm = new SectionForm($request, $sectionId);
193  $sectionForm->readInputData();
194 
195  if ($sectionForm->validate()) {
196  $sectionForm->execute($args, $request);
197  return DAO::getDataChangedEvent($sectionForm->getSectionId());
198  } else {
199  $json = new JSONMessage(false);
200  return $json->getString();
201  }
202  }
203 
210  function deleteSection($args, $request) {
211  $journal = $request->getJournal();
212 
213  $sectionDao = DAORegistry::getDAO('SectionDAO');
214  $section = $sectionDao->getById(
215  $request->getUserVar('sectionId'),
216  $journal->getId()
217  );
218 
219  if (isset($section)) {
220  $sectionDao->deleteObject($section);
221  return DAO::getDataChangedEvent($section->getId());
222  } else {
223  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER); // manager.setup.errorDeletingItem
224  $json = new JSONMessage(false, __('manager.setup.errorDeletingItem'));
225  }
226  return $json->getString();
227  }
228 }
229 
230 ?>
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.
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 section grid row requests.
editSection($args, $request)
static getDataChangedEvent($elementId=null, $parentElementId=null, $content= '')
Definition: DAO.inc.php:632
Form for adding/editing a section.
Base class defining an action that can be performed by the user in the user interface.