3 * @file mod_roomReservationRoomsManager.inc
4 * Class for the management of rooms
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
8 * Copyright © 2007 Roland Hieber
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 require_once("db.inc");
30 require_once("mod_room-reservation/functions.inc");
31 require_once("mod_room-reservation/mod_roomReservationRoom.inc");
32 require_once("mod_room-reservation/mod_roomReservationConfig.inc");
34 db_user("roomreservation");
36 /** Simple class for creating, editing and deleting rooms */
37 class mod_roomReservationRoomsManager {
38 /** (mod_roomReservationConfig) Reference to the configuration */
43 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
44 * configuration object
45 * @return rmRoomsManager
47 public function __construct(mod_roomReservationConfig &$oCfg) {
52 * Get a room by its OID. Returns <tt>null</tt> if the room was not found.
53 * @param $nOid (integer) The OID of the room
54 * @return mod_roomReservationRoom
56 static function getRoomByOid($nOid) {
58 $h = db_query("SELECT * FROM rooms WHERE oid = $1;", $nOid);
59 if(pg_num_rows($h) > 0) {
60 $arResult = pg_fetch_array($h);
61 $o = new mod_roomReservationRoom($arResult["name"],
62 $arResult["room_no"], $arResult["floor"], $arResult["building"],
63 $arResult["location"]);
69 * Get a room by its name. Returns <tt>null</tt> if the room was not found.
70 * @param $sName (string) The name of the room
71 * @return mod_roomReservationRoom
73 static function getRoomByName($sName) {
75 $h = db_query("SELECT * FROM rooms WHERE name = $1;", $sName);
76 if(pg_num_rows($h) > 0) {
77 $arResult = pg_fetch_array($h);
78 $o = new mod_roomReservationRoom($arResult["name"],
79 $arResult["room_no"], $arResult["floor"], $arResult["building"],
80 $arResult["location"]);
86 * Get all rooms from the database
87 * @return array of mod_roomReservationRoom
89 static function getRooms() {
91 $hQuery = db_query("SELECT * FROM rooms ORDER BY name;");
92 while($arResult = pg_fetch_array($hQuery)) {
93 $aoReturn[] = new mod_roomReservationRoom($arResult["name"],
94 $arResult["room_no"], $arResult["floor"], $arResult["building"],
95 $arResult["location"]);