Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
MultipleListsListbuilderHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
17 import('lib.pkp.classes.controllers.listbuilder.ListbuilderList');
18 
19 define_exposed('LISTBUILDER_SOURCE_TYPE_NONE', 3);
20 
22 
24  var $_lists;
25 
30  parent::ListbuilderHandler();
31  }
32 
33 
34  //
35  // Getters and Setters
36  //
40  function getTemplate() {
41  if (is_null($this->_template)) {
42  $this->setTemplate('controllers/listbuilder/multipleListsListbuilder.tpl');
43  }
44 
45  return $this->_template;
46  }
47 
52  function &getLists() {
53  return $this->_lists;
54  }
55 
56 
57  //
58  // Protected methods.
59  //
64  function addList($list) {
65  assert(is_a($list, 'ListbuilderList'));
66 
67  $currentLists = $this->getLists();
68  if (!is_array($currentLists)) {
69  $currentLists = array();
70  }
71  $currentLists[$list->getId()] = $list;
72  $this->_setLists($currentLists);
73  }
74 
81  function loadData($request, $filter) {
82  // Give a chance to subclasses set data
83  // on their lists.
84  $this->setListsData($request, $filter);
85 
86  $data = array();
87  $lists = $this->getLists();
88 
89  foreach ($lists as $list) {
90  $data[$list->getId()] = $list->getData();
91  }
92 
93  return $data;
94  }
95 
99  function initialize($request) {
100  // Basic configuration.
101  // Currently this component only works with
102  // these configurations, but, if needed, it's
103  // easy to adapt this class to work with the other
104  // listbuilders configuration.
105  parent::initialize($request, false);
106  $this->setSourceType(LISTBUILDER_SOURCE_TYPE_NONE);
107  $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL);
108  }
109 
110 
111  //
112  // Publicly (remotely) available listbuilder functions
113  //
119  function fetch($args, $request) {
120  $templateMgr = TemplateManager::getManager($request);
121  $templateMgr->assign('lists', $this->getLists());
123  return parent::fetch($args, $request);
124  }
125 
126 
127  //
128  // Extended protected methods.
129  //
133  protected function initFeatures($request, $args) {
134  // Multiple lists listbuilder always have orderable rows.
135  // We don't have any other requirement for it.
136  import('lib.pkp.classes.controllers.grid.feature.OrderMultipleListsItemsFeature');
137  return array(new OrderMultipleListsItemsFeature());
138  }
139 
143  protected function getRowInstance() {
144  $row = parent::getRowInstance();
145 
146  // Currently we can't/don't need to delete a row inside multiple
147  // lists listbuilder. If we need, we have to adapt this class
148  // and its js handler.
149  $row->setHasDeleteItemLink(false);
150  return $row;
151  }
152 
156  protected function renderGridBodyPartsInternally($request) {
157  // Render the rows.
158  $listsRows = array();
159  $gridData = $this->getGridDataElements($request);
160  foreach ($gridData as $listId => $elements) {
161  $listsRows[$listId] = $this->renderRowsInternally($request, $elements);
162  }
163 
164  $templateMgr = TemplateManager::getManager($request);
165  $templateMgr->assign('grid', $this);
166  $templateMgr->assign('listsRows', $listsRows);
167 
168  // In listbuilders we don't use the grid body.
169  return false;
170  }
171 
172 
173  //
174  // Protected template methods.
175  //
183  protected function setListsData($request, $filter) {
184  assert(false);
185  }
187 
188  //
189  // Private helper methods.
190  //
195  private function _setLists($lists) {
196  $this->_lists = $lists;
197  }
198 }
199 
200 ?>
renderRowsInternally($request, &$elements)
setTemplate($template)
Class defining basic operations for handling Listbuilder UI elements.
& getGridDataElements($request)
Implements multiple lists listbuilder ordering functionality.
Class defining basic operations for handling multiple lists listbuilder UI elements.