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 /** Simple class for creating, editing and deleting rooms */
35 class mod_roomReservationRoomsManager {
36 /** (mod_roomReservationConfig) Reference to the configuration */
41 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
42 * configuration object
43 * @return rmRoomsManager
45 public function __construct(mod_roomReservationConfig &$oCfg) {
50 * Get a room by its OID. Returns <tt>null</tt> if the room was not found.
51 * @param $nOid (integer) The OID of the room
52 * @return mod_roomReservationRoom
54 static function getRoomByOid($nOid) {
56 $h = db_query("SELECT * FROM rooms WHERE oid = $1;", $nOid);
57 if(pg_num_rows($h) > 0) {
58 $arResult = pg_fetch_array($h);
59 $o = new mod_roomReservationRoom($arResult["name"],
60 $arResult["room_no"], $arResult["floor"], $arResult["building"],
61 $arResult["location"]);
67 * Get a room by its name. Returns <tt>null</tt> if the room was not found.
68 * @param $sName (string) The name of the room
69 * @return mod_roomReservationRoom
71 static function getRoomByName($sName) {
73 $h = db_query("SELECT * FROM rooms WHERE name = $1;", $sName);
74 if(pg_num_rows($h) > 0) {
75 $arResult = pg_fetch_array($h);
76 $o = new mod_roomReservationRoom($arResult["name"],
77 $arResult["room_no"], $arResult["floor"], $arResult["building"],
78 $arResult["location"]);
84 * Get all rooms from the database
85 * @return array of mod_roomReservationRoom
87 static function getRooms() {
89 $hQuery = db_query("SELECT * FROM rooms ORDER BY name;");
90 while($arResult = pg_fetch_array($hQuery)) {
91 $aoReturn[] = new mod_roomReservationRoom($arResult["name"],
92 $arResult["room_no"], $arResult["floor"], $arResult["building"],
93 $arResult["location"]);