Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
FilesListbuilderHandler.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
17 
19 
22 
26  function FilesListbuilderHandler($fileStage) {
27  parent::ListbuilderHandler();
28 
29  $this->_fileStage = $fileStage;
30 
31  $this->addRoleAssignment(
32  array(ROLE_ID_SUB_EDITOR, ROLE_ID_MANAGER, ROLE_ID_ASSISTANT),
33  array('fetch', 'fetchRow', 'fetchOptions')
34  );
35  }
36 
41  function getFileStage() {
42  return $this->_fileStage;
43  }
44 
45 
46  //
47  // Implement template methods from PKPHandler
48  //
52  function authorize($request, &$args, $roleAssignments, $stageId) {
53  import('classes.security.authorization.WorkflowStageAccessPolicy'); // context-specific.
54  $this->addPolicy(new WorkflowStageAccessPolicy($request, $args, $roleAssignments, 'submissionId', $stageId), true);
55  return parent::authorize($request, $args, $roleAssignments);
56  }
57 
62  function initialize($request) {
63  parent::initialize($request);
64 
65  // Basic configuration
66  $this->setSourceType(LISTBUILDER_SOURCE_TYPE_SELECT);
67  $this->setSaveType(LISTBUILDER_SAVE_TYPE_EXTERNAL);
68  $this->setSaveFieldName('files');
69 
70  // Add the file column
71  $itemColumn = new ListbuilderGridColumn($this, 'name', 'common.name');
72  import('lib.pkp.controllers.listbuilder.files.FileListbuilderGridCellProvider');
73  $itemColumn->setCellProvider(new FileListbuilderGridCellProvider());
74  $this->addColumn($itemColumn);
75  }
76 
77 
78  //
79  // Public methods
80  //
81 
87  function getOptions($submissionFiles) {
88  $itemList = array();
89  foreach ($submissionFiles as $submissionFile) {
90  $itemList[$submissionFile->getFileId()] = $submissionFile->getFileLabel();
91  }
92  return array($itemList);
93  }
94 
95 
96  //
97  // Overridden template methods
98  //
102  function getRequestArgs() {
103  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
104  $args = parent::getRequestArgs();
105  $args['submissionId'] = $submission->getId();
106  return $args;
107  }
108 
112  function setupTemplate($request) {
113  parent::setupTemplate($request);
114 
115  AppLocale::requireComponents(LOCALE_COMPONENT_APP_EDITOR, LOCALE_COMPONENT_PKP_SUBMISSION);
116  }
117 
121  function getRowDataElement($request, $rowId) {
122  // fallback on the parent if a rowId is found
123  if ( !empty($rowId) ) {
124  return parent::getRowDataElement($request, $rowId);
125  }
126 
127  // Otherwise return from the newRowId
128  $newRowId = $this->getNewRowId($request);
129  $fileId = (int) $newRowId['name'];
130  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
131  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
132  import('lib.pkp.classes.submission.SubmissionFile'); // Bring in const
133  $submissionFiles = $submissionFileDao->getLatestRevisions($submission->getId(), $this->getFileStage());
134  foreach ($submissionFiles as $submissionFile) {
135  if ($submissionFile->getFileId() == $fileId) {
136  return $submissionFile;
137  }
138  }
139  return null;
140  }
141 }
142 
143 ?>
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 OMP&#39;s submission workflow stage components.
authorize($request, &$args, $roleAssignments, $stageId)
addRoleAssignment($roleIds, $operations)
Base class for selecting files to add a user to.
Represents a column within a listbuilder.
Base class for a cell provider that can retrieve labels from arrays.
& getAuthorizedContextObject($assocType)