Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
submission/CategoriesListbuilderHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
17 
20  var $_press;
21 
24 
28  function CategoriesListbuilderHandler() {
29  parent::ListbuilderHandler();
30  $this->addRoleAssignment(
31  array(ROLE_ID_MANAGER, ROLE_ID_AUTHOR),
32  array('fetch', 'fetchRow', 'fetchOptions')
33  );
34  }
35 
42  function authorize($request, &$args, $roleAssignments) {
43  import('lib.pkp.classes.security.authorization.PkpContextAccessPolicy');
44  $this->addPolicy(new PkpContextAccessPolicy($request, $roleAssignments));
45  return parent::authorize($request, $args, $roleAssignments);
46  }
47 
52  function setSubmissionId($submissionId) {
53  $this->submissionId = $submissionId;
54  }
55 
60  function getSubmissionId() {
61  return $this->submissionId;
62  }
63 
68  function setPress($press) {
69  $this->_press = $press;
70  }
71 
76  function getPress() {
77  return $this->_press;
78  }
79 
84  function loadData($request) {
85  $press = $this->getPress();
86  $submissionId = $this->getSubmissionId();
87 
88  if ($submissionId) {
89  $submissionDao = DAORegistry::getDAO('MonographDAO');
90  $assignedCategories = $submissionDao->getCategories($submissionId, $press->getId());
91  return $assignedCategories;
92  }
93 
94  return array();
95  }
96 
100  function getOptions() {
101  $press = $this->getPress();
102  $submissionId = $this->getSubmissionId();
103 
104  if ($submissionId) {
105  // Preexisting submission
106  $submissionDao = DAORegistry::getDAO('MonographDAO');
107  $availableCategories = $submissionDao->getUnassignedCategories($submissionId, $press->getId());
108  } else {
109  // New submission
110  $categoryDao = DAORegistry::getDAO('CategoryDAO');
111  $availableCategories = $categoryDao->getByPressId($press->getId());
112  }
113 
114  $itemList = array(0 => array());
115  while ($category = $availableCategories->next()) {
116  $itemList[0][$category->getId()] = $category->getLocalizedTitle();
117  }
118  return $itemList;
119  }
120 
125  function getRequestArgs() {
126  $args = parent::getRequestArgs();
127  $args['submissionId'] = $this->getSubmissionId();
128  return $args;
129  }
130 
137  function getRowDataElement($request, $rowId) {
138  // fallback on the parent if a rowId is found
139  if ( !empty($rowId) ) {
140  return parent::getRowDataElement($request, $rowId);
141  }
142 
143  // Otherwise return from the $newRowId
144  $newRowId = $this->getNewRowId($request);
145  $categoryId = $newRowId['name'];
146  $categoryDao = DAORegistry::getDAO('CategoryDAO');
147  $press = $request->getPress();
148  $category = $categoryDao->getById($categoryId, $press->getId());
149  return $category;
150  }
151 
152  //
153  // Overridden template methods
154  //
159  function initialize($request) {
160  parent::initialize($request);
162  LOCALE_COMPONENT_PKP_MANAGER,
163  LOCALE_COMPONENT_APP_SUBMISSION
164  );
166  // Basic configuration
167  $this->setPress($request->getPress());
168  $this->setTitle('submission.submit.placement.categories');
169  $this->setInstructions('submission.submit.placement.categoriesDescription');
170  $this->setSourceType(LISTBUILDER_SOURCE_TYPE_SELECT);
171  $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL);
172  $this->setSaveFieldName('categories');
173 
174  $this->setSubmissionId($request->getUserVar('submissionId'));
175 
176  // Name column
177  $nameColumn = new ListbuilderGridColumn($this, 'name', 'common.name');
178 
179  import('controllers.listbuilder.categories.CategoryListbuilderGridCellProvider');
180  $nameColumn->setCellProvider(new CategoryListbuilderGridCellProvider());
181  $this->addColumn($nameColumn);
182  }
183 }
184 
185 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
static requireComponents()
addColumn($column)
Class defining basic operations for handling Listbuilder UI elements.
Class to control access to PKP applications&#39; setup components.
addRoleAssignment($roleIds, $operations)
Represents a column within a listbuilder.
setInstructions($instructions)
Class for a cell provider that provides category information.