00001 <?php
00002
00016
00017
00018 import('scheduler.SpecialEvent');
00019
00020 class SpecialEventDAO extends DAO {
00026 function &getSpecialEvent($specialEventId) {
00027 $result =& $this->retrieve(
00028 'SELECT * FROM special_events WHERE special_event_id = ?', $specialEventId
00029 );
00030
00031 $returner = null;
00032 if ($result->RecordCount() != 0) {
00033 $returner =& $this->_returnSpecialEventFromRow($result->GetRowAssoc(false));
00034 }
00035 $result->Close();
00036 return $returner;
00037 }
00038
00044 function getSpecialEventSchedConfId($specialEventId) {
00045 $result =& $this->retrieve(
00046 'SELECT sched_conf_id FROM special_events WHERE special_event_id = ?', $specialEventId
00047 );
00048
00049 return isset($result->fields[0]) ? $result->fields[0] : 0;
00050 }
00051
00058 function specialEventExistsForSchedConf($specialEventId, $schedConfId) {
00059 $result =& $this->retrieve(
00060 'SELECT COUNT(*)
00061 FROM special_events
00062 WHERE special_event_id = ?
00063 AND sched_conf_id = ?',
00064 array(
00065 $specialEventId,
00066 $schedConfId
00067 )
00068 );
00069 $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00070
00071 $result->Close();
00072 unset($result);
00073
00074 return $returner;
00075 }
00076
00081 function getLocaleFieldNames() {
00082 return array('name', 'description');
00083 }
00084
00090 function &_returnSpecialEventFromRow(&$row) {
00091 $specialEvent = new SpecialEvent();
00092 $specialEvent->setId($row['special_event_id']);
00093 $specialEvent->setSchedConfId($row['sched_conf_id']);
00094 $specialEvent->setStartTime($this->datetimeFromDB($row['start_time']));
00095 $specialEvent->setEndTime($this->datetimeFromDB($row['end_time']));
00096 $this->getDataObjectSettings('special_event_settings', 'special_event_id', $row['special_event_id'], $specialEvent);
00097
00098 return $specialEvent;
00099 }
00100
00105 function updateLocaleFields(&$specialEvent) {
00106 $this->updateDataObjectSettings('special_event_settings', $specialEvent, array(
00107 'special_event_id' => $specialEvent->getId()
00108 ));
00109 }
00110
00116 function insertSpecialEvent(&$specialEvent) {
00117 $this->update(
00118 sprintf('INSERT INTO special_events
00119 (sched_conf_id, start_time, end_time)
00120 VALUES
00121 (?, %s, %s)',
00122 $this->datetimeToDB($specialEvent->getStartTime()), $this->datetimeToDB($specialEvent->getEndTime())
00123 ), array(
00124 (int) $specialEvent->getSchedConfId()
00125 )
00126 );
00127 $specialEvent->setId($this->getInsertSpecialEventId());
00128 $this->updateLocaleFields($specialEvent);
00129 return $specialEvent->getId();
00130 }
00131
00137 function updateSpecialEvent(&$specialEvent) {
00138 $returner = $this->update(
00139 sprintf('UPDATE special_events
00140 SET sched_conf_id = ?,
00141 start_time = %s,
00142 end_time = %s
00143 WHERE special_event_id = ?',
00144 $this->datetimeToDB($specialEvent->getStartTime()), $this->datetimeToDB($specialEvent->getEndTime())
00145 ), array(
00146 (int) $specialEvent->getSchedConfId(),
00147 (int) $specialEvent->getId()
00148 )
00149 );
00150 $this->updateLocaleFields($specialEvent);
00151 return $returner;
00152 }
00153
00159 function deleteSpecialEvent($specialEvent) {
00160 return $this->deleteSpecialEventById($specialEvent->getId());
00161 }
00162
00168 function deleteSpecialEventById($specialEventId) {
00169 $this->update('DELETE FROM special_event_settings WHERE special_event_id = ?', $specialEventId);
00170 $ret = $this->update('DELETE FROM special_events WHERE special_event_id = ?', $specialEventId);
00171 return $ret;
00172 }
00173
00178 function deleteSpecialEventsBySchedConfId($schedConfId) {
00179 $specialEvents =& $this->getSpecialEventsBySchedConfId($schedConfId);
00180 while (($specialEvent =& $specialEvents->next())) {
00181 $this->deleteSpecialEvent($specialEvent);
00182 unset($specialEvent);
00183 }
00184 }
00185
00191 function &getSpecialEventsBySchedConfId($schedConfId, $rangeInfo = null) {
00192 $result =& $this->retrieveRange('SELECT * FROM special_events WHERE sched_conf_id = ? ORDER BY start_time, end_time', $schedConfId, $rangeInfo);
00193 $returner = new DAOResultFactory($result, $this, '_returnSpecialEventFromRow');
00194 return $returner;
00195 }
00196
00201 function getInsertSpecialEventId() {
00202 return $this->getInsertId('special_events', 'special_event_id');
00203 }
00204 }
00205
00206 ?>