2013-12-29 15:08:33 +01:00
|
|
|
<?php
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
2017-12-10 18:56:40 +01:00
|
|
|
use Engelsystem\ValidationResult;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate a name for a room.
|
|
|
|
*
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param string $name The new name
|
|
|
|
* @param int $room_id The room id
|
2017-12-10 18:56:40 +01:00
|
|
|
* @return ValidationResult
|
|
|
|
*/
|
|
|
|
function Room_validate_name($name, $room_id)
|
|
|
|
{
|
|
|
|
$valid = true;
|
|
|
|
if (empty($name)) {
|
|
|
|
$valid = false;
|
|
|
|
}
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-10 18:56:40 +01:00
|
|
|
if (count(DB::select('SELECT RID FROM `Room` WHERE `Name`=? AND NOT `RID`=?', [
|
2017-12-25 23:12:52 +01:00
|
|
|
$name,
|
|
|
|
$room_id
|
|
|
|
])) > 0) {
|
2017-12-10 18:56:40 +01:00
|
|
|
$valid = false;
|
|
|
|
}
|
|
|
|
return new ValidationResult($valid, $name);
|
|
|
|
}
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2016-10-03 18:32:25 +02:00
|
|
|
/**
|
|
|
|
* returns a list of rooms.
|
2017-01-02 15:43:36 +01:00
|
|
|
*
|
2017-01-21 13:58:53 +01:00
|
|
|
* @return array
|
2016-10-03 18:32:25 +02:00
|
|
|
*/
|
2017-12-10 15:02:37 +01:00
|
|
|
function Rooms()
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-12-10 15:02:37 +01:00
|
|
|
return DB::select('SELECT * FROM `Room` ORDER BY `Name`');
|
2016-10-03 18:32:25 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 12:01:19 +01:00
|
|
|
/**
|
|
|
|
* Returns Room id array
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function Room_ids()
|
|
|
|
{
|
|
|
|
$result = DB::select('SELECT `RID` FROM `Room`');
|
|
|
|
return select_array($result, 'RID', 'RID');
|
|
|
|
}
|
|
|
|
|
2013-12-29 15:08:33 +01:00
|
|
|
/**
|
2015-05-14 17:20:46 +02:00
|
|
|
* Delete a room
|
2016-10-03 18:32:25 +02:00
|
|
|
*
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param int $room_id
|
2013-12-29 15:08:33 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Room_delete($room_id)
|
|
|
|
{
|
2017-12-14 20:42:05 +01:00
|
|
|
$room = Room($room_id);
|
2017-12-10 18:56:40 +01:00
|
|
|
DB::delete('DELETE FROM `Room` WHERE `RID` = ?', [
|
|
|
|
$room_id
|
|
|
|
]);
|
2017-12-14 20:42:05 +01:00
|
|
|
engelsystem_log('Room deleted: ' . $room['Name']);
|
2017-12-10 18:56:40 +01:00
|
|
|
}
|
|
|
|
|
2015-05-14 17:20:46 +02:00
|
|
|
/**
|
|
|
|
* Create a new room
|
|
|
|
*
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param string $name Name of the room
|
|
|
|
* @param string $map_url URL to a map tha can be displayed in an iframe
|
|
|
|
* @param string description Markdown description
|
2017-01-03 03:22:48 +01:00
|
|
|
* @return false|int
|
2015-05-14 17:20:46 +02:00
|
|
|
*/
|
2019-11-27 23:43:21 +01:00
|
|
|
function Room_create($name, $map_url, $description)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-07-23 11:46:54 +02:00
|
|
|
DB::insert('
|
2020-05-13 18:26:32 +02:00
|
|
|
INSERT INTO `Room` (`Name`, `map_url`, `description`)
|
|
|
|
VALUES (?, ?, ?)
|
2017-12-10 18:56:40 +01:00
|
|
|
', [
|
|
|
|
$name,
|
|
|
|
$map_url,
|
|
|
|
$description
|
|
|
|
]);
|
|
|
|
$result = DB::getPdo()->lastInsertId();
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-10 18:56:40 +01:00
|
|
|
engelsystem_log(
|
|
|
|
'Room created: ' . $name
|
|
|
|
. ', map_url: ' . $map_url
|
|
|
|
. ', description: ' . $description
|
2017-01-03 03:22:48 +01:00
|
|
|
);
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-10 18:56:40 +01:00
|
|
|
return $result;
|
|
|
|
}
|
2017-01-21 13:58:53 +01:00
|
|
|
|
2017-12-10 18:56:40 +01:00
|
|
|
/**
|
2019-11-27 23:43:21 +01:00
|
|
|
* Update a room
|
2017-12-10 18:56:40 +01:00
|
|
|
*
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param int $room_id The rooms id
|
|
|
|
* @param string $name Name of the room
|
|
|
|
* @param string $map_url URL to a map tha can be displayed in an iframe
|
|
|
|
* @param string $description Markdown description
|
|
|
|
* @return int
|
2017-12-10 18:56:40 +01:00
|
|
|
*/
|
2019-11-27 23:43:21 +01:00
|
|
|
function Room_update($room_id, $name, $map_url, $description)
|
2017-12-10 18:56:40 +01:00
|
|
|
{
|
|
|
|
$result = DB::update('
|
|
|
|
UPDATE `Room`
|
|
|
|
SET
|
|
|
|
`Name`=?,
|
|
|
|
`map_url`=?,
|
|
|
|
`description`=?
|
|
|
|
WHERE `RID`=?
|
|
|
|
LIMIT 1', [
|
|
|
|
$name,
|
|
|
|
$map_url,
|
|
|
|
$description,
|
|
|
|
$room_id
|
|
|
|
]);
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-10 18:56:40 +01:00
|
|
|
engelsystem_log(
|
2017-12-25 23:12:52 +01:00
|
|
|
'Room updated: ' . $name .
|
|
|
|
', map_url: ' . $map_url .
|
2017-12-10 18:56:40 +01:00
|
|
|
', description: ' . $description
|
|
|
|
);
|
2017-12-25 23:12:52 +01:00
|
|
|
|
2017-12-10 18:56:40 +01:00
|
|
|
return $result;
|
2013-12-29 15:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns room by id.
|
|
|
|
*
|
2017-12-25 23:12:52 +01:00
|
|
|
* @param int $room_id RID
|
2018-01-14 23:07:34 +01:00
|
|
|
* @return array|null
|
2013-12-29 15:08:33 +01:00
|
|
|
*/
|
2017-12-10 15:02:37 +01:00
|
|
|
function Room($room_id)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2018-01-14 23:07:34 +01:00
|
|
|
$room = DB::selectOne('
|
2017-01-03 15:32:12 +01:00
|
|
|
SELECT *
|
|
|
|
FROM `Room`
|
2017-12-10 18:56:40 +01:00
|
|
|
WHERE `RID` = ?', [
|
|
|
|
$room_id
|
|
|
|
]);
|
2018-01-14 23:07:34 +01:00
|
|
|
|
|
|
|
return empty($room) ? null : $room;
|
2013-12-29 15:08:33 +01:00
|
|
|
}
|