2013-12-29 15:08:33 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
|
|
|
|
2016-10-03 18:32:25 +02:00
|
|
|
/**
|
|
|
|
* returns a list of rooms.
|
2017-01-02 15:43:36 +01:00
|
|
|
*
|
2016-10-03 18:32:25 +02:00
|
|
|
* @param boolean $show_all returns also hidden rooms when true
|
2017-01-21 13:58:53 +01:00
|
|
|
* @return array
|
2016-10-03 18:32:25 +02:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Rooms($show_all = false)
|
|
|
|
{
|
2017-01-21 13:58:53 +01:00
|
|
|
return DB::select('SELECT * FROM `Room`' . ($show_all ? '' : ' WHERE `show`=\'Y\'') . ' ORDER BY `Name`');
|
2016-10-03 18:32:25 +02:00
|
|
|
}
|
|
|
|
|
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-01-02 03:57:23 +01:00
|
|
|
* @param int $room_id
|
2017-01-21 13:58:53 +01:00
|
|
|
* @return bool
|
2013-12-29 15:08:33 +01:00
|
|
|
*/
|
2017-01-02 03:57:23 +01:00
|
|
|
function Room_delete($room_id)
|
|
|
|
{
|
2017-01-21 13:58:53 +01:00
|
|
|
return DB::delete('DELETE FROM `Room` WHERE `RID` = ?', [$room_id]);
|
2015-05-14 17:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new room
|
|
|
|
*
|
2017-01-21 13:58:53 +01:00
|
|
|
* @param string $name Name of the room
|
|
|
|
* @param boolean $from_frab Is this a frab imported room?
|
|
|
|
* @param boolean $public Is the room visible for angels?
|
|
|
|
* @param int $number Room number
|
2017-01-03 03:22:48 +01:00
|
|
|
* @return false|int
|
2015-05-14 17:20:46 +02:00
|
|
|
*/
|
2017-01-03 03:22:48 +01:00
|
|
|
function Room_create($name, $from_frab, $public, $number = null)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-01-21 13:58:53 +01:00
|
|
|
$result = DB::insert('
|
|
|
|
INSERT INTO `Room` (`Name`, `FromPentabarf`, `show`, `Number`)
|
|
|
|
VALUES (?, ?, ?, ?)
|
|
|
|
',
|
|
|
|
[
|
|
|
|
$name,
|
|
|
|
$from_frab ? 'Y' : '',
|
|
|
|
$public ? 'Y' : '',
|
|
|
|
(int)$number,
|
|
|
|
]
|
2017-01-03 03:22:48 +01:00
|
|
|
);
|
2017-01-21 13:58:53 +01:00
|
|
|
if (!$result) {
|
2017-01-02 03:57:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-21 13:58:53 +01:00
|
|
|
|
|
|
|
return DB::getPdo()->lastInsertId();
|
2013-12-29 15:08:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns room by id.
|
|
|
|
*
|
2017-01-03 15:32:12 +01:00
|
|
|
* @param int $room_id RID
|
|
|
|
* @param bool $show_only
|
2017-01-03 03:22:48 +01:00
|
|
|
* @return array|false
|
2013-12-29 15:08:33 +01:00
|
|
|
*/
|
2017-01-03 15:32:12 +01:00
|
|
|
function Room($room_id, $show_only = true)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-01-21 13:58:53 +01:00
|
|
|
$room_source = DB::select('
|
2017-01-03 15:32:12 +01:00
|
|
|
SELECT *
|
|
|
|
FROM `Room`
|
2017-01-21 13:58:53 +01:00
|
|
|
WHERE `RID` = ?
|
|
|
|
' . ($show_only ? 'AND `show` = \'Y\'' : ''),
|
|
|
|
[$room_id]
|
2017-01-03 15:32:12 +01:00
|
|
|
);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
if (DB::getStm()->errorCode() != '00000') {
|
2017-01-02 03:57:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-21 13:58:53 +01:00
|
|
|
|
|
|
|
if (empty($room_source)) {
|
|
|
|
return null;
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2017-01-21 13:58:53 +01:00
|
|
|
|
|
|
|
return array_shift($room_source);
|
2013-12-29 15:08:33 +01:00
|
|
|
}
|