• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/controllers/grid/files/SubmissionFilesGridHandlerImplementation.inc.php

00001 <?php
00002 
00016 // Import submission files grid specific classes.
00017 import('controllers.grid.files.SubmissionFilesGridRow');
00018 import('controllers.grid.files.FileNameGridColumn');
00019 
00020 // Import monograph file class which contains the MONOGRAPH_FILE_* constants.
00021 import('classes.monograph.MonographFile');
00022 
00023 // Define the grid capabilities.
00024 define('FILE_GRID_ADD',       0x00000001);
00025 define('FILE_GRID_DOWNLOAD_ALL', 0x00000002);
00026 define('FILE_GRID_DELETE',    0x00000004);
00027 define('FILE_GRID_VIEW_NOTES',      0x00000008);
00028 
00029 class SubmissionFilesGridHandlerImplementation {
00030 
00032    var $_gridHandler;
00033 
00035    var $_stageId;
00036 
00038    var $_canAdd;
00039 
00041    var $_canViewNotes;
00042 
00044    var $_canDownloadAll;
00045 
00047    var $_canDelete;
00048 
00049 
00058    function SubmissionFilesGridHandlerImplementation(&$gridHandler, $stageId, $capabilities) {
00059       $this->_gridHandler =& $gridHandler;
00060 
00061       // the StageId can be set later if necessary.
00062       if ($stageId) {
00063          $this->_stageId = (int)$stageId;
00064       }
00065       $this->setCanAdd($capabilities & FILE_GRID_ADD);
00066       $this->_canDownloadAll = (boolean)($capabilities & FILE_GRID_DOWNLOAD_ALL);
00067       $this->setCanDelete($capabilities & FILE_GRID_DELETE);
00068       $this->_canViewNotes = (boolean)($capabilities & FILE_GRID_VIEW_NOTES);
00069    }
00070 
00071 
00072    //
00073    // Getters and Setters
00074    //
00079    function &getGridHandler() {
00080       return $this->_gridHandler;
00081    }
00082 
00087    function getStageId() {
00088       return $this->_stageId;
00089    }
00090 
00095    function &getMonograph() {
00096       $gridHandler =& $this->getGridHandler();
00097       // We assume proper authentication by the data provider.
00098       $monograph =& $gridHandler->getAuthorizedContextObject(ASSOC_TYPE_MONOGRAPH);
00099       assert(is_a($monograph, 'Monograph'));
00100       return $monograph;
00101    }
00102 
00107    function canAdd() {
00108       return $this->_canAdd;
00109    }
00110 
00115    function setCanAdd($canAdd) {
00116       $this->_canAdd = (boolean) $canAdd;
00117    }
00118 
00123    function canViewNotes() {
00124       return $this->_canViewNotes;
00125    }
00126 
00131    function canDownloadAll() {
00132       return $this->_canDownloadAll;
00133    }
00134 
00139    function canDelete() {
00140       return $this->_canDelete;
00141    }
00142 
00147    function setCanDelete($canDelete) {
00148       $this->_canDelete = (boolean) $canDelete;
00149    }
00150 
00151 
00152    //
00153    // Public methods
00154    //
00158    function authorize(&$request, &$args, $roleAssignments) {
00159       // Set the stage id from the request parameter if not set previously.
00160       if (!$this->getStageId()) {
00161          $stageId = (int) $request->getUserVar('stageId');
00162          // This will be validated with the authorization policy added by
00163          // the grid data provider.
00164          $this->_stageId = $stageId;
00165       }
00166       $gridHandler =& $this->getGridHandler();
00167       $dataProvider =& $gridHandler->getDataProvider();
00168       $dataProvider->setStageId($this->getStageId());
00169    }
00170 
00174    function initialize(&$request) {
00175       // Load translations.
00176       AppLocale::requireComponents(
00177          LOCALE_COMPONENT_OMP_SUBMISSION,
00178          LOCALE_COMPONENT_PKP_SUBMISSION,
00179          LOCALE_COMPONENT_OMP_EDITOR,
00180          LOCALE_COMPONENT_PKP_COMMON,
00181          LOCALE_COMPONENT_APPLICATION_COMMON
00182       );
00183 
00184       // Add grid actions
00185       $gridHandler =& $this->getGridHandler();
00186       $dataProvider =& $gridHandler->getDataProvider();
00187       if($this->canAdd()) {
00188          assert($dataProvider);
00189          $gridHandler->addAction($dataProvider->getAddFileAction($request));
00190       }
00191 
00192       // Test whether the tar binary is available for the export to work, if so, add 'download all' grid action
00193       $tarBinary = Config::getVar('cli', 'tar');
00194       if ($this->canDownloadAll() && !empty($tarBinary) && file_exists($tarBinary) && $gridHandler->hasGridDataElements($request)) {
00195          import('controllers.grid.files.fileList.linkAction.DownloadAllLinkAction');
00196 
00197          $monograph =& $this->getMonograph();
00198          $stageId = $this->getStageId();
00199          $linkParams = array('monographId' => $monograph->getId(), 'stageId' => $stageId);
00200 
00201          // Get the files to be downloaded.
00202          $files =& $gridHandler->getFilesToDownload($request);
00203          if (sizeof($files) > 0) {
00204             $gridHandler->addAction(new DownloadAllLinkAction($request, $linkParams, $files), GRID_ACTION_POSITION_BELOW);
00205          }
00206       }
00207 
00208       // The file name column is common to all file grid types.
00209       $gridHandler->addColumn(new FileNameGridColumn($this->canViewNotes(), $this->getStageId()));
00210 
00211       // Set the no items row text
00212       $gridHandler->setEmptyRowText('grid.noFiles');
00213    }
00214 
00218    function &getRowInstance() {
00219       $row = new SubmissionFilesGridRow($this->canDelete(), $this->canViewNotes(), $this->getStageId());
00220       return $row;
00221    }
00222 }
00223 
00224 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1