Open Journal Systems  3.3.0
SelectableSubmissionFileListCategoryGridHandler.inc.php
1 <?php
2 
16 // Import UI base classes.
17 import('lib.pkp.classes.controllers.grid.CategoryGridHandler');
18 
19 // Import submission files grid specific classes.
20 import('lib.pkp.controllers.grid.files.SubmissionFilesGridRow');
21 import('lib.pkp.controllers.grid.files.FileNameGridColumn');
22 import('lib.pkp.controllers.grid.files.SelectableSubmissionFileListCategoryGridRow');
23 
24 // Import the class that defines file grids capabilities.
25 import('lib.pkp.classes.controllers.grid.files.FilesGridCapabilities');
26 
27 // Import file constants.
28 import('lib.pkp.classes.submission.SubmissionFile');
29 
31 
33  var $_capabilities;
34 
36  var $_stageId;
37 
45  function __construct($dataProvider, $stageId, $capabilities = 0) {
46  // the StageId can be set later if necessary.
47  if ($stageId) {
48  $this->_stageId = (int)$stageId;
49  }
50 
51  $this->_capabilities = new FilesGridCapabilities($capabilities);
52 
53  parent::__construct($dataProvider);
54  }
55 
56 
57  //
58  // Getters and Setters
59  //
64  function getCapabilities() {
65  return $this->_capabilities;
66  }
67 
72  function getStageId() {
73  return $this->_stageId;
74  }
75 
80  function getSubmission() {
81  // We assume proper authentication by the data provider.
82  $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
83  assert(is_a($submission, 'Submission'));
84  return $submission;
85  }
86 
87 
88  //
89  // Overridden methods from GridHandler
90  //
94  protected function loadData($request, $filter) {
95  // Let parent class get data from data provider.
96  $workflowStages = parent::loadData($request, $filter);
97 
98  // Filter the data.
99  if ($filter['allStages']) {
100  return array_combine($workflowStages, $workflowStages);
101  } else {
102  return array($this->getStageId() => $this->getStageId());
103  }
104  }
105 
109  protected function getFilterForm() {
110  return 'controllers/grid/files/selectableSubmissionFileListCategoryGridFilter.tpl';
111  }
112 
116  protected function isFilterFormCollapsible() {
117  return false;
118  }
119 
123  function getFilterSelectionData($request) {
124  return array('allStages' => $request->getUserVar('allStages') ? true : false);
125  }
126 
127 
128  //
129  // Overridden methods from CategoryGridHandler
130  //
134  protected function getCategoryRowInstance() {
136  }
137 
138 
139  //
140  // Implement template methods from PKPHandler
141  //
145  function authorize($request, &$args, $roleAssignments) {
146  // Set the stage id from the request parameter if not set previously.
147  if (!$this->getStageId()) {
148  $stageId = (int) $request->getUserVar('stageId');
149  // This will be validated with the authorization policy added by
150  // the grid data provider.
151  $this->_stageId = $stageId;
152  }
153 
154  $dataProvider = $this->getDataProvider();
155  $dataProvider->setStageId($this->getStageId());
156 
157  return parent::authorize($request, $args, $roleAssignments);
158  }
159 
163  function initialize($request, $args = null) {
164  parent::initialize($request, $args);
165 
166  // Load translations.
168  LOCALE_COMPONENT_APP_SUBMISSION,
169  LOCALE_COMPONENT_PKP_SUBMISSION,
170  LOCALE_COMPONENT_APP_EDITOR,
171  LOCALE_COMPONENT_PKP_EDITOR,
172  LOCALE_COMPONENT_PKP_COMMON,
173  LOCALE_COMPONENT_APP_COMMON
174  );
175 
176  // Add grid actions
177  $capabilities = $this->getCapabilities();
178  $dataProvider = $this->getDataProvider();
179 
180  if($capabilities->canManage()) {
181  $this->addAction($dataProvider->getSelectAction($request));
182  }
183 
184  if($capabilities->canAdd()) {
185  assert(isset($dataProvider));
186  $this->addAction($dataProvider->getAddFileAction($request));
187  }
188 
189  // Test whether an archive tool is available for the export to work, if so, add 'download all' grid action
190  if ($capabilities->canDownloadAll() && $this->hasGridDataElements($request)) {
191  $submission = $this->getSubmission();
192  $stageId = $this->getStageId();
193  $linkParams = array('submissionId' => $submission->getId(), 'stageId' => $stageId);
194  $files = $this->getFilesToDownload($request);
195 
196  $this->addAction($capabilities->getDownloadAllAction($request, $files, $linkParams), GRID_ACTION_POSITION_BELOW);
197  }
198 
199  // The file name column is common to all file grid types.
200  $this->addColumn(new FileNameGridColumn($capabilities->canViewNotes(), $this->getStageId()));
201 
202  // The file list grid layout has an additional file genre column.
203  import('lib.pkp.controllers.grid.files.fileList.FileGenreGridColumn');
204  $this->addColumn(new FileGenreGridColumn());
205 
206  // Set the no items row text
207  $this->setEmptyRowText('grid.noFiles');
208  }
209 
213  function initFeatures($request, $args) {
214  import('lib.pkp.classes.controllers.grid.feature.selectableItems.SelectableItemsFeature');
215  return array(new SelectableItemsFeature());
216  }
217 
218 
219  //
220  // Overridden methods from GridHandler
221  //
225  protected function getRowInstance() {
226  return new SubmissionFilesGridRow($this->getCapabilities(), $this->getStageId());
227  }
228 
229 
230  //
231  // Protected methods
232  //
238  function getFilesToDownload($request) {
239  $dataProvider = $this->getDataProvider();
240  $workflowStages = $this->getGridDataElements($request);
241 
242  // Get the submission files to be downloaded.
243  $submissionFiles = array();
244  foreach ($workflowStages as $stageId) {
245  $submissionFiles = array_merge(
246  $submissionFiles,
247  $this->getGridCategoryDataElements($request, $stageId)
248  );
249  }
250  return $submissionFiles;
251  }
252 
256  function isDataElementInCategorySelected($categoryDataId, &$gridDataElement) {
257  $currentStageId = $this->getAuthorizedContextObject(ASSOC_TYPE_WORKFLOW_STAGE);
258  $submissionFile = $gridDataElement['submissionFile'];
259 
260  // Check for special cases when the file needs to be unselected.
261  $dataProvider = $this->getDataProvider();
262  if ($dataProvider->getFileStage() != $submissionFile->getFileStage()) {
263  return false;
264  } elseif ($currentStageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW || $currentStageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) {
265  if ($currentStageId != $categoryDataId) {
266  return false;
267  }
268  }
269 
270  // Passed the checks above. If viewable then select it.
271  return $submissionFile->getViewable();
272  }
273 
278  function getSelectName() {
279  return 'selectedFiles';
280  }
281 }
282 
283 
GridHandler\setEmptyRowText
setEmptyRowText($emptyRowText)
Definition: GridHandler.inc.php:231
PKPHandler\__construct
__construct()
Definition: PKPHandler.inc.php:85
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
SelectableSubmissionFileListCategoryGridHandler\getRowInstance
getRowInstance()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:231
GridHandler\getDataProvider
getDataProvider()
Definition: GridHandler.inc.php:157
SelectableSubmissionFileListCategoryGridHandler\getSelectName
getSelectName()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:284
SelectableSubmissionFileListCategoryGridHandler\getSubmission
getSubmission()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:86
FileGenreGridColumn
Implements a file name column.
Definition: FileGenreGridColumn.inc.php:17
SelectableSubmissionFileListCategoryGridHandler\isDataElementInCategorySelected
isDataElementInCategorySelected($categoryDataId, &$gridDataElement)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:262
SelectableSubmissionFileListCategoryGridHandler\$_stageId
$_stageId
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:42
GridHandler\getGridDataElements
& getGridDataElements($request)
Definition: GridHandler.inc.php:345
GridHandler\addAction
addAction($action, $position=GRID_ACTION_POSITION_ABOVE)
Definition: GridHandler.inc.php:266
GridHandler\addColumn
addColumn($column)
Definition: GridHandler.inc.php:335
FileNameGridColumn
Implements a file name column.
Definition: FileNameGridColumn.inc.php:18
SelectableSubmissionFileListCategoryGridHandler\getFilesToDownload
getFilesToDownload($request)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:244
SelectableItemsFeature
Implements grid widgets selectable items functionality.
Definition: SelectableItemsFeature.inc.php:19
SelectableSubmissionFileListCategoryGridHandler\getFilterForm
getFilterForm()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:115
CategoryGridHandler
Class defining basic operations for handling HTML grids with categories.
Definition: CategoryGridHandler.inc.php:23
SelectableSubmissionFileListCategoryGridHandler\getCategoryRowInstance
getCategoryRowInstance()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:140
SelectableSubmissionFileListCategoryGridHandler\isFilterFormCollapsible
isFilterFormCollapsible()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:122
SelectableSubmissionFileListCategoryGridHandler\initialize
initialize($request, $args=null)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:169
SelectableSubmissionFileListCategoryGridHandler\$_capabilities
$_capabilities
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:36
SelectableSubmissionFileListCategoryGridHandler\getStageId
getStageId()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:78
SelectableSubmissionFileListCategoryGridHandler\getFilterSelectionData
getFilterSelectionData($request)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:129
PKPHandler\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: PKPHandler.inc.php:174
SelectableSubmissionFileListCategoryGridHandler\initFeatures
initFeatures($request, $args)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:219
SelectableSubmissionFileListCategoryGridHandler\getCapabilities
getCapabilities()
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:70
SelectableSubmissionFileListCategoryGridHandler
Handle selectable submission file list category grid requests.
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:30
CategoryGridHandler\getGridCategoryDataElements
& getGridCategoryDataElements($request, $categoryElement)
Definition: CategoryGridHandler.inc.php:123
FilesGridCapabilities
Defines files grid capabilities. Should be used by grid handlers that handle submission files to stor...
Definition: FilesGridCapabilities.inc.php:25
SelectableSubmissionFileListCategoryGridHandler\__construct
__construct($dataProvider, $stageId, $capabilities=0)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:51
SelectableSubmissionFileListCategoryGridHandler\loadData
loadData($request, $filter)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:100
SelectableSubmissionFileListCategoryGridRow
Selectable submission file list category grid row definition.
Definition: SelectableSubmissionFileListCategoryGridRow.inc.php:17
SelectableSubmissionFileListCategoryGridHandler\authorize
authorize($request, &$args, $roleAssignments)
Definition: SelectableSubmissionFileListCategoryGridHandler.inc.php:151
SubmissionFilesGridRow
Handle submission file grid row requests.
Definition: SubmissionFilesGridRow.inc.php:19