00001 <?php
00002
00015
00016
00017 import('form.Form');
00018
00019 class RegistrationTypeForm extends Form {
00021 var $typeId;
00022
00024 var $validAccessTypes;
00025
00027 var $validCurrencies;
00028
00030 var $registrationOptionCosts;
00031
00033 var $registrationTypeDao;
00034
00039 function RegistrationTypeForm($typeId = null) {
00040 $this->registrationTypeDao =& DAORegistry::getDAO('RegistrationTypeDAO');
00041
00042 $this->validAccessTypes = array (
00043 REGISTRATION_TYPE_ACCESS_ONLINE => __('manager.registrationTypes.access.online'),
00044 REGISTRATION_TYPE_ACCESS_PHYSICAL => __('manager.registrationTypes.access.physical'),
00045 REGISTRATION_TYPE_ACCESS_BOTH => __('manager.registrationTypes.access.both')
00046 );
00047
00048 $currencyDao =& DAORegistry::getDAO('CurrencyDAO');
00049 $currencies =& $currencyDao->getCurrencies();
00050 $this->validCurrencies = array();
00051 while (list(, $currency) = each($currencies)) {
00052 $this->validCurrencies[$currency->getCodeAlpha()] = $currency->getName() . ' (' . $currency->getCodeAlpha() . ')';
00053 }
00054
00055 if (isset($typeId)) {
00056 $this->typeId = (int) $typeId;
00057 $this->registrationOptionCosts = $this->registrationTypeDao->getRegistrationOptionCosts($this->typeId);
00058 } else {
00059 $this->typeId = null;
00060 }
00061
00062 parent::Form('registration/registrationTypeForm.tpl');
00063
00064
00065 $this->addCheck(new FormValidatorLocale($this, 'name', 'required', 'manager.registrationTypes.form.typeNameRequired'));
00066
00067
00068 $this->addCheck(new FormValidator($this, 'cost', 'required', 'manager.registrationTypes.form.costRequired'));
00069 $this->addCheck(new FormValidatorCustom($this, 'cost', 'required', 'manager.registrationTypes.form.costNumeric', create_function('$cost', 'return (is_numeric($cost) && $cost >= 0);')));
00070
00071
00072 $this->addCheck(new FormValidator($this, 'currency', 'required', 'manager.registrationTypes.form.currencyRequired'));
00073 $this->addCheck(new FormValidatorInSet($this, 'currency', 'required', 'manager.registrationTypes.form.currencyValid', array_keys($this->validCurrencies)));
00074
00075
00076 $this->addCheck(new FormValidatorCustom($this, 'openDate', 'required', 'manager.registrationTypes.form.closeBeforeOpen',
00077 create_function('$openDate,$form',
00078 'return ($openDate < $form->getData(\'closeDate\'));'),
00079 array(&$this)));
00080
00081
00082 $this->addCheck(new FormValidator($this, 'access', 'required', 'manager.registrationTypes.form.accessRequired'));
00083 $this->addCheck(new FormValidatorInSet($this, 'access', 'required', 'manager.registrationTypes.form.accessValid', array_keys($this->validAccessTypes)));
00084
00085
00086 $this->addCheck(new FormValidatorInSet($this, 'institutional', 'optional', 'manager.registrationTypes.form.institutionalValid', array('1')));
00087
00088
00089 $this->addCheck(new FormValidatorInSet($this, 'membership', 'optional', 'manager.registrationTypes.form.membershipValid', array('1')));
00090
00091
00092 $this->addCheck(new FormValidatorInSet($this, 'notPublic', 'optional', 'manager.registrationTypes.form.notPublicValid', array('1')));
00093
00094 $this->addCheck(new FormValidatorPost($this));
00095 }
00096
00101 function getLocaleFieldNames() {
00102 return $this->registrationTypeDao->getLocaleFieldNames();
00103 }
00104
00108 function display() {
00109 $templateMgr =& TemplateManager::getManager();
00110 $templateMgr->assign('dateExtentFuture', REGISTRATION_TYPE_YEAR_OFFSET_FUTURE);
00111 $templateMgr->assign('typeId', $this->typeId);
00112 $templateMgr->assign('validCurrencies', $this->validCurrencies);
00113 $templateMgr->assign('validAccessTypes', $this->validAccessTypes);
00114 $templateMgr->assign('registrationOptionCosts', $this->registrationOptionCosts);
00115 $templateMgr->assign('helpTopicId', 'conference.currentConferences.registration');
00116
00117 $schedConf =& Request::getSchedConf();
00118 $registrationOptionDao =& DAORegistry::getDAO('RegistrationOptionDAO');
00119 $registrationOptions =& $registrationOptionDao->getRegistrationOptionsBySchedConfId($schedConf->getId());
00120 $registrationOptionsArray =& $registrationOptions->toArray();
00121 $templateMgr->assign_by_ref('registrationOptions', $registrationOptionsArray);
00122
00123 parent::display();
00124 }
00125
00129 function initData() {
00130 if (isset($this->typeId)) {
00131 $registrationType =& $this->registrationTypeDao->getRegistrationType($this->typeId);
00132
00133 if ($registrationType != null) {
00134 $this->_data = array(
00135 'name' => $registrationType->getName(null),
00136 'description' => $registrationType->getDescription(null),
00137 'cost' => $registrationType->getCost(),
00138 'currency' => $registrationType->getCurrencyCodeAlpha(),
00139 'openDate' => $registrationType->getOpeningDate(),
00140 'closeDate' => $registrationType->getClosingDate(),
00141 'expiryDate' => $registrationType->getExpiryDate(),
00142 'access' => $registrationType->getAccess(),
00143 'institutional' => $registrationType->getInstitutional(),
00144 'membership' => $registrationType->getMembership(),
00145 'notPublic' => $registrationType->getPublic()?0:1,
00146 'code' => $registrationType->getCode()
00147 );
00148
00149 } else {
00150 $this->typeId = null;
00151 }
00152 } else {
00153 $this->_data = array(
00154 'notPublic' => 0
00155 );
00156 }
00157 }
00158
00162 function readInputData() {
00163 $this->readUserVars(array('name', 'description', 'cost', 'currency', 'access', 'institutional', 'membership', 'notPublic', 'code', 'registrationOptionCosts'));
00164 $this->_data['openDate'] = Request::getUserDateVar('openDate');
00165 $this->_data['closeDate'] = Request::getUserDateVar('closeDate');
00166 $this->_data['expiryDate'] = Request::getUserVar('expiryDate')?Request::getUserDateVar('expiryDate'):null;
00167 }
00168
00172 function execute() {
00173 $schedConf =& Request::getSchedConf();
00174
00175 if (isset($this->typeId)) {
00176 $registrationType =& $this->registrationTypeDao->getRegistrationType($this->typeId);
00177 }
00178
00179 if (!isset($registrationType)) {
00180 $registrationType = new RegistrationType();
00181 }
00182
00183 $registrationType->setSchedConfId($schedConf->getId());
00184 $registrationType->setName($this->getData('name'), null);
00185 $registrationType->setDescription($this->getData('description'), null);
00186 $registrationType->setCost(round($this->getData('cost'), 2));
00187 $registrationType->setCurrencyCodeAlpha($this->getData('currency'));
00188 $registrationType->setOpeningDate($this->getData('openDate'));
00189 $registrationType->setClosingDate($this->getData('closeDate'));
00190 $registrationType->setExpiryDate($this->getData('expiryDate'));
00191 $registrationType->setAccess($this->getData('access'));
00192 $registrationType->setInstitutional($this->getData('institutional')?1:0);
00193 $registrationType->setMembership($this->getData('membership')?1:0);
00194 $registrationType->setPublic($this->getData('notPublic')?0:1);
00195 $registrationType->setCode($this->getData('code'));
00196
00197
00198 if ($registrationType->getTypeId() != null) {
00199 $this->registrationTypeDao->updateRegistrationType($registrationType);
00200 $this->registrationTypeDao->deleteRegistrationOptionCosts($registrationType->getTypeId());
00201 } else {
00202 $registrationType->setSequence(REALLY_BIG_NUMBER);
00203 $this->registrationTypeDao->insertRegistrationType($registrationType);
00204
00205
00206 $this->registrationTypeDao->resequenceRegistrationTypes($registrationType->getSchedConfId());
00207 }
00208
00209 $registrationOptionCosts = (array) $this->getData('registrationOptionCosts');
00210 foreach ($registrationOptionCosts as $optionId => $cost) {
00211 $this->registrationTypeDao->insertRegistrationOptionCost($registrationType->getTypeId(), $optionId, $cost);
00212 }
00213 }
00214 }
00215
00216 ?>