00001 <?php
00002
00015
00016
00017 import('form.Form');
00018
00019 class MetadataForm extends Form {
00021 var $paper;
00022
00024 var $canEdit;
00025
00027 var $canViewAuthors;
00028
00032 function MetadataForm($paper) {
00033 $roleDao =& DAORegistry::getDAO('RoleDAO');
00034
00035 $schedConf =& Request::getSchedConf();
00036 $user =& Request::getUser();
00037 $roleId = $roleDao->getRoleIdFromPath(Request::getRequestedPage());
00038
00039
00040 $this->canEdit = false;
00041 if ($roleId != null && ($roleId == ROLE_ID_DIRECTOR || $roleId == ROLE_ID_TRACK_DIRECTOR)) {
00042 $this->canEdit = true;
00043 }
00044
00045
00046 if ($roleId == ROLE_ID_AUTHOR) {
00047 if(AuthorAction::mayEditPaper($paper)) {
00048 $this->canEdit = true;
00049 }
00050 }
00051
00052 if ($this->canEdit) {
00053 parent::Form('submission/metadata/metadataEdit.tpl');
00054 $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'author.submit.form.titleRequired'));
00055 $this->addCheck(new FormValidatorArray($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', array('firstName', 'lastName')));
00056 $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', create_function('$email, $regExp', 'return String::regexp_match($regExp, $email);'), array(ValidatorEmail::getRegexp()), false, array('email')));
00057 $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'user.profile.form.urlInvalid', create_function('$url, $regExp', 'return empty($url) ? true : String::regexp_match($regExp, $url);'), array(ValidatorUrl::getRegexp()), false, array('url')));
00058 } else {
00059 parent::Form('submission/metadata/metadataView.tpl');
00060 }
00061
00062
00063 $this->canViewAuthors = true;
00064 if ($roleId != null && $roleId == ROLE_ID_REVIEWER) {
00065 $this->canViewAuthors = false;
00066 }
00067
00068 $this->paper = $paper;
00069
00070 $this->addCheck(new FormValidatorPost($this));
00071 }
00072
00076 function initData() {
00077 if (isset($this->paper)) {
00078 $paper =& $this->paper;
00079 $this->_data = array(
00080 'authors' => array(),
00081 'title' => $paper->getTitle(null),
00082 'abstract' => $paper->getAbstract(null),
00083 'discipline' => $paper->getDiscipline(null),
00084 'subjectClass' => $paper->getSubjectClass(null),
00085 'subject' => $paper->getSubject(null),
00086 'coverageGeo' => $paper->getCoverageGeo(null),
00087 'coverageChron' => $paper->getCoverageChron(null),
00088 'coverageSample' => $paper->getCoverageSample(null),
00089 'type' => $paper->getType(null),
00090 'language' => $paper->getLanguage(),
00091 'sponsor' => $paper->getSponsor(null),
00092 'citations' => $paper->getCitations()
00093 );
00094
00095 $authors =& $paper->getAuthors();
00096 for ($i=0, $count=count($authors); $i < $count; $i++) {
00097 array_push(
00098 $this->_data['authors'],
00099 array(
00100 'authorId' => $authors[$i]->getId(),
00101 'firstName' => $authors[$i]->getFirstName(),
00102 'middleName' => $authors[$i]->getMiddleName(),
00103 'lastName' => $authors[$i]->getLastName(),
00104 'affiliation' => $authors[$i]->getAffiliation(),
00105 'country' => $authors[$i]->getCountry(),
00106 'countryLocalized' => $authors[$i]->getCountryLocalized(),
00107 'email' => $authors[$i]->getEmail(),
00108 'url' => $authors[$i]->getUrl(),
00109 'biography' => $authors[$i]->getBiography(null)
00110 )
00111 );
00112 if ($authors[$i]->getPrimaryContact()) {
00113 $this->setData('primaryContact', $i);
00114 }
00115 }
00116 }
00117 }
00118
00123 function getLocaleFieldNames() {
00124 return array('title', 'abstract', 'subjectClass', 'subject', 'coverageGeo', 'coverageChron', 'coverageSample', 'type', 'sponsor', 'citations');
00125 }
00126
00130 function display() {
00131 $schedConf =& Request::getSchedConf();
00132 $roleDao =& DAORegistry::getDAO('RoleDAO');
00133 $trackDao =& DAORegistry::getDAO('TrackDAO');
00134
00135 AppLocale::requireComponents(array(LOCALE_COMPONENT_OCS_DIRECTOR));
00136
00137 $templateMgr =& TemplateManager::getManager();
00138 $templateMgr->assign('paperId', isset($this->paper)?$this->paper->getPaperId():null);
00139 $templateMgr->assign('rolePath', Request::getRequestedPage());
00140 $templateMgr->assign('canViewAuthors', $this->canViewAuthors);
00141
00142 $countryDao =& DAORegistry::getDAO('CountryDAO');
00143 $templateMgr->assign('countries', $countryDao->getCountries());
00144
00145 $templateMgr->assign('helpTopicId','submission.indexingMetadata');
00146 if ($this->paper) {
00147 $templateMgr->assign_by_ref('track', $trackDao->getTrack($this->paper->getTrackId()));
00148 }
00149
00150 parent::display();
00151 }
00152
00153
00157 function readInputData() {
00158 $this->readUserVars(
00159 array(
00160 'authors',
00161 'deletedAuthors',
00162 'primaryContact',
00163 'title',
00164 'abstract',
00165 'discipline',
00166 'subjectClass',
00167 'subject',
00168 'coverageGeo',
00169 'coverageChron',
00170 'coverageSample',
00171 'type',
00172 'language',
00173 'sponsor',
00174 'citations'
00175 )
00176 );
00177 }
00178
00183 function execute() {
00184 $paperDao =& DAORegistry::getDAO('PaperDAO');
00185 $authorDao =& DAORegistry::getDAO('AuthorDAO');
00186 $trackDao =& DAORegistry::getDAO('TrackDAO');
00187
00188
00189
00190 $paper =& $this->paper;
00191 $paper->setTitle($this->getData('title'), null);
00192
00193 $track =& $trackDao->getTrack($paper->getTrackId());
00194 $paper->setAbstract($this->getData('abstract'), null);
00195
00196 $paper->setDiscipline($this->getData('discipline'), null);
00197 $paper->setSubjectClass($this->getData('subjectClass'), null);
00198 $paper->setSubject($this->getData('subject'), null);
00199 $paper->setCoverageGeo($this->getData('coverageGeo'), null);
00200 $paper->setCoverageChron($this->getData('coverageChron'), null);
00201 $paper->setCoverageSample($this->getData('coverageSample'), null);
00202 $paper->setType($this->getData('type'), null);
00203 $paper->setLanguage($this->getData('language'));
00204 $paper->setSponsor($this->getData('sponsor'), null);
00205 $paper->setCitations($this->getData('citations'));
00206
00207
00208 $authors = $this->getData('authors');
00209 for ($i=0, $count=count($authors); $i < $count; $i++) {
00210 if ($authors[$i]['authorId'] > 0) {
00211
00212 $author =& $paper->getAuthor($authors[$i]['authorId']);
00213 $isExistingAuthor = true;
00214
00215 } else {
00216
00217 if (checkPhpVersion('5.0.0')) {
00218 $author = new Author();
00219 } else {
00220 $author =& new Author();
00221 }
00222 $isExistingAuthor = false;
00223 }
00224
00225 if ($author != null) {
00226 $author->setFirstName($authors[$i]['firstName']);
00227 $author->setMiddleName($authors[$i]['middleName']);
00228 $author->setLastName($authors[$i]['lastName']);
00229 $author->setAffiliation($authors[$i]['affiliation']);
00230 $author->setCountry($authors[$i]['country']);
00231 $author->setEmail($authors[$i]['email']);
00232 $author->setUrl($authors[$i]['url']);
00233 $author->setBiography($authors[$i]['biography'], null);
00234 $author->setPrimaryContact($this->getData('primaryContact') == $i ? 1 : 0);
00235 $author->setSequence($authors[$i]['seq']);
00236
00237 if ($isExistingAuthor == false) {
00238 $paper->addAuthor($author);
00239 }
00240 unset($author);
00241 }
00242 }
00243
00244
00245 $deletedAuthors = explode(':', $this->getData('deletedAuthors'));
00246 for ($i=0, $count=count($deletedAuthors); $i < $count; $i++) {
00247 $paper->removeAuthor($deletedAuthors[$i]);
00248 }
00249
00250
00251 $paperDao->updatePaper($paper);
00252
00253
00254 import('search.PaperSearchIndex');
00255 PaperSearchIndex::indexPaperMetadata($paper);
00256
00257 return $paper->getId();
00258 }
00259
00264 function getCanEdit() {
00265 return $this->canEdit;
00266 }
00267 }
00268
00269 ?>