db_user migration
[iserv-mod-room-reservation.git] / inc / mod_roomReservationRoomsManager.inc
1 <?php
2 /**
3 * @file mod_roomReservationRoomsManager.inc
4 * Class for the management of rooms
5 * @author Roland Hieber (roland.hieber@wilhelm-gym.net)
6 * @date 28.12.2007
7 *
8 * Copyright © 2007 Roland Hieber
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
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
26 * THE SOFTWARE.
27 */
28
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");
33
34 db_user("roomreservation");
35
36 /** Simple class for creating, editing and deleting rooms */
37 class mod_roomReservationRoomsManager {
38 /** (mod_roomReservationConfig) Reference to the configuration */
39 protected $oCfg;
40
41 /**
42 * Constructor
43 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
44 * configuration object
45 * @return rmRoomsManager
46 */
47 public function __construct(mod_roomReservationConfig &$oCfg) {
48 $this->oCfg = $oCfg;
49 }
50
51 /**
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
55 */
56 static function getRoomByOid($nOid) {
57 $o = null;
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"]);
64 }
65 return $o;
66 }
67
68 /**
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
72 */
73 static function getRoomByName($sName) {
74 $o = null;
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"]);
81 }
82 return $o;
83 }
84
85 /**
86 * Get all rooms from the database
87 * @return array of mod_roomReservationRoom
88 */
89 static function getRooms() {
90 $aoReturn = array();
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"]);
96 }
97 return $aoReturn;
98 }
99 }
100 ?>
This page took 0.048342 seconds and 5 git commands to generate.