Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ChapterAuthorListbuilderHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
17 
20  var $_chapterId;
21 
26  parent::ListbuilderHandler();
27  $this->addRoleAssignment(
28  array(ROLE_ID_AUTHOR, ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER),
29  array('fetch', 'fetchRow', 'fetchOptions', 'save')
30  );
31  }
32 
33  //
34  // Getters/Setters
35  //
40  function getMonograph() {
41  return $this->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
42  }
43 
48  function setChapterId($chapterId) {
49  $this->_chapterId = $chapterId;
50  }
51 
56  function getChapterId() {
57  return $this->_chapterId;
58  }
59 
60  //
61  // Implement template methods from PKPHandler
62  //
69  function authorize($request, &$args, $roleAssignments) {
70  import('classes.security.authorization.SubmissionAccessPolicy');
71  $this->addPolicy(new SubmissionAccessPolicy($request, $args, $roleAssignments));
72  return parent::authorize($request, $args, $roleAssignments);
73  }
74 
75  /*
76  * Configure the grid
77  * @param PKPRequest $request
78  */
79  function initialize($request) {
80  parent::initialize($request);
81 
82  // Add locale keys
83  AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION, LOCALE_COMPONENT_PKP_SUBMISSION);
84 
85  // Basic configuration
86  $this->setTitle('submission.submit.addAuthor');
87  $this->setSourceType(LISTBUILDER_SOURCE_TYPE_SELECT);
88  $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL);
89  $this->setSaveFieldName('authors');
90 
91  // Fetch and authorize chapter
92  $chapterDao = DAORegistry::getDAO('ChapterDAO');
93  $monograph = $this->getMonograph();
94  $chapter = $chapterDao->getChapter(
95  $request->getUserVar('chapterId'),
96  $monograph->getId()
97  );
98  if ($chapter) {
99  // This is an existing chapter
100  $this->setChapterId($chapter->getId());
101  } else {
102  // This is a new chapter
103  $this->setChapterId(null);
104  }
105 
106  // Name column
107  $nameColumn = new ListbuilderGridColumn($this, 'name', 'common.name');
108  // We can reuse the User cell provider because getFullName
109  import('lib.pkp.controllers.listbuilder.users.UserListbuilderGridCellProvider');
110  $nameColumn->setCellProvider(new UserListbuilderGridCellProvider());
111  $this->addColumn($nameColumn);
112  }
113 
117  function initFeatures($request, $args) {
118  import('lib.pkp.classes.controllers.grid.feature.OrderListbuilderItemsFeature');
119  return array(new OrderListbuilderItemsFeature());
120  }
121 
125  function getRequestArgs() {
126  $monograph = $this->getMonograph();
127  return array(
128  'submissionId' => $monograph->getId(),
129  'chapterId' => $this->getChapterId()
130  );
131  }
132 
138  function getRowDataElement($request, $rowId) {
139  // fallback on the parent if a rowId is found
140  if ( !empty($rowId) ) {
141  return parent::getRowDataElement($request, $rowId);
142  }
143  $id = 0;
144  // Otherwise return from the newRowId
145  $authorId = $this->getNewRowId($request); // this is an array: Example: $authorId['name'] => 25
146  if (isset($authorId['name'])) {
147  $id = (int) $authorId['name'];
148  }
149 
150  $authorDao = DAORegistry::getDAO('AuthorDAO');
151  $monograph = $this->getMonograph();
152  return $authorDao->getById($id, $monograph->getId());
153  }
154 
158  function getOptions() {
159  // Initialize the object to return
160  $items = array(
161  array()
162  );
163 
164  $monograph = $this->getMonograph();
165  $authors = $monograph->getAuthors();
166 
167  foreach ($authors as $author) {
168  $items[0][$author->getId()] = $author->getFullName();
169  }
170  unset($authors);
171 
172  return $items;
173  }
174 
175 
176  //
177  // Public methods
178  //
179  /*
180  * Load the data for the list builder
181  * @param PKPRequest $request
182  */
183  function loadData($request, $filter) {
184  $monograph = $this->getMonograph();
185 
186  // If it's a new chapter, it has no authors.
187  if (!$this->getChapterId()) return array();
188 
189  // Retrieve the contributors associated with this chapter to be displayed in the grid
190  $chapterAuthorDao = DAORegistry::getDAO('ChapterAuthorDAO');
191  $chapterAuthors = $chapterAuthorDao->getAuthors($monograph->getId(), $this->getChapterId());
192 
193  return $chapterAuthors;
194  }
195 }
196 
197 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
Implements listbuilder ordering functionality.
static requireComponents()
addColumn($column)
Class defining basic operations for handling Listbuilder UI elements.
addRoleAssignment($roleIds, $operations)
Class to control (write) access to submissions and (read) access to submission details in OMP...
Represents a column within a listbuilder.
Class for adding contributors to a chapter.
Base class for a cell provider that can retrieve labels from arrays.
authorize($request, &$args, $roleAssignments)
& getAuthorizedContextObject($assocType)