00001 <?php
00002
00017 import('form.Form');
00018
00019 class TimeBlockForm extends Form {
00021 var $timeBlockId;
00022
00027 function TimeBlockForm($timeBlockId = null) {
00028 $this->timeBlockId = isset($timeBlockId) ? (int) $timeBlockId : null;
00029
00030 parent::Form('manager/scheduler/timeBlockForm.tpl');
00031
00032 $this->addCheck(new FormValidatorCustom($this, 'startTime', 'required', 'manager.scheduler.timeBlocks.blockOverlap', array(&$this, 'checkBlockSequence')));
00033 $this->addCheck(new FormValidatorCustom($this, 'endTime', 'required', 'manager.scheduler.timeBlock.timeOrderWrong',
00034 create_function('$endTime,$form',
00035 'return ($endTime >= $form->getData(\'startTime\'));'),
00036 array(&$this)));
00037 $this->addCheck(new FormValidatorPost($this));
00038
00039 }
00040
00041 function checkBlockSequence($aStart) {
00042 $aEnd = $this->getData('endTime');
00043
00044 $timeBlockDao =& DAORegistry::getDAO('TimeBlockDAO');
00045 $schedConf =& Request::getSchedConf();
00046
00047 $allOk = true;
00048
00049 $timeBlocks =& $timeBlockDao->getTimeBlocksBySchedConfId($schedConf->getId());
00050 while ($timeBlock =& $timeBlocks->next()) {
00051 if ($this->timeBlockId != $timeBlock->getId()) {
00052 $bStart = strtotime($timeBlock->getStartTime());
00053 $bEnd = strtotime($timeBlock->getEndTime());
00054 if (
00055 ($bStart >= $aStart && $bStart < $aEnd) ||
00056 ($bEnd > $aStart && $bEnd <= $aEnd) ||
00057 ($aStart >= $bStart && $aStart < $bEnd) ||
00058 ($aEnd > $bStart && $aEnd <= $bEnd)
00059 ) $allOk = false;
00060 }
00061 unset($timeBlock);
00062 }
00063 return $allOk;
00064 }
00065
00075 function timeToSmartyChooser($fromTime, $untilTime) {
00076 return $untilTime - $fromTime + mktime(0, 0, 0);
00077 }
00078
00088 function smartyChooserToTime($smartyTime, $baseTimestamp = 0) {
00089 $time = $smartyTime - mktime(0, 0, 0);
00090 $time = $time % (60 * 60 * 24);
00091 return $time + $baseTimestamp;
00092 }
00093
00098 function getLocaleFieldNames() {
00099 $timeBlockDao =& DAORegistry::getDAO('TimeBlockDAO');
00100 return $timeBlockDao->getLocaleFieldNames();
00101 }
00102
00106 function display() {
00107 $templateMgr =& TemplateManager::getManager();
00108 $templateMgr->assign('timeBlockId', $this->timeBlockId);
00109 $templateMgr->assign('helpTopicId', 'conference.managementPages.timeBlocks');
00110
00111 $schedConf =& Request::getSchedConf();
00112 $templateMgr->assign('schedConfStartDate', $schedConf->getSetting('startDate'));
00113 $templateMgr->assign('schedConfEndDate', $schedConf->getSetting('endDate'));
00114
00115 parent::display();
00116 }
00117
00121 function initData() {
00122 if (isset($this->timeBlockId)) {
00123 $timeBlockDao =& DAORegistry::getDAO('TimeBlockDAO');
00124 $timeBlock =& $timeBlockDao->getTimeBlock($this->timeBlockId);
00125
00126 if ($timeBlock != null) {
00127 $this->_data = array(
00128 'startTime' => $timeBlock->getStartTime(),
00129 'endTime' => $timeBlock->getEndTime()
00130 );
00131
00132 } else {
00133 $this->timeBlockId = null;
00134 }
00135 }
00136 }
00137
00141 function readInputData() {
00142 $startTime = Request::getUserDateVar('startTime');
00143 $endTime = Request::getUserDateVar('endTime', strftime('%d', $startTime), strftime('%m', $startTime), strftime('%Y', $startTime));
00144 $this->setData('startTime', $startTime);
00145 $this->setData('endTime', $endTime);
00146 }
00147
00151 function execute() {
00152 $timeBlockDao =& DAORegistry::getDAO('TimeBlockDAO');
00153 $schedConf =& Request::getSchedConf();
00154
00155 if (isset($this->timeBlockId)) {
00156 $timeBlock =& $timeBlockDao->getTimeBlock($this->timeBlockId);
00157 }
00158
00159 if (!isset($timeBlock)) {
00160 $timeBlock = new TimeBlock();
00161 }
00162
00163 $timeBlock->setSchedConfId($schedConf->getId());
00164 $timeBlock->setStartTime($this->getData('startTime'));
00165 $timeBlock->setEndTime($this->getData('endTime'));
00166
00167
00168 if ($timeBlock->getId() != null) {
00169 $timeBlockDao->updateTimeBlock($timeBlock);
00170 } else {
00171 $timeBlockDao->insertTimeBlock($timeBlock);
00172 }
00173 }
00174 }
00175
00176 ?>