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

controllers/wizard/fileUpload/form/SubmissionFilesUploadForm.inc.php

00001 <?php
00002 
00016 import('controllers.wizard.fileUpload.form.SubmissionFilesUploadBaseForm');
00017 
00018 class SubmissionFilesUploadForm extends SubmissionFilesUploadBaseForm {
00019 
00021    var $_uploaderRoles;
00022 
00023 
00036    function SubmissionFilesUploadForm(&$request, $monographId, $stageId, $uploaderRoles, $fileStage,
00037          $revisionOnly = false, $reviewRound = null, $revisedFileId = null, $assocType = null, $assocId = null) {
00038 
00039       // Initialize class.
00040       assert(is_null($uploaderRoles) || (is_array($uploaderRoles) && count($uploaderRoles) >= 1));
00041       $this->_uploaderRoles = $uploaderRoles;
00042 
00043       AppLocale::requireComponents(LOCALE_COMPONENT_OMP_MANAGER);
00044 
00045       parent::SubmissionFilesUploadBaseForm(
00046          $request, 'controllers/wizard/fileUpload/form/fileUploadForm.tpl',
00047          $monographId, $stageId, $fileStage, $revisionOnly, $reviewRound, $revisedFileId, $assocType, $assocId
00048       );
00049    }
00050 
00051 
00052    //
00053    // Getters and Setters
00054    //
00059    function getUploaderRoles() {
00060       assert(!is_null($this->_uploaderRoles));
00061       return $this->_uploaderRoles;
00062    }
00063 
00064 
00065    //
00066    // Implement template methods from Form
00067    //
00071    function readInputData() {
00072       $this->readUserVars(array('genreId', 'uploaderUserGroupId'));
00073       return parent::readInputData();
00074    }
00075 
00079    function validate(&$request) {
00080       // Is this a revision?
00081       $revisedFileId = $this->getRevisedFileId();
00082       if ($this->getData('revisionOnly')) {
00083          assert($revisedFileId > 0);
00084       }
00085 
00086       // Retrieve the request context.
00087       $router =& $request->getRouter();
00088       $context =& $router->getContext($request);
00089 
00090       if (!$revisedFileId) {
00091          // Add an additional check for the genre to the form.
00092          $this->addCheck(
00093             new FormValidatorCustom(
00094                $this, 'genreId', FORM_VALIDATOR_REQUIRED_VALUE,
00095                'submission.upload.noGenre',
00096                create_function(
00097                   '$genreId,$genreDao,$context',
00098                   'return is_a($genreDao->getById($genreId, $context->getId()), "Genre");'
00099                ),
00100                array(DAORegistry::getDAO('GenreDAO'), $context)
00101             )
00102          );
00103       }
00104 
00105       // Validate the uploader's user group.
00106       $uploaderUserGroupId = $this->getData('uploaderUserGroupId');
00107       if ($uploaderUserGroupId) {
00108          $user =& $request->getUser();
00109          $this->addCheck(
00110             new FormValidatorCustom(
00111                $this, 'uploaderUserGroupId', FORM_VALIDATOR_REQUIRED_VALUE,
00112                'submission.upload.invalidUserGroup',
00113                create_function(
00114                   '$userGroupId,$userGroupDao,$userId',
00115                   'return $userGroupDao->userInGroup($userId, $userGroupId);'
00116                ),
00117                array(DAORegistry::getDAO('UserGroupDAO'), $user->getId(), $context)
00118             )
00119          );
00120       }
00121 
00122       return parent::validate();
00123    }
00124 
00128    function fetch($request) {
00129       // Retrieve available monograph file genres.
00130       $genreList =& $this->_retrieveGenreList($request);
00131       $this->setData('monographFileGenres', $genreList);
00132 
00133       // Retrieve the current context.
00134       $router =& $request->getRouter();
00135       $context =& $router->getContext($request);
00136       assert(is_a($context, 'Press'));
00137 
00138       // Retrieve the user's user groups.
00139       $user =& $request->getUser();
00140       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
00141       $assignedUserGroups =& $userGroupDao->getByUserId($user->getId(), $context->getId());
00142 
00143       // Check which of these groups make sense in the context
00144       // from which the uploader was instantiated.
00145       // FIXME: The series editor role may only be displayed if the
00146       // user is assigned to the current submission as a series
00147       // editor, see #6000.
00148       $uploaderRoles = $this->getUploaderRoles();
00149       $uploaderUserGroups = array();
00150       $highestAuthorityUserGroupId = null;
00151       $highestAuthorityRoleId = null;
00152       while($userGroup =& $assignedUserGroups->next()) { /* @var $userGroup UserGroup */
00153          // Add all user groups that belong to any of the uploader roles.
00154          if (in_array($userGroup->getRoleId(), $uploaderRoles)) {
00155             $uploaderUserGroups[$userGroup->getId()] = $userGroup->getLocalizedName();
00156 
00157             // Identify the first of the user groups that belongs
00158             // to the role with the lowest role id (=highest authority
00159             // level). We'll need this information to identify the default
00160             // selection, see below.
00161             if (is_null($highestAuthorityUserGroupId) || $userGroup->getRoleId() <= $highestAuthorityRoleId) {
00162                $highestAuthorityRoleId = $userGroup->getRoleId();
00163                if (is_null($highestAuthorityUserGroupId) || $userGroup->getId() < $highestAuthorityUserGroupId) {
00164                   $highestAuthorityUserGroupId = $userGroup->getId();
00165                }
00166             }
00167          }
00168 
00169          unset($userGroup);
00170       }
00171       if (empty($uploaderUserGroups)) fatalError('Invalid uploader roles!');
00172       $this->setData('uploaderUserGroups', $uploaderUserGroups);
00173 
00174       // Identify the default user group (only required when there is
00175       // more than one group).
00176       $defaultUserGroupId = null;
00177       if (count($uploaderUserGroups) > 1) {
00178          // See whether the current user has been assigned as
00179          // a workflow stage participant.
00180          $stageAssignmentDao = & DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
00181          $stageAssignments = $stageAssignmentDao->getBySubmissionAndStageId(
00182             $this->getData('monographId'),
00183             $this->getStageId(),
00184             null,
00185             $user->getId()
00186          );
00187 
00188          while ($stageAssignment =& $stageAssignments->next()) { /* @var $stageSignoff Signoff */
00189             if (isset($uploaderUserGroups[$stageAssignment->getUserGroupId()])) {
00190                $defaultUserGroupId = $stageAssignment->getUserGroupId();
00191                break;
00192             }
00193          }
00194 
00195          // If we didn't find a corresponding stage signoff then
00196          // use the user group with the highest authority as default.
00197          if (is_null($defaultUserGroupId)) $defaultUserGroupId = $highestAuthorityUserGroupId;
00198       }
00199       $this->setData('defaultUserGroupId', $defaultUserGroupId);
00200 
00201       $settingsDao =& DAORegistry::getDAO('PressSettingsDAO');
00202       $this->setData('pressSettings', $settingsDao->getPressSettings($context->getId()));
00203 
00204       // Include a status message for this installation's max file upload size.
00205       $this->setData('maxFileUploadSize', get_cfg_var('upload_max_filesize'));
00206 
00207       return parent::fetch($request);
00208    }
00209 
00215    function &execute($request) {
00216       // Identify the file genre and category.
00217       $revisedFileId = $this->getRevisedFileId();
00218       if ($revisedFileId) {
00219          // The file genre and category will be copied over from the revised file.
00220          $fileGenre = null;
00221       } else {
00222          // This is a new file so we need the file genre and category from the form.
00223          $fileGenre = $this->getData('genreId') ? (int)$this->getData('genreId') : null;
00224       }
00225 
00226       // Retrieve the uploader's user group.
00227       $uploaderUserGroupId = $this->getData('uploaderUserGroupId');
00228       if (!$uploaderUserGroupId) fatalError('Invalid uploader user group!');
00229 
00230       // Identify the uploading user.
00231       $user =& $request->getUser();
00232       assert(is_a($user, 'User'));
00233 
00234       $assocType = $this->getData('assocType') ? (int) $this->getData('assocType') : null;
00235       $assocId = $this->getData('assocId') ? (int) $this->getData('assocId') : null;
00236 
00237       // Upload the file.
00238       $press =& $request->getPress();
00239       import('classes.file.MonographFileManager');
00240       $monographFileManager = new MonographFileManager($press->getId(), $this->getData('monographId'));
00241       $fileStage = $this->getData('fileStage');
00242       $monographFile = $monographFileManager->uploadMonographFile(
00243          'uploadedFile', $fileStage,
00244          $user->getId(), $uploaderUserGroupId, $revisedFileId, $fileGenre, $assocType, $assocId
00245       );
00246 
00247       if ($monographFile && ($fileStage == MONOGRAPH_FILE_REVIEW_FILE || $fileStage == MONOGRAPH_FILE_REVIEW_ATTACHMENT || $fileStage == MONOGRAPH_FILE_REVIEW_REVISION)) {
00248          // Add the uploaded review file to the review round.
00249          $reviewRound =& $this->getReviewRound();
00250          $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO');
00251          $submissionFileDao->assignRevisionToReviewRound($monographFile->getFileId(), $monographFile->getRevision(), $reviewRound);
00252       }
00253 
00254       if ($monographFile) {
00255          // log the upload event.
00256          import('classes.log.MonographFileLog');
00257          import('classes.log.MonographFileEventLogEntry'); // constants
00258          $localeKey = $revisedFileId ? 'submission.event.revisionUploaded' : 'submission.event.fileUploaded';
00259          $assocType = $revisedFileId ? MONOGRAPH_LOG_FILE_REVISION_UPLOAD : MONOGRAPH_LOG_FILE_UPLOAD;
00260          MonographFileLog::logEvent($request, $monographFile, $assocType, $localeKey, array('fileStage' => $fileStage, 'revisedFileId' => $revisedFileId, 'fileId' => $monographFile->getFileId(), 'fileRevision' => $monographFile->getRevision(), 'originalFileName' => $monographFile->getOriginalFileName(), 'submissionId' => $this->getData('monographId'), 'username' => $user->getUsername()));
00261       }
00262 
00263       return $monographFile;
00264    }
00265 
00266 
00267    //
00268    // Private helper methods
00269    //
00275    function &_retrieveGenreList(&$request) {
00276       $context =& $request->getContext();
00277       $genreDao =& DAORegistry::getDAO('GenreDAO'); /* @var $genreDao GenreDAO */
00278       $genres =& $genreDao->getEnabledByPressId($context->getId());
00279 
00280       // Transform the genres into an array and
00281       // assign them to the form.
00282       $genreList = array();
00283       while($genre =& $genres->next()){
00284          $genreId = $genre->getId();
00285          $genreList[$genreId] = $genre->getLocalizedName();
00286          unset($genre);
00287       }
00288       return $genreList;
00289    }
00290 }
00291 
00292 ?>

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