removed other obsolete code and task tags, wrapped text to 80 columns
[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 /** Simple class for creating, editing and deleting rooms */
35 class mod_roomReservationRoomsManager {
36 /** (mod_roomReservationConfig) Reference to the configuration */
37 protected $oCfg;
38
39 /**
40 * Constructor
41 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
42 * configuration object
43 * @return rmRoomsManager
44 */
45 public function __construct(mod_roomReservationConfig &$oCfg) {
46 $this->oCfg = $oCfg;
47 }
48
49 /**
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
53 */
54 static function getRoomByOid($nOid) {
55 $o = null;
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"]);
62 }
63 return $o;
64 }
65
66 /**
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
70 */
71 static function getRoomByName($sName) {
72 $o = null;
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"]);
79 }
80 return $o;
81 }
82
83 /**
84 * Get all rooms from the database
85 * @return array of mod_roomReservationRoom
86 */
87 static function getRooms() {
88 $aoReturn = array();
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"]);
94 }
95 return $aoReturn;
96 }
97 }
98 ?>
This page took 0.048322 seconds and 5 git commands to generate.