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
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
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
00062 $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00063 $reviewAssignment =& $reviewAssignmentDao->getById((int) $assocId);
00064 if ($reviewAssignment->getDateCompleted()) fatalError('Review already completed!');
00065
00066
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
00081 $this->addCheck(new FormValidatorPost($this));
00082 }
00083
00084
00085
00086
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');
00136 if ($this->getStageId() == WORKFLOW_STAGE_ID_INTERNAL_REVIEW || $this->getStageId() == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) {
00137
00138 if (!is_a($this->getReviewRound(), 'ReviewRound')) assert(false);
00139
00140
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
00144
00145 if ($this->getData('fileStage') == MONOGRAPH_FILE_REVIEW_ATTACHMENT) {
00146 $this->_monographFiles = array();
00147 } else {
00148
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
00155 $this->_monographFiles =& $submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_PUBLICATION_FORMAT,
00156 $this->getAssocId(), $this->getData('monographId'), $this->getData('fileStage'));
00157 } else {
00158
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
00171
00175 function readInputData() {
00176
00177
00178 $this->readUserVars(array('revisedFileId'));
00179 }
00180
00184 function fetch($request) {
00185
00186 $this->setData('stageId', $this->getStageId());
00187
00188
00189 $reviewRound =& $this->getReviewRound();
00190 if (is_a($reviewRound, 'ReviewRound')) {
00191 $this->setData('reviewRoundId', $reviewRound->getId());
00192 }
00193
00194
00195 $uploadedFile =& $this->getData('uploadedFile');
00196
00197
00198 $monographFileOptions = array();
00199 $currentMonographFileGenres = array();
00200
00201
00202 $revisedFileId = $this->getRevisedFileId();
00203 $foundRevisedFile = false;
00204 $monographFiles =& $this->getMonographFiles();
00205 foreach ($monographFiles as $monographFile) {
00206
00207 if ($uploadedFile && $uploadedFile->getFileId() == $monographFile->getFileId()) continue;
00208
00209
00210 if ($revisedFileId && $revisedFileId == $monographFile->getFileId()) {
00211
00212 $this->setData('revisedFileName', $monographFile->getOriginalFileName());
00213 $this->setData('genreId', $monographFile->getGenreId());
00214 $foundRevisedFile = true;
00215 }
00216
00217
00218
00219
00220 $fileName = $monographFile->getLocalizedName() != '' ? $monographFile->getLocalizedName() : __('common.untitled');
00221 if ($monographFile->getRevision() > 1) $fileName .= ' (' . $monographFile->getRevision() . ')';
00222
00223
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
00235 if (count($monographFileOptions) == 1 && $this->getData('revisionOnly')) {
00236
00237 $this->setData('revisedFileId', $lastMonographFile->getFileId());
00238 $this->setData('revisedFileName', $lastMonographFile->getOriginalFileName());
00239 $this->setData('genreId', $lastMonographFile->getGenreId());
00240 }
00241
00242
00243 if (count($monographFileOptions) && !$this->getData('revisionOnly')) {
00244 $monographFileOptions = array('' => __('submission.upload.uploadNewFile')) + $monographFileOptions;
00245 }
00246
00247
00248
00249 if ($revisedFileId && !$foundRevisedFile) fatalError('Invalid revised file id!');
00250
00251
00252 $this->setData('currentMonographFileGenres', $currentMonographFileGenres);
00253 $this->setData('monographFileOptions', $monographFileOptions);
00254
00255
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 ?>