00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class MetadataForm extends Form {
00022 var $article;
00023
00025 var $canEdit;
00026
00028 var $canViewAuthors;
00029
00033 function MetadataForm($article) {
00034 $roleDao = &DAORegistry::getDAO('RoleDAO');
00035 $copyAssignmentDao = &DAORegistry::getDAO('CopyAssignmentDAO');
00036
00037 $user = &Request::getUser();
00038 $roleId = $roleDao->getRoleIdFromPath(Request::getRequestedPage());
00039
00040
00041 $this->canEdit = false;
00042 if ($roleId != null && ($roleId == ROLE_ID_EDITOR || $roleId == ROLE_ID_SECTION_EDITOR)) {
00043 $this->canEdit = true;
00044 }
00045
00046
00047 if ($roleId == ROLE_ID_AUTHOR) {
00048 $copyAssignment = $copyAssignmentDao->getCopyAssignmentByArticleId($article->getArticleId());
00049 if ($article->getStatus() != STATUS_PUBLISHED && ($copyAssignment == null || $copyAssignment->getDateCompleted() == null)) {
00050 $this->canEdit = true;
00051 }
00052 }
00053
00054
00055
00056 if ($roleId != null && ($roleId == ROLE_ID_COPYEDITOR)) {
00057 $copyAssignment = $copyAssignmentDao->getCopyAssignmentByArticleId($article->getArticleId());
00058 if ($copyAssignment != null && $article->getStatus() != STATUS_PUBLISHED) {
00059 if ($copyAssignment->getDateNotified() != null && $copyAssignment->getDateFinalCompleted() == null) {
00060 $this->canEdit = true;
00061 }
00062 }
00063 }
00064
00065 if ($this->canEdit) {
00066 parent::Form('submission/metadata/metadataEdit.tpl');
00067 $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'author.submit.form.titleRequired'));
00068 } else {
00069 parent::Form('submission/metadata/metadataView.tpl');
00070 }
00071
00072
00073 $this->canViewAuthors = true;
00074 if ($roleId != null && $roleId == ROLE_ID_REVIEWER) {
00075 $this->canViewAuthors = false;
00076 }
00077
00078 $this->article = $article;
00079
00080 $this->addCheck(new FormValidatorPost($this));
00081 }
00082
00086 function initData() {
00087 if (isset($this->article)) {
00088 $article = &$this->article;
00089 $this->_data = array(
00090 'authors' => array(),
00091 'title' => $article->getTitle(null),
00092 'abstract' => $article->getAbstract(null),
00093 'coverPageAltText' => $article->getCoverPageAltText(null),
00094 'showCoverPage' => $article->getShowCoverPage(null),
00095 'hideCoverPageToc' => $article->getHideCoverPageToc(null),
00096 'hideCoverPageAbstract' => $article->getHideCoverPageAbstract(null),
00097 'originalFileName' => $article->getOriginalFileName(null),
00098 'fileName' => $article->getFileName(null),
00099 'width' => $article->getWidth(null),
00100 'height' => $article->getHeight(null),
00101 'discipline' => $article->getDiscipline(null),
00102 'subjectClass' => $article->getSubjectClass(null),
00103 'subject' => $article->getSubject(null),
00104 'coverageGeo' => $article->getCoverageGeo(null),
00105 'coverageChron' => $article->getCoverageChron(null),
00106 'coverageSample' => $article->getCoverageSample(null),
00107 'type' => $article->getType(null),
00108 'language' => $article->getLanguage(),
00109 'sponsor' => $article->getSponsor(null),
00110 'hideAuthor' => $article->getHideAuthor()
00111 );
00112
00113 $authors = &$article->getAuthors();
00114 for ($i=0, $count=count($authors); $i < $count; $i++) {
00115 array_push(
00116 $this->_data['authors'],
00117 array(
00118 'authorId' => $authors[$i]->getAuthorId(),
00119 'firstName' => $authors[$i]->getFirstName(),
00120 'middleName' => $authors[$i]->getMiddleName(),
00121 'lastName' => $authors[$i]->getLastName(),
00122 'affiliation' => $authors[$i]->getAffiliation(),
00123 'country' => $authors[$i]->getCountry(),
00124 'countryLocalized' => $authors[$i]->getCountryLocalized(),
00125 'email' => $authors[$i]->getEmail(),
00126 'url' => $authors[$i]->getUrl(),
00127 'competingInterests' => $authors[$i]->getCompetingInterests(null),
00128 'biography' => $authors[$i]->getBiography(null)
00129 )
00130 );
00131 if ($authors[$i]->getPrimaryContact()) {
00132 $this->setData('primaryContact', $i);
00133 }
00134 }
00135 }
00136 }
00137
00142 function getLocaleFieldNames() {
00143 return array(
00144 'title', 'abstract', 'coverPageAltText', 'showCoverPage', 'hideCoverPageToc', 'hideCoverPageAbstract', 'originalFileName', 'fileName', 'width', 'height',
00145 'discipline', 'subjectClass', 'subject', 'coverageGeo', 'coverageChron', 'coverageSample', 'type', 'sponsor'
00146 );
00147 }
00148
00152 function display() {
00153 $journal = &Request::getJournal();
00154 $settingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00155 $roleDao = &DAORegistry::getDAO('RoleDAO');
00156 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00157
00158 $templateMgr = &TemplateManager::getManager();
00159 $templateMgr->assign('articleId', isset($this->article)?$this->article->getArticleId():null);
00160 $templateMgr->assign('journalSettings', $settingsDao->getJournalSettings($journal->getJournalId()));
00161 $templateMgr->assign('rolePath', Request::getRequestedPage());
00162 $templateMgr->assign('canViewAuthors', $this->canViewAuthors);
00163
00164 $countryDao =& DAORegistry::getDAO('CountryDAO');
00165 $templateMgr->assign('countries', $countryDao->getCountries());
00166
00167 $templateMgr->assign('helpTopicId','submission.indexingAndMetadata');
00168 if ($this->article) {
00169 $templateMgr->assign_by_ref('section', $sectionDao->getSection($this->article->getSectionId()));
00170 }
00171
00172 if ($this->canEdit) {
00173 import('article.Article');
00174 $hideAuthorOptions = array(
00175 AUTHOR_TOC_DEFAULT => Locale::Translate('editor.article.hideTocAuthorDefault'),
00176 AUTHOR_TOC_HIDE => Locale::Translate('editor.article.hideTocAuthorHide'),
00177 AUTHOR_TOC_SHOW => Locale::Translate('editor.article.hideTocAuthorShow')
00178 );
00179 $templateMgr->assign('hideAuthorOptions', $hideAuthorOptions);
00180 }
00181
00182 parent::display();
00183 }
00184
00185
00189 function readInputData() {
00190 $this->readUserVars(
00191 array(
00192 'articleId',
00193 'authors',
00194 'deletedAuthors',
00195 'primaryContact',
00196 'title',
00197 'abstract',
00198 'coverPageAltText',
00199 'showCoverPage',
00200 'hideCoverPageToc',
00201 'hideCoverPageAbstract',
00202 'originalFileName',
00203 'fileName',
00204 'width',
00205 'height',
00206 'discipline',
00207 'subjectClass',
00208 'subject',
00209 'coverageGeo',
00210 'coverageChron',
00211 'coverageSample',
00212 'type',
00213 'language',
00214 'sponsor',
00215 'hideAuthor'
00216 )
00217 );
00218
00219 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00220 $section = &$sectionDao->getSection($this->article->getSectionId());
00221 if (!$section->getAbstractsNotRequired()) {
00222 $this->addCheck(new FormValidatorLocale($this, 'abstract', 'required', 'author.submit.form.abstractRequired'));
00223 }
00224
00225 }
00226
00231 function execute() {
00232 $articleDao = &DAORegistry::getDAO('ArticleDAO');
00233 $authorDao = &DAORegistry::getDAO('AuthorDAO');
00234 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00235
00236
00237
00238 $article = &$this->article;
00239 $article->setTitle($this->getData('title'), null);
00240
00241 $section = &$sectionDao->getSection($article->getSectionId());
00242 $article->setAbstract($this->getData('abstract'), null);
00243
00244 import('file.PublicFileManager');
00245 $publicFileManager =& new PublicFileManager();
00246 if ($publicFileManager->uploadedFileExists('coverPage')) {
00247 $journal = Request::getJournal();
00248 $originalFileName = $publicFileManager->getUploadedFileName('coverPage');
00249 $newFileName = 'cover_article_' . $this->getData('articleId') . '_' . $this->getFormLocale() . '.' . $publicFileManager->getExtension($originalFileName);
00250 $publicFileManager->uploadJournalFile($journal->getJournalId(), 'coverPage', $newFileName);
00251 $article->setOriginalFileName($publicFileManager->truncateFileName($originalFileName, 127), $this->getFormLocale());
00252 $article->setFileName($newFileName, $this->getFormLocale());
00253
00254
00255 list($width, $height) = getimagesize($publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/' . $newFileName);
00256 $article->setWidth($width, $this->getFormLocale());
00257 $article->setHeight($height, $this->getFormLocale());
00258 }
00259
00260 $article->setCoverPageAltText($this->getData('coverPageAltText'), null);
00261 $showCoverPage = array_map(create_function('$arrayElement', 'return (int)$arrayElement;'), (array) $this->getData('showCoverPage'));
00262 foreach (array_keys($this->getData('coverPageAltText')) as $locale) {
00263 if (!array_key_exists($locale, $showCoverPage)) {
00264 $showCoverPage[$locale] = 0;
00265 }
00266 }
00267 $article->setShowCoverPage($showCoverPage, null);
00268
00269 $hideCoverPageToc = array_map(create_function('$arrayElement', 'return (int)$arrayElement;'), (array) $this->getData('hideCoverPageToc'));
00270 foreach (array_keys($this->getData('coverPageAltText')) as $locale) {
00271 if (!array_key_exists($locale, $hideCoverPageToc)) {
00272 $hideCoverPageToc[$locale] = 0;
00273 }
00274 }
00275 $article->setHideCoverPageToc($hideCoverPageToc, null);
00276
00277 $hideCoverPageAbstract = array_map(create_function('$arrayElement', 'return (int)$arrayElement;'), (array) $this->getData('hideCoverPageAbstract'));
00278 foreach (array_keys($this->getData('coverPageAltText')) as $locale) {
00279 if (!array_key_exists($locale, $hideCoverPageAbstract)) {
00280 $hideCoverPageAbstract[$locale] = 0;
00281 }
00282 }
00283 $article->setHideCoverPageAbstract($hideCoverPageAbstract, null);
00284
00285 $article->setDiscipline($this->getData('discipline'), null);
00286 $article->setSubjectClass($this->getData('subjectClass'), null);
00287 $article->setSubject($this->getData('subject'), null);
00288 $article->setCoverageGeo($this->getData('coverageGeo'), null);
00289 $article->setCoverageChron($this->getData('coverageChron'), null);
00290 $article->setCoverageSample($this->getData('coverageSample'), null);
00291 $article->setType($this->getData('type'), null);
00292 $article->setLanguage($this->getData('language'));
00293 $article->setSponsor($this->getData('sponsor'), null);
00294 $article->setHideAuthor($this->getData('hideAuthor') ? $this->getData('hideAuthor') : 0);
00295
00296
00297 $authors = $this->getData('authors');
00298 for ($i=0, $count=count($authors); $i < $count; $i++) {
00299 if ($authors[$i]['authorId'] > 0) {
00300
00301 $author = &$article->getAuthor($authors[$i]['authorId']);
00302 $isExistingAuthor = true;
00303
00304 } else {
00305
00306 $author = &new Author();
00307 $isExistingAuthor = false;
00308 }
00309
00310 if ($author != null) {
00311 $author->setFirstName($authors[$i]['firstName']);
00312 $author->setMiddleName($authors[$i]['middleName']);
00313 $author->setLastName($authors[$i]['lastName']);
00314 $author->setAffiliation($authors[$i]['affiliation']);
00315 $author->setCountry($authors[$i]['country']);
00316 $author->setEmail($authors[$i]['email']);
00317 $author->setUrl($authors[$i]['url']);
00318 if (array_key_exists('competingInterests', $authors[$i])) {
00319 $author->setCompetingInterests($authors[$i]['competingInterests'], null);
00320 }
00321 $author->setBiography($authors[$i]['biography'], null);
00322 $author->setPrimaryContact($this->getData('primaryContact') == $i ? 1 : 0);
00323 $author->setSequence($authors[$i]['seq']);
00324
00325 if ($isExistingAuthor == false) {
00326 $article->addAuthor($author);
00327 }
00328 }
00329 }
00330
00331
00332 $deletedAuthors = explode(':', $this->getData('deletedAuthors'));
00333 for ($i=0, $count=count($deletedAuthors); $i < $count; $i++) {
00334 $article->removeAuthor($deletedAuthors[$i]);
00335 }
00336
00337
00338 $articleDao->updateArticle($article);
00339
00340
00341 import('search.ArticleSearchIndex');
00342 ArticleSearchIndex::indexArticleMetadata($article);
00343
00344 return $article->getArticleId();
00345 }
00346
00351 function getCanEdit() {
00352 return $this->canEdit;
00353 }
00354 }
00355
00356 ?>