summaryrefslogtreecommitdiff
path: root/includes/pages/admin_rooms.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-12-10 18:56:40 +0100
committermsquare <msquare@notrademark.de>2017-12-10 18:56:40 +0100
commitafb77d22ba35dfbee74bbbee95626d55edef8898 (patch)
treed8d35dc5a7848276f83bcab3d1a792e7fb2e1b66 /includes/pages/admin_rooms.php
parentaae8c77ed1a7b0d323f1d32c71b5fd12ff15d4bf (diff)
move room db queries to model
Diffstat (limited to 'includes/pages/admin_rooms.php')
-rw-r--r--includes/pages/admin_rooms.php58
1 files changed, 10 insertions, 48 deletions
diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php
index c5b7b610..55b52cd9 100644
--- a/includes/pages/admin_rooms.php
+++ b/includes/pages/admin_rooms.php
@@ -1,7 +1,4 @@
<?php
-
-use Engelsystem\Database\DB;
-
/**
* @return string
*/
@@ -15,7 +12,7 @@ function admin_rooms_title()
*/
function admin_rooms()
{
- $rooms_source = DB::select('SELECT * FROM `Room` ORDER BY `Name`');
+ $rooms_source = Rooms();
$rooms = [];
$request = request();
@@ -40,7 +37,7 @@ function admin_rooms()
$description = null;
$room_id = 0;
- $angeltypes_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
+ $angeltypes_source = AngelTypes();
$angeltypes = [];
$angeltypes_count = [];
foreach ($angeltypes_source as $angeltype) {
@@ -60,10 +57,7 @@ function admin_rooms()
$map_url = $room['map_url'];
$description = $room['description'];
- $needed_angeltypes = DB::select(
- 'SELECT `angel_type_id`, `count` FROM `NeededAngelTypes` WHERE `room_id`=?',
- [$room_id]
- );
+ $needed_angeltypes = NeededAngelTypes_by_room($room_id);
foreach ($needed_angeltypes as $needed_angeltype) {
$angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
}
@@ -74,16 +68,12 @@ function admin_rooms()
$valid = true;
if ($request->has('name') && strlen(strip_request_item('name')) > 0) {
- $name = strip_request_item('name');
- if (
- isset($room)
- && count(DB::select(
- 'SELECT RID FROM `Room` WHERE `Name`=? AND NOT `RID`=?',
- [$name, $room_id]
- )) > 0
- ) {
+ $result = Room_validate_name(strip_request_item('name'), $room_id);
+ if(!$result->isValid()) {
$valid = false;
$msg .= error(_('This name is already in use.'), true);
+ } else {
+ $name = $result->getValue();
}
} else {
$valid = false;
@@ -116,38 +106,10 @@ function admin_rooms()
}
if ($valid) {
- if (!empty($room_id)) {
- DB::update('
- UPDATE `Room`
- SET
- `Name`=?,
- `from_frab`=?,
- `map_url`=?,
- `description`=?
- WHERE `RID`=?
- LIMIT 1
- ', [
- $name,
- (int) $from_frab,
- $map_url,
- $description,
- $room_id,
- ]);
- engelsystem_log(
- 'Room updated: ' . $name
- . ', frab import: ' . ($from_frab ? 'Yes' : '')
- . ', map_url: ' . $map_url
- . ', description: ' . $description
- );
- } else {
+ if (empty($room_id)) {
$room_id = Room_create($name, $from_frab, $map_url, $description);
-
- engelsystem_log(
- 'Room created: ' . $name
- . ', frab import: ' . ($from_frab ? 'Yes' : '')
- . ', map_url: ' . $map_url
- . ', description: ' . $description
- );
+ } else {
+ Room_update($room_id, $name, $from_frab, $map_url, $description);
}
NeededAngelTypes_delete_by_room($room_id);