removed the row from SQL table log_module
[iserv-mod-room-reservation.git] / includes / 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 * TODO: move into M Class Library
9 * Copyright © 2007 Roland Hieber
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 */
29
30 require_once("db.inc");
31 require_once("mod_room-reservation/functions.inc");
32 require_once("mod_room-reservation/mod_roomReservationRoom.inc");
33 require_once("mod_room-reservation/mod_roomReservationConfig.inc");
34
35 /** Simple class for creating, editing and deleting rooms */
36 class mod_roomReservationRoomsManager {
37 /** (mod_roomReservationConfig) Reference to the configuration */
38 protected $oCfg;
39
40 /**
41 * Constructor
42 * @param $oCfg (reference to mod_roomReservationConfig) Reference to the
43 * configuration object
44 * @return rmRoomsManager
45 */
46 public function __construct(mod_roomReservationConfig &$oCfg) {
47 $this->oCfg = $oCfg;
48 }
49
50 /**
51 * Insert or update a room in the database
52 * param $or (rsRoom) Room to store in the database
53 * return (int) The UID of the booking, or <tt>-1</tt> in case of a failure.
54 * Call getLastError() to get more information about the error.
55 */
56 /** public function write(rsRoom $or) {
57 // Only administrators are allowed to create and alter rooms
58 if(!$this->oCfg->userIsAdmin()) {
59 // TODO throw exception
60 setLastError(RS_ERROR_ACCESS_DENIED);
61 return -1;
62 }
63
64 $strWhere = "";
65 $strLog = "";
66
67 // Update or insert?
68 if($or->getUid() == null) {
69 // No UID yet, insert new room
70 $strLog = sprintf("Raum „%s“ angelegt", $or->getName());
71 } else {
72 $strWhere = "rsr_uid = ".qp(intval($or->getUid()));
73 $strLog = sprintf("Raum „%s“ geändert", $or->getName());
74 }
75
76 $aPut["rsr_name"] = $or->getName();
77 db_store("rooms", $aPut, $strWhere == "" ? null : $strWhere);
78
79 $hQuery = db_query("SELECT currval('roomschedule_rooms_rsr_uid_seq') ".
80 "FROM roomschedule_rooms;");
81 $nNewUid = pg_fetch_result($hQuery, 0, "currval");
82
83 rrInsertLog($strLog);
84
85 // Return new UID
86 return $nNewUid;
87 }
88 */
89 /**
90 * Delete a room from the database
91 * param $nUid (int) Unique ID of the room
92 * return (bool) <tt>true</tt> on success, otherwise <tt>false</tt>.
93 * Call getLastError() to get more information about the error.
94 */
95 /* public function delete($nUid) {
96 // Only administrators are allowed to delete rooms
97 if(!$this->oCfg->userIsAdmin()) {
98 // TODO throw exception
99 setLastError(RS_ERROR_ACCESS_DENIED);
100 return false;
101 }
102 // Delete it from the database
103 $strRoom = $this->getRoomName($nUid);
104 if(!db_query("DELETE FROM roomschedule_rooms WHERE rsr_uid = $1;",
105 intval($nUid))) {
106 // TODO throw exception
107 setLastError(RS_ERROR_SQL);
108 return false;
109 } else {
110 rsInsertLog(sprintf("Raum „%s“ gelöscht", $strRoom));
111 return true;
112 }
113 }
114 */
115
116 /**
117 * Get all rooms from the database
118 * @return array of mod_roomReservationRoom
119 */
120 function getRooms() {
121 $aoReturn = array();
122 $hQuery = db_query("SELECT * FROM rooms ORDER BY name;");
123 while($arResult = pg_fetch_array($hQuery)) {
124 $aoReturn[] = new mod_roomReservationRoom($arResult["name"],
125 $arResult["room_no"], $arResult["floor"], $arResult["building"],
126 $arResult["location"]);
127 }
128 return $aoReturn;
129 }
130 }
131 ?>
This page took 0.05329 seconds and 5 git commands to generate.