engelsystem/includes/model/Room_model.php

80 lines
1.6 KiB
PHP
Raw Normal View History

2013-12-29 15:08:33 +01:00
<?php
use Engelsystem\Database\DB;
/**
* returns a list of rooms.
2017-01-02 15:43:36 +01:00
*
* @param boolean $show_all returns also hidden rooms when true
* @return array
*/
2017-01-02 03:57:23 +01:00
function Rooms($show_all = false)
{
return DB::select('SELECT * FROM `Room`' . ($show_all ? '' : ' WHERE `show`=\'Y\'') . ' ORDER BY `Name`');
}
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
*
2017-01-02 03:57:23 +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-07-28 18:50:00 +02:00
DB::delete('DELETE FROM `Room` WHERE `RID` = ?', [$room_id]);
2015-05-14 17:20:46 +02:00
}
/**
* Create a new room
*
* @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-07-23 11:46:54 +02:00
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
);
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 $onlyVisible
2017-01-03 03:22:48 +01:00
* @return array|false
2013-12-29 15:08:33 +01:00
*/
function Room($room_id, $onlyVisible = true)
2017-01-02 03:57:23 +01:00
{
return DB::selectOne('
2017-01-03 15:32:12 +01:00
SELECT *
FROM `Room`
WHERE `RID` = ?
' . ($onlyVisible ? 'AND `show` = \'Y\'' : ''),
[$room_id]
2017-01-03 15:32:12 +01:00
);
2013-12-29 15:08:33 +01:00
}