00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class SuppFileForm extends Form {
00022 var $suppFileId;
00023
00025 var $article;
00026
00028 var $suppFile;
00029
00035 function SuppFileForm($article, $suppFileId = null) {
00036 parent::Form('submission/suppFile/suppFile.tpl');
00037
00038 $this->article = $article;
00039
00040 if (isset($suppFileId) && !empty($suppFileId)) {
00041 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00042 $this->suppFile = &$suppFileDao->getSuppFile($suppFileId, $article->getArticleId());
00043 if (isset($this->suppFile)) {
00044 $this->suppFileId = $suppFileId;
00045 }
00046 }
00047
00048
00049 $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'author.submit.suppFile.form.titleRequired'));
00050 $this->addCheck(new FormValidatorPost($this));
00051 }
00052
00057 function getLocaleFieldNames() {
00058 $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
00059 return $suppFileDao->getLocaleFieldNames();
00060 }
00061
00065 function display() {
00066 $journal = &Request::getJournal();
00067
00068 $templateMgr = &TemplateManager::getManager();
00069 $templateMgr->assign('enablePublicSuppFileId', $journal->getSetting('enablePublicSuppFileId'));
00070 $templateMgr->assign('rolePath', Request::getRequestedPage());
00071 $templateMgr->assign('articleId', $this->article->getArticleId());
00072 $templateMgr->assign('suppFileId', $this->suppFileId);
00073
00074 $typeOptionsOutput = array(
00075 'author.submit.suppFile.researchInstrument',
00076 'author.submit.suppFile.researchMaterials',
00077 'author.submit.suppFile.researchResults',
00078 'author.submit.suppFile.transcripts',
00079 'author.submit.suppFile.dataAnalysis',
00080 'author.submit.suppFile.dataSet',
00081 'author.submit.suppFile.sourceText'
00082 );
00083 $typeOptionsValues = $typeOptionsOutput;
00084 array_push($typeOptionsOutput, 'common.other');
00085 array_push($typeOptionsValues, '');
00086
00087 $templateMgr->assign('typeOptionsOutput', $typeOptionsOutput);
00088 $templateMgr->assign('typeOptionsValues', $typeOptionsValues);
00089
00090
00091
00092 $templateMgr->assign('from', Request::getUserVar('from'));
00093
00094 if (isset($this->article)) {
00095 $templateMgr->assign('submissionProgress', $this->article->getSubmissionProgress());
00096 }
00097
00098 if (isset($this->suppFile)) {
00099 $templateMgr->assign_by_ref('suppFile', $this->suppFile);
00100 }
00101 $templateMgr->assign('helpTopicId','submission.supplementaryFiles');
00102 parent::display();
00103 }
00104
00108 function validate() {
00109 $journal = &Request::getJournal();
00110 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00111
00112 $publicSuppFileId = $this->getData('publicSuppFileId');
00113 if ($publicSuppFileId && $suppFileDao->suppFileExistsByPublicId($publicSuppFileId, $this->suppFileId, $journal->getJournalId())) {
00114 $this->addError('publicIssueId', Locale::translate('author.suppFile.suppFilePublicIdentificationExists'));
00115 $this->addErrorField('publicSuppFileId');
00116 }
00117
00118 return parent::validate();
00119 }
00120
00124 function initData() {
00125 if (isset($this->suppFile)) {
00126 $suppFile = &$this->suppFile;
00127 $this->_data = array(
00128 'title' => $suppFile->getTitle(null),
00129 'creator' => $suppFile->getCreator(null),
00130 'subject' => $suppFile->getSubject(null),
00131 'type' => $suppFile->getType(),
00132 'typeOther' => $suppFile->getTypeOther(null),
00133 'description' => $suppFile->getDescription(null),
00134 'publisher' => $suppFile->getPublisher(null),
00135 'sponsor' => $suppFile->getSponsor(null),
00136 'dateCreated' => $suppFile->getDateCreated(),
00137 'source' => $suppFile->getSource(null),
00138 'language' => $suppFile->getLanguage(),
00139 'showReviewers' => $suppFile->getShowReviewers()==1?1:0,
00140 'publicSuppFileId' => $suppFile->getPublicSuppFileId()
00141 );
00142
00143 } else {
00144 $this->_data = array(
00145 'type' => '',
00146 'showReviewers' => 1
00147 );
00148 }
00149
00150 }
00151
00155 function readInputData() {
00156 $this->readUserVars(
00157 array(
00158 'title',
00159 'creator',
00160 'subject',
00161 'type',
00162 'typeOther',
00163 'description',
00164 'publisher',
00165 'sponsor',
00166 'dateCreated',
00167 'source',
00168 'language',
00169 'showReviewers',
00170 'publicSuppFileId'
00171 )
00172 );
00173 }
00174
00179 function execute($fileName = null) {
00180 import("file.ArticleFileManager");
00181 $articleFileManager = &new ArticleFileManager($this->article->getArticleId());
00182 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00183
00184 $fileName = isset($fileName) ? $fileName : 'uploadSuppFile';
00185
00186 if (isset($this->suppFile)) {
00187 $suppFile = &$this->suppFile;
00188
00189
00190 if ($articleFileManager->uploadedFileExists($fileName)) {
00191 $articleFileManager->uploadSuppFile($fileName, $suppFile->getFileId());
00192 import('search.ArticleSearchIndex');
00193 ArticleSearchIndex::updateFileIndex($this->article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $suppFile->getFileId());
00194 }
00195
00196
00197 ArticleSearchIndex::indexSuppFileMetadata($suppFile);
00198
00199
00200 $this->setSuppFileData($suppFile);
00201 $suppFileDao->updateSuppFile($suppFile);
00202
00203 } else {
00204
00205 if ($articleFileManager->uploadedFileExists($fileName)) {
00206 $fileId = $articleFileManager->uploadSuppFile($fileName);
00207 import('search.ArticleSearchIndex');
00208 ArticleSearchIndex::updateFileIndex($this->article->getArticleId(), ARTICLE_SEARCH_SUPPLEMENTARY_FILE, $fileId);
00209 } else {
00210 $fileId = 0;
00211 }
00212
00213
00214 $suppFile = &new SuppFile();
00215 $suppFile->setArticleId($this->article->getArticleId());
00216 $suppFile->setFileId($fileId);
00217 $this->setSuppFileData($suppFile);
00218 $suppFileDao->insertSuppFile($suppFile);
00219 $this->suppFileId = $suppFile->getSuppFileId();
00220 }
00221
00222 return $this->suppFileId;
00223 }
00224
00229 function setSuppFileData(&$suppFile) {
00230 $suppFile->setTitle($this->getData('title'), null);
00231 $suppFile->setCreator($this->getData('creator'), null);
00232 $suppFile->setSubject($this->getData('subject'), null);
00233 $suppFile->setType($this->getData('type'));
00234 $suppFile->setTypeOther($this->getData('typeOther'), null);
00235 $suppFile->setDescription($this->getData('description'), null);
00236 $suppFile->setPublisher($this->getData('publisher'), null);
00237 $suppFile->setSponsor($this->getData('sponsor'), null);
00238 $suppFile->setDateCreated($this->getData('dateCreated') == '' ? Core::getCurrentDate() : $this->getData('dateCreated'));
00239 $suppFile->setSource($this->getData('source'), null);
00240 $suppFile->setLanguage($this->getData('language'));
00241 $suppFile->setShowReviewers($this->getData('showReviewers')==1?1:0);
00242 $suppFile->setPublicSuppFileId($this->getData('publicSuppFileId'));
00243 }
00244 }
00245
00246 ?>