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

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

00001 <?php
00002 
00016 import('lib.pkp.classes.form.Form');
00017 import('classes.file.MonographFileManager');
00018 import('classes.monograph.MonographFile');
00019 
00020 class SubmissionFilesUploadBaseForm extends Form {
00021 
00023    var $_stageId;
00024 
00026    var $_reviewRound;
00027 
00029    var $_monographFiles;
00030 
00031 
00043    function SubmissionFilesUploadBaseForm(&$request, $template, $monographId, $stageId, $fileStage,
00044          $revisionOnly = false, $reviewRound = null, $revisedFileId = null, $assocType = null, $assocId = null) {
00045 
00046       // Check the incoming parameters.
00047       if ( !is_numeric($monographId) || $monographId <= 0 ||
00048          !is_numeric($fileStage) || $fileStage <= 0 ||
00049          !is_numeric($stageId) || $stageId < 1 || $stageId > 5 ||
00050          isset($assocType) !== isset($assocId)) {
00051          fatalError('Invalid parameters!');
00052       }
00053 
00054       // Initialize class.
00055       parent::Form($template);
00056       $this->_stageId = $stageId;
00057 
00058       if ($reviewRound) {
00059          $this->_reviewRound =& $reviewRound;
00060       } else if ($assocType == ASSOC_TYPE_REVIEW_ASSIGNMENT && !$reviewRound) {
00061          // Get the review assignment object.
00062          $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
00063          $reviewAssignment =& $reviewAssignmentDao->getById((int) $assocId); /* @var $reviewAssignment ReviewAssignment */
00064          if ($reviewAssignment->getDateCompleted()) fatalError('Review already completed!');
00065 
00066          // Get the review round object.
00067          $reviewRoundDao =& DAORegistry::getDAO('ReviewRound');
00068          $this->_reviewRound =& $reviewRoundDao->getReviewRoundById($reviewAssignment->getReviewRoundId());
00069       } else if (!$assocType && !$reviewRound) {
00070          $reviewRound = null;
00071       }
00072 
00073       $this->setData('fileStage', (int)$fileStage);
00074       $this->setData('monographId', (int)$monographId);
00075       $this->setData('revisionOnly', (boolean)$revisionOnly);
00076       $this->setData('revisedFileId', $revisedFileId ? (int)$revisedFileId : null);
00077       $this->setData('assocType', $assocType ? (int)$assocType : null);
00078       $this->setData('assocId', $assocId ? (int)$assocId : null);
00079 
00080       // Add validators.
00081       $this->addCheck(new FormValidatorPost($this));
00082    }
00083 
00084 
00085    //
00086    // Setters and Getters
00087    //
00092    function getStageId() {
00093       return $this->_stageId;
00094    }
00095 
00100    function &getReviewRound() {
00101       return $this->_reviewRound;
00102    }
00103 
00108    function getRevisedFileId() {
00109       return $this->getData('revisedFileId') ? (int)$this->getData('revisedFileId') : null;
00110    }
00111 
00116    function getAssocType() {
00117       return $this->getData('assocType');
00118    }
00119 
00124    function getAssocId() {
00125       return $this->getData('assocId');
00126    }
00127 
00133    function &getMonographFiles() {
00134       if (is_null($this->_monographFiles)) {
00135          $submissionFileDao =& DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
00136          if ($this->getStageId() == WORKFLOW_STAGE_ID_INTERNAL_REVIEW || $this->getStageId() == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) {
00137             // If we have a review stage id then we also expect a review round.
00138             if (!is_a($this->getReviewRound(), 'ReviewRound')) assert(false);
00139 
00140             // Can only upload submission files, review files, or review attachments.
00141             if (!in_array($this->getData('fileStage'), array(MONOGRAPH_FILE_SUBMISSION, MONOGRAPH_FILE_REVIEW_FILE, MONOGRAPH_FILE_REVIEW_ATTACHMENT, MONOGRAPH_FILE_REVIEW_REVISION))) fatalError('Invalid file stage!');
00142 
00143             // Hide the revision selector for review
00144             // attachments to make it easier for reviewers
00145             if ($this->getData('fileStage') == MONOGRAPH_FILE_REVIEW_ATTACHMENT) {
00146                $this->_monographFiles = array();
00147             } else {
00148                // Retrieve the monograph files for the given review round.
00149                $reviewRound =& $this->getReviewRound();
00150                $this->_monographFiles =& $submissionFileDao->getRevisionsByReviewRound($reviewRound);
00151             }
00152          } else if ($this->getStageId() == WORKFLOW_STAGE_ID_PRODUCTION &&
00153             $this->getAssocType() == ASSOC_TYPE_PUBLICATION_FORMAT && is_int($this->getAssocId())) {
00154             // Retrieve only the monograph files with the same publication format.
00155             $this->_monographFiles =& $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_PUBLICATION_FORMAT,
00156                $this->getAssocId(), $this->getData('monographId'), $this->getData('fileStage'));
00157          } else {
00158             // Retrieve the monograph files for the given file stage.
00159             $this->_monographFiles =& $submissionFileDao->getLatestRevisions(
00160                $this->getData('monographId'), $this->getData('fileStage')
00161             );
00162          }
00163       }
00164 
00165       return $this->_monographFiles;
00166    }
00167 
00168 
00169    //
00170    // Implement template methods from Form
00171    //
00175    function readInputData() {
00176       // Only Genre and revised file can be set in the form. All other
00177       // information is generated on our side.
00178       $this->readUserVars(array('revisedFileId'));
00179    }
00180 
00184    function fetch($request) {
00185       // Set the workflow stage.
00186       $this->setData('stageId', $this->getStageId());
00187 
00188       // Set the review round id, if any.
00189       $reviewRound =& $this->getReviewRound();
00190       if (is_a($reviewRound, 'ReviewRound')) {
00191          $this->setData('reviewRoundId', $reviewRound->getId());
00192       }
00193 
00194       // Retrieve the uploaded file (if any).
00195       $uploadedFile =& $this->getData('uploadedFile');
00196 
00197       // Initialize the list with files available for review.
00198       $monographFileOptions = array();
00199       $currentMonographFileGenres = array();
00200 
00201       // Go through all files and build a list of files available for review.
00202       $revisedFileId = $this->getRevisedFileId();
00203       $foundRevisedFile = false;
00204       $monographFiles =& $this->getMonographFiles();
00205       foreach ($monographFiles as $monographFile) {
00206          // The uploaded file must be excluded from the list of revisable files.
00207          if ($uploadedFile && $uploadedFile->getFileId() == $monographFile->getFileId()) continue;
00208 
00209          // Is this the revised file?
00210          if ($revisedFileId && $revisedFileId == $monographFile->getFileId()) {
00211             // This is the revised monograph file, so pass it's data on to the form.
00212             $this->setData('revisedFileName', $monographFile->getOriginalFileName());
00213             $this->setData('genreId', $monographFile->getGenreId());
00214             $foundRevisedFile = true;
00215          }
00216 
00217          // Create an entry in the list of existing files which
00218          // the user can select from in case he chooses to upload
00219          // a revision.
00220          $fileName = $monographFile->getLocalizedName() != '' ? $monographFile->getLocalizedName() : __('common.untitled');
00221          if ($monographFile->getRevision() > 1) $fileName .= ' (' . $monographFile->getRevision() . ')';
00222 
00223          // If we are about to add a revision of a revision, remove the original one from the list of possible file choices.
00224          if (array_key_exists($monographFile->getSourceFileId(), $monographFileOptions)) {
00225             unset($monographFileOptions[$monographFile->getSourceFileId()]);
00226          }
00227 
00228          $monographFileOptions[$monographFile->getFileId()] = $fileName;
00229          $currentMonographFileGenres[$monographFile->getFileId()] = $monographFile->getGenreId();
00230 
00231          $lastMonographFile = $monographFile;
00232       }
00233 
00234       // If there is only one option for a file to review, and user must revise, do not show the selector.
00235       if (count($monographFileOptions) == 1 && $this->getData('revisionOnly')) {
00236          // There was only one option, use the last added monograph file
00237          $this->setData('revisedFileId', $lastMonographFile->getFileId());
00238          $this->setData('revisedFileName', $lastMonographFile->getOriginalFileName());
00239          $this->setData('genreId', $lastMonographFile->getGenreId());
00240       }
00241 
00242       // If this is not a "review only" form then add a default item.
00243       if (count($monographFileOptions) && !$this->getData('revisionOnly')) {
00244          $monographFileOptions = array('' => __('submission.upload.uploadNewFile')) + $monographFileOptions;
00245       }
00246 
00247       // Make sure that the revised file (if any) really was among
00248       // the retrieved monograph files in the current file stage.
00249       if ($revisedFileId && !$foundRevisedFile) fatalError('Invalid revised file id!');
00250 
00251       // Set the review file candidate data in the template.
00252       $this->setData('currentMonographFileGenres', $currentMonographFileGenres);
00253       $this->setData('monographFileOptions', $monographFileOptions);
00254 
00255       // Show ensuring a blind review link.
00256       $press =& $request->getPress();
00257       if ($press->getSetting('showEnsuringLink')) {
00258          import('lib.pkp.classes.linkAction.request.ConfirmationModal');
00259          $ensuringLink = new LinkAction(
00260             'addUser',
00261             new ConfirmationModal(
00262                __('review.blindPeerReview'),
00263                __('review.ensuringBlindReview')),
00264             __('review.ensuringBlindReview'));
00265 
00266          $templateMgr =& TemplateManager::getManager();
00267          $templateMgr->assign('ensuringLink', $ensuringLink);
00268       }
00269 
00270       return parent::fetch($request);
00271    }
00272 }
00273 
00274 ?>

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