Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
listbuilder/settings/CategoriesListbuilderHandler.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.listbuilder.settings.SetupListbuilderHandler');
17 
20  var $seriesId;
21 
25  function CategoriesListbuilderHandler() {
26  parent::SetupListbuilderHandler();
27  $this->addRoleAssignment(
28  ROLE_ID_MANAGER,
29  array('fetch', 'fetchRow', 'fetchOptions')
30  );
31  }
32 
37  function setSeriesId($seriesId) {
38  $this->seriesId = $seriesId;
39  }
40 
45  function getSeriesId() {
46  return $this->seriesId;
47  }
48 
53  function loadData($request) {
54  $press = $this->getContext();
55  $seriesId = $this->getSeriesId();
56 
57  $seriesDao = DAORegistry::getDAO('SeriesDAO');
58  return $seriesDao->getCategories($seriesId, $press->getId());
59  }
60 
64  function getOptions() {
65  $press = $this->getContext();
66  $seriesDao = DAORegistry::getDAO('SeriesDAO');
67 
68  if ($this->getSeriesId()) {
69  $unassignedCategories = $seriesDao->getUnassignedCategories($this->getSeriesId(), $press->getId());
70  } else {
71  $categoryDao = DAORegistry::getDAO('CategoryDAO');
72  $unassignedCategories = $categoryDao->getByPressId($press->getId());
73  }
74 
75  $itemList = array(0 => array());
76  while ($category = $unassignedCategories->next()) {
77  $itemList[0][$category->getId()] = $category->getLocalizedTitle();
78  unset($category);
79  }
80  return $itemList;
81  }
82 
87  function getRequestArgs() {
88  $args = parent::getRequestArgs();
89  $args['seriesId'] = $this->getSeriesId();
90  return $args;
91  }
92 
93 
99  function getRowDataElement($request, $rowId) {
100  // fallback on the parent if a rowId is found
101  if ( !empty($rowId) ) {
102  return parent::getRowDataElement($request, $rowId);
103  }
104 
105  // Otherwise return from the $newRowId
106  $newRowId = $this->getNewRowId($request);
107  $categoryId = $newRowId['name'];
108  $categoryDao = DAORegistry::getDAO('CategoryDAO');
109  $press = $request->getPress();
110  return $categoryDao->getById($categoryId, $press->getId());
111  }
112 
113  //
114  // Overridden template methods
115  //
120  function initialize($request) {
121  parent::initialize($request);
122  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER);
124  // Basic configuration
125  $this->setTitle('grid.category.categories');
126  $this->setSourceType(LISTBUILDER_SOURCE_TYPE_SELECT);
127  $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL);
128  $this->setSaveFieldName('categories');
129 
130  $this->setSeriesId($request->getUserVar('seriesId'));
131 
132  // Name column
133  $nameColumn = new ListbuilderGridColumn($this, 'name', 'common.name');
134 
135  import('controllers.listbuilder.categories.CategoryListbuilderGridCellProvider');
136  $nameColumn->setCellProvider(new CategoryListbuilderGridCellProvider());
137  $this->addColumn($nameColumn);
138  }
139 }
140 
141 ?>
static & getDAO($name, $dbconn=null)
static requireComponents()
addColumn($column)
addRoleAssignment($roleIds, $operations)
Represents a column within a listbuilder.
Base class for setup listbuilders.
Class for a cell provider that provides category information.