classes/scheduler/BuildingDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('scheduler.Building');
00019 
00020 class BuildingDAO extends DAO {
00026    function &getBuilding($buildingId) {
00027       $result =& $this->retrieve(
00028          'SELECT * FROM buildings WHERE building_id = ?', $buildingId
00029       );
00030 
00031       $returner = null;
00032       if ($result->RecordCount() != 0) {
00033          $returner =& $this->_returnBuildingFromRow($result->GetRowAssoc(false));
00034       }
00035       $result->Close();
00036       return $returner;
00037    }
00038 
00044    function getBuildingSchedConfId($buildingId) {
00045       $result =& $this->retrieve(
00046          'SELECT sched_conf_id FROM buildings WHERE building_id = ?', $buildingId
00047       );
00048 
00049       return isset($result->fields[0]) ? $result->fields[0] : 0;
00050    }
00051 
00058    function buildingExistsForSchedConf($buildingId, $schedConfId) {
00059       $result =& $this->retrieve(
00060          'SELECT  COUNT(*)
00061             FROM buildings
00062             WHERE building_id = ?
00063             AND   sched_conf_id = ?',
00064          array(
00065             $buildingId,
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', 'abbrev', 'description');
00083    }
00084 
00090    function &_returnBuildingFromRow(&$row) {
00091       $building = new Building();
00092       $building->setId($row['building_id']);
00093       $building->setSchedConfId($row['sched_conf_id']);
00094       $this->getDataObjectSettings('building_settings', 'building_id', $row['building_id'], $building);
00095 
00096       return $building;
00097    }
00098 
00103    function updateLocaleFields(&$building) {
00104       $this->updateDataObjectSettings('building_settings', $building, array(
00105          'building_id' => $building->getId()
00106       ));
00107    }
00108 
00114    function insertBuilding(&$building) {
00115       $this->update(
00116          sprintf('INSERT INTO buildings
00117             (sched_conf_id)
00118             VALUES
00119             (?)'),
00120          array(
00121             $building->getSchedConfId()
00122          )
00123       );
00124       $building->setId($this->getInsertBuildingId());
00125       $this->updateLocaleFields($building);
00126       return $building->getId();
00127    }
00128 
00134    function updateBuilding(&$building) {
00135       $returner = $this->update(
00136          sprintf('UPDATE buildings
00137             SET
00138                sched_conf_id = ?
00139             WHERE building_id = ?'),
00140          array(
00141             $building->getSchedConfId(),
00142             $building->getId()
00143          )
00144       );
00145       $this->updateLocaleFields($building);
00146       return $returner;
00147    }
00148 
00154    function deleteBuilding($building) {
00155       return $this->deleteBuildingById($building->getId());
00156    }
00157 
00163    function deleteBuildingById($buildingId) {
00164       // Delete dependent rooms first.
00165       $roomDao =& DAORegistry::getDAO('RoomDAO');
00166       $rooms =& $roomDao->deleteRoomsByBuildingId($buildingId);
00167 
00168       $this->update('DELETE FROM building_settings WHERE building_id = ?', $buildingId);
00169       $ret = $this->update('DELETE FROM buildings WHERE building_id = ?', $buildingId);
00170       return $ret;
00171    }
00172 
00177    function deleteBuildingsBySchedConfId($schedConfId) {
00178       $buildings =& $this->getBuildingsBySchedConfId($schedConfId);
00179       while (($building =& $buildings->next())) {
00180          $this->deleteBuilding($building);
00181          unset($building);
00182       }
00183    }
00184 
00190    function &getBuildingsBySchedConfId($schedConfId, $rangeInfo = null) {
00191       $result =& $this->retrieveRange(
00192          'SELECT * FROM buildings WHERE sched_conf_id = ? ORDER BY sched_conf_id',
00193          $schedConfId,
00194          $rangeInfo
00195       );
00196 
00197       $returner = new DAOResultFactory($result, $this, '_returnBuildingFromRow');
00198       return $returner;
00199    }
00200 
00205    function getInsertBuildingId() {
00206       return $this->getInsertId('buildings', 'building_id');
00207    }
00208 }
00209 
00210 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7