oCfg = $oCfg;
}
/**
* Insert or update a room in the database
* param $or (rsRoom) Room to store in the database
* return (int) The UID of the booking, or -1 in case of a failure.
* Call getLastError() to get more information about the error.
*/
/** public function write(rsRoom $or) {
// Only administrators are allowed to create and alter rooms
if(!$this->oCfg->userIsAdmin()) {
// TODO throw exception
setLastError(RS_ERROR_ACCESS_DENIED);
return -1;
}
$strWhere = "";
$strLog = "";
// Update or insert?
if($or->getUid() == null) {
// No UID yet, insert new room
$strLog = sprintf("Raum „%s“ angelegt", $or->getName());
} else {
$strWhere = "rsr_uid = ".qp(intval($or->getUid()));
$strLog = sprintf("Raum „%s“ geändert", $or->getName());
}
$aPut["rsr_name"] = $or->getName();
db_store("rooms", $aPut, $strWhere == "" ? null : $strWhere);
$hQuery = db_query("SELECT currval('roomschedule_rooms_rsr_uid_seq') ".
"FROM roomschedule_rooms;");
$nNewUid = pg_fetch_result($hQuery, 0, "currval");
rrInsertLog($strLog);
// Return new UID
return $nNewUid;
}
*/
/**
* Delete a room from the database
* param $nUid (int) Unique ID of the room
* return (bool) true on success, otherwise false.
* Call getLastError() to get more information about the error.
*/
/* public function delete($nUid) {
// Only administrators are allowed to delete rooms
if(!$this->oCfg->userIsAdmin()) {
// TODO throw exception
setLastError(RS_ERROR_ACCESS_DENIED);
return false;
}
// Delete it from the database
$strRoom = $this->getRoomName($nUid);
if(!db_query("DELETE FROM roomschedule_rooms WHERE rsr_uid = $1;",
intval($nUid))) {
// TODO throw exception
setLastError(RS_ERROR_SQL);
return false;
} else {
rsInsertLog(sprintf("Raum „%s“ gelöscht", $strRoom));
return true;
}
}
*/
/**
* Get a room by its OID. Returns null if the room was not found.
* @param $nOid (integer) The OID of the room
* @return mod_roomReservationRoom
*/
static function getRoomByOid($nOid) {
$o = null;
$h = db_query("SELECT * FROM rooms WHERE oid = $1;", $nOid);
if(pg_num_rows($h) > 0) {
$arResult = pg_fetch_array($h);
$o = new mod_roomReservationRoom($arResult["name"],
$arResult["room_no"], $arResult["floor"], $arResult["building"],
$arResult["location"]);
}
return $o;
}
/**
* Get a room by its name. Returns null if the room was not found.
* @param $sName (string) The name of the room
* @return mod_roomReservationRoom
*/
static function getRoomByName($sName) {
$o = null;
$h = db_query("SELECT * FROM rooms WHERE name = $1;", $sName);
if(pg_num_rows($h) > 0) {
$arResult = pg_fetch_array($h);
$o = new mod_roomReservationRoom($arResult["name"],
$arResult["room_no"], $arResult["floor"], $arResult["building"],
$arResult["location"]);
}
return $o;
}
/**
* Get all rooms from the database
* @return array of mod_roomReservationRoom
*/
static function getRooms() {
$aoReturn = array();
$hQuery = db_query("SELECT * FROM rooms ORDER BY name;");
while($arResult = pg_fetch_array($hQuery)) {
$aoReturn[] = new mod_roomReservationRoom($arResult["name"],
$arResult["room_no"], $arResult["floor"], $arResult["building"],
$arResult["location"]);
}
return $aoReturn;
}
}
?>