00001 <?php
00002
00016
00017
00018 import('scheduler.Room');
00019
00020 class RoomDAO extends DAO {
00026 function &getRoom($roomId) {
00027 $result =& $this->retrieve(
00028 'SELECT * FROM rooms WHERE room_id = ?', $roomId
00029 );
00030
00031 $returner = null;
00032 if ($result->RecordCount() != 0) {
00033 $returner =& $this->_returnRoomFromRow($result->GetRowAssoc(false));
00034 }
00035 $result->Close();
00036 return $returner;
00037 }
00038
00044 function getRoomBuildingId($roomId) {
00045 $result =& $this->retrieve(
00046 'SELECT building_id FROM rooms WHERE room_id = ?', $roomId
00047 );
00048
00049 return isset($result->fields[0]) ? $result->fields[0] : 0;
00050 }
00051
00057 function getRoomSchedConfId($roomId) {
00058 $result =& $this->retrieve(
00059 'SELECT b.sched_conf_id FROM rooms r LEFT JOIN buildings b ON (r.building_id = b.building_id) WHERE r.room_id = ?', $roomId
00060 );
00061
00062 return isset($result->fields[0]) ? $result->fields[0] : 0;
00063 }
00064
00069 function getLocaleFieldNames() {
00070 return array('name', 'abbrev', 'description');
00071 }
00072
00078 function &_returnRoomFromRow(&$row) {
00079 $room = new Room();
00080 $room->setId($row['room_id']);
00081 $room->setBuildingId($row['building_id']);
00082 $this->getDataObjectSettings('room_settings', 'room_id', $row['room_id'], $room);
00083
00084 return $room;
00085 }
00086
00091 function updateLocaleFields(&$room) {
00092 $this->updateDataObjectSettings('room_settings', $room, array(
00093 'room_id' => $room->getId()
00094 ));
00095 }
00096
00102 function insertRoom(&$room) {
00103 $this->update(
00104 sprintf('INSERT INTO rooms
00105 (building_id)
00106 VALUES
00107 (?)'),
00108 array(
00109 $room->getBuildingId()
00110 )
00111 );
00112 $room->setId($this->getInsertRoomId());
00113 $this->updateLocaleFields($room);
00114 return $room->getId();
00115 }
00116
00122 function updateRoom(&$room) {
00123 $returner = $this->update(
00124 sprintf('UPDATE rooms
00125 SET
00126 building_id = ?
00127 WHERE room_id = ?'),
00128 array(
00129 $room->getBuildingId(),
00130 $room->getId()
00131 )
00132 );
00133 $this->updateLocaleFields($room);
00134 return $returner;
00135 }
00136
00142 function deleteRoom($room) {
00143 return $this->deleteRoomById($room->getId());
00144 }
00145
00151 function deleteRoomById($roomId) {
00152 $this->update('DELETE FROM room_settings WHERE room_id = ?', $roomId);
00153 $ret = $this->update('DELETE FROM rooms WHERE room_id = ?', $roomId);
00154 return $ret;
00155 }
00156
00161 function deleteRoomsByBuildingId($buildingId) {
00162 $rooms =& $this->getRoomsByBuildingId($buildingId);
00163 while (($room =& $rooms->next())) {
00164 $this->deleteRoom($room);
00165 unset($room);
00166 }
00167 }
00168
00174 function &getRoomsByBuildingId($buildingId, $rangeInfo = null) {
00175 $result =& $this->retrieveRange(
00176 'SELECT * FROM rooms WHERE building_id = ? ORDER BY building_id',
00177 $buildingId,
00178 $rangeInfo
00179 );
00180
00181 $returner = new DAOResultFactory($result, $this, '_returnRoomFromRow');
00182 return $returner;
00183 }
00184
00189 function getInsertRoomId() {
00190 return $this->getInsertId('rooms', 'room_id');
00191 }
00192 }
00193
00194 ?>