00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class ThesisForm extends Form {
00021
00023 var $thesisId;
00024
00026 var $validStatus;
00027
00029 var $validDegrees;
00030
00031
00036 function ThesisForm($thesisId = null) {
00037 $thesisPlugin = &PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00038 $thesisPlugin->import('Thesis');
00039
00040 $this->validStatus = array (
00041 THESIS_STATUS_INACTIVE => Locale::translate('plugins.generic.thesis.manager.status.inactive'),
00042 THESIS_STATUS_ACTIVE => Locale::translate('plugins.generic.thesis.manager.status.active')
00043 );
00044
00045 $this->validDegrees = array (
00046 THESIS_DEGREE_MASTERS => Locale::translate('plugins.generic.thesis.manager.degree.masters'),
00047 THESIS_DEGREE_DOCTORATE => Locale::translate('plugins.generic.thesis.manager.degree.doctorate')
00048 );
00049
00050 $this->thesisId = isset($thesisId) ? (int) $thesisId : null;
00051
00052 $journal = &Request::getJournal();
00053 parent::Form($thesisPlugin->getTemplatePath() . 'thesisForm.tpl');
00054
00055
00056
00057 $this->addCheck(new FormValidator($this, 'status', 'required', 'plugins.generic.thesis.manager.form.statusRequired'));
00058 $this->addCheck(new FormValidatorInSet($this, 'status', 'required', 'plugins.generic.thesis.manager.form.statusValid', array_keys($this->validStatus)));
00059
00060
00061 $this->addCheck(new FormValidator($this, 'degree', 'required', 'plugins.generic.thesis.manager.form.degreeRequired'));
00062 $this->addCheck(new FormValidatorInSet($this, 'degree', 'required', 'plugins.generic.thesis.manager.form.degreeValid', array_keys($this->validDegrees)));
00063
00064
00065 $this->addCheck(new FormValidator($this, 'department', 'required', 'plugins.generic.thesis.manager.form.departmentRequired'));
00066
00067
00068 $this->addCheck(new FormValidator($this, 'university', 'required', 'plugins.generic.thesis.manager.form.universityRequired'));
00069
00070
00071 $this->addCheck(new FormValidator($this, 'dateApprovedYear', 'required', 'plugins.generic.thesis.manager.form.dateApprovedRequired'));
00072 $this->addCheck(new FormValidatorCustom($this, 'dateApprovedYear', 'required', 'plugins.generic.thesis.manager.form.dateApprovedValid', create_function('$dateApprovedYear', '$minYear = date(\'Y\') + THESIS_APPROVED_YEAR_OFFSET_PAST; $maxYear = date(\'Y\'); return ($dateApprovedYear >= $minYear && $dateApprovedYear <= $maxYear) ? true : false;')));
00073
00074 $this->addCheck(new FormValidator($this, 'dateApprovedMonth', 'required', 'plugins.generic.thesis.manager.form.dateApprovedRequired'));
00075 $this->addCheck(new FormValidatorCustom($this, 'dateApprovedMonth', 'required', 'plugins.generic.thesis.manager.form.dateApprovedValid', create_function('$dateApprovedMonth', 'return ($dateApprovedMonth >= 1 && $dateApprovedMonth <= 12) ? true : false;')));
00076
00077 $this->addCheck(new FormValidator($this, 'dateApprovedDay', 'required', 'plugins.generic.thesis.manager.form.dateApprovedRequired'));
00078 $this->addCheck(new FormValidatorCustom($this, 'dateApprovedDay', 'required', 'plugins.generic.thesis.manager.form.dateApprovedValid', create_function('$dateApprovedDay', 'return ($dateApprovedDay >= 1 && $dateApprovedDay <= 31) ? true : false;')));
00079
00080
00081 $this->addCheck(new FormValidator($this, 'title', 'required', 'plugins.generic.thesis.manager.form.titleRequired'));
00082
00083
00084 $this->addCheck(new FormValidator($this, 'studentFirstName', 'required', 'plugins.generic.thesis.manager.form.studentFirstNameRequired'));
00085
00086
00087 $this->addCheck(new FormValidator($this, 'studentLastName', 'required', 'plugins.generic.thesis.manager.form.studentLastNameRequired'));
00088
00089
00090 $this->addCheck(new FormValidatorEmail($this, 'studentEmail', 'required', 'plugins.generic.thesis.manager.form.studentEmailValid'));
00091
00092
00093 $this->addCheck(new FormValidator($this, 'supervisorFirstName', 'required', 'plugins.generic.thesis.manager.form.supervisorFirstNameRequired'));
00094
00095
00096 $this->addCheck(new FormValidator($this, 'supervisorLastName', 'required', 'plugins.generic.thesis.manager.form.supervisorLastNameRequired'));
00097
00098
00099 $this->addCheck(new FormValidatorEmail($this, 'supervisorEmail', 'required', 'plugins.generic.thesis.manager.form.supervisorEmailValid'));
00100
00101
00102 $this->addCheck(new FormValidator($this, 'abstract', 'required', 'plugins.generic.thesis.manager.form.abstractRequired'));
00103
00104 $this->addCheck(new FormValidatorPost($this));
00105 }
00106
00110 function display() {
00111 $thesisPlugin = &PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00112 $thesisPlugin->import('Thesis');
00113
00114 $templateMgr = &TemplateManager::getManager();
00115 $templateMgr->assign('thesisId', $this->thesisId);
00116 $templateMgr->assign('validStatus', $this->validStatus);
00117 $templateMgr->assign('validDegrees', $this->validDegrees);
00118 $templateMgr->assign('yearOffsetPast', THESIS_APPROVED_YEAR_OFFSET_PAST);
00119
00120 parent::display();
00121 }
00122
00126 function initData() {
00127 if (isset($this->thesisId)) {
00128 $thesisDao = &DAORegistry::getDAO('ThesisDAO');
00129 $thesis = &$thesisDao->getThesis($this->thesisId);
00130
00131 if ($thesis != null) {
00132 $this->_data = array(
00133 'status' => $thesis->getStatus(),
00134 'degree' => $thesis->getDegree(),
00135 'degreeName' => $thesis->getDegreeName(),
00136 'department' => $thesis->getDepartment(),
00137 'university' => $thesis->getUniversity(),
00138 'dateApproved' => $thesis->getDateApproved(),
00139 'title' => $thesis->getTitle(),
00140 'url' => $thesis->getUrl(),
00141 'abstract' => $thesis->getAbstract(),
00142 'comment' => $thesis->getComment(),
00143 'studentFirstName' => $thesis->getStudentFirstName(),
00144 'studentMiddleName' => $thesis->getStudentMiddleName(),
00145 'studentLastName' => $thesis->getStudentLastName(),
00146 'studentEmail' => $thesis->getStudentEmail(),
00147 'studentEmailPublish' => $thesis->getStudentEmailPublish(),
00148 'studentBio' => $thesis->getStudentBio(),
00149 'supervisorFirstName' => $thesis->getSupervisorFirstName(),
00150 'supervisorMiddleName' => $thesis->getSupervisorMiddleName(),
00151 'supervisorLastName' => $thesis->getSupervisorLastName(),
00152 'supervisorEmail' => $thesis->getSupervisorEmail(),
00153 'discipline' => $thesis->getDiscipline(),
00154 'subjectClass' => $thesis->getSubjectClass(),
00155 'keyword' => $thesis->getSubject(),
00156 'coverageGeo' => $thesis->getCoverageGeo(),
00157 'coverageChron' => $thesis->getCoverageChron(),
00158 'coverageSample' => $thesis->getCoverageSample(),
00159 'method' => $thesis->getMethod(),
00160 'language' => $thesis->getLanguage()
00161 );
00162
00163 } else {
00164 $this->thesisId = null;
00165 }
00166 }
00167 }
00168
00172 function readInputData() {
00173 $this->readUserVars(array('status', 'degree', 'degreeName', 'department', 'university', 'dateApprovedYear', 'dateApprovedMonth', 'dateApprovedDay', 'title', 'url', 'abstract', 'comment', 'studentFirstName', 'studentMiddleName', 'studentLastName', 'studentEmail', 'studentEmailPublish', 'studentBio', 'supervisorFirstName', 'supervisorMiddleName', 'supervisorLastName', 'supervisorEmail', 'discipline', 'subjectClass', 'keyword', 'coverageGeo', 'coverageChron', 'coverageSample', 'method', 'language'));
00174 $this->_data['dateApproved'] = $this->_data['dateApprovedYear'] . '-' . $this->_data['dateApprovedMonth'] . '-' . $this->_data['dateApprovedDay'];
00175
00176
00177 if (!empty($this->_data['url'])) {
00178 $this->addCheck(new FormValidatorCustom($this, 'url', 'required', 'plugins.generic.thesis.manager.form.urlPrefixIncluded', create_function('$url', 'return strpos(trim(strtolower($url)), \'http://\') === 0 || strpos(trim(strtolower($url)), \'ftp://\') === 0 ? true : false;'), array()));
00179 }
00180 }
00181
00185 function execute() {
00186 $thesisPlugin = &PluginRegistry::getPlugin('generic', 'ThesisPlugin');
00187 $thesisPlugin->import('Thesis');
00188
00189 $thesisDao = &DAORegistry::getDAO('ThesisDAO');
00190 $journal = &Request::getJournal();
00191 $journalId = $journal->getJournalId();
00192
00193 if (isset($this->thesisId)) {
00194 $thesis = &$thesisDao->getThesis($this->thesisId);
00195 }
00196
00197 if (!isset($thesis)) {
00198 $thesis = &new Thesis();
00199 }
00200
00201 $thesis->setJournalId($journalId);
00202 $thesis->setStatus($this->getData('status'));
00203 $thesis->setDegree($this->getData('degree'));
00204 $thesis->setDegreeName($this->getData('degreeName'));
00205 $thesis->setDepartment($this->getData('department'));
00206 $thesis->setUniversity($this->getData('university'));
00207 $thesis->setTitle($this->getData('title'));
00208 $thesis->setDateApproved($this->getData('dateApprovedYear') . '-' . $this->getData('dateApprovedMonth') . '-' . $this->getData('dateApprovedDay'));
00209 $thesis->setUrl(strtolower($this->getData('url')));
00210 $thesis->setAbstract($this->getData('abstract'));
00211 $thesis->setComment($this->getData('comment'));
00212 $thesis->setStudentFirstName($this->getData('studentFirstName'));
00213 $thesis->setStudentMiddleName($this->getData('studentMiddleName'));
00214 $thesis->setStudentLastName($this->getData('studentLastName'));
00215 $thesis->setStudentEmail($this->getData('studentEmail'));
00216 $thesis->setStudentEmailPublish($this->getData('studentEmailPublish') == null ? 0 : 1);
00217 $thesis->setStudentBio($this->getData('studentBio'));
00218 $thesis->setSupervisorFirstName($this->getData('supervisorFirstName'));
00219 $thesis->setSupervisorMiddleName($this->getData('supervisorMiddleName'));
00220 $thesis->setSupervisorLastName($this->getData('supervisorLastName'));
00221 $thesis->setSupervisorEmail($this->getData('supervisorEmail'));
00222 $thesis->setDiscipline($this->getData('discipline'));
00223 $thesis->setSubjectClass($this->getData('subjectClass'));
00224 $thesis->setSubject($this->getData('keyword'));
00225 $thesis->setCoverageGeo($this->getData('coverageGeo'));
00226 $thesis->setCoverageChron($this->getData('coverageChron'));
00227 $thesis->setCoverageSample($this->getData('coverageSample'));
00228 $thesis->setMethod($this->getData('method'));
00229 $thesis->setLanguage($this->getData('language'));
00230 $thesis->setDateSubmitted(Core::getCurrentDate());
00231
00232
00233 if ($thesis->getThesisId() != null) {
00234 $thesisDao->updateThesis($thesis);
00235 } else {
00236 $thesisDao->insertThesis($thesis);
00237 }
00238 }
00239 }
00240
00241 ?>