summaryrefslogtreecommitdiff
path: root/includes/model/Room_model.php
blob: 79536e935faca15579e14a1bec49486df7590b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

use Engelsystem\Database\DB;

/**
 * returns a list of rooms.
 *
 * @return array
 */
function Rooms()
{
    return DB::select('SELECT * FROM `Room` ORDER BY `Name`');
}

/**
 * Returns Room id array
 *
 * @return array
 */
function Room_ids()
{
    $result = DB::select('SELECT `RID` FROM `Room`');
    return select_array($result, 'RID', 'RID');
}

/**
 * Delete a room
 *
 * @param int $room_id
 */
function Room_delete($room_id)
{
    DB::delete('DELETE FROM `Room` WHERE `RID` = ?', [$room_id]);
}

/**
 * Create a new room
 *
 * @param string  $name      Name of the room
 * @param boolean $from_frab Is this a frab imported room?
 * @param string $map_url URL to a map tha can be displayed in an iframe
 * @param description markdown description
 * @return false|int
 */
function Room_create($name, $from_frab, $map_url, $description)
{
    DB::insert('
          INSERT INTO `Room` (`Name`, `from_frab`, `map_url`, `description`)
           VALUES (?, ?, ?, ?)
        ',
        [
            $name,
            (int) $from_frab,
            $map_url,
            $description,
        ]
    );

    return DB::getPdo()->lastInsertId();
}

/**
 * Returns room by id.
 *
 * @param int  $room_id RID
 * @param bool $onlyVisible
 * @return array|false
 */
function Room($room_id)
{
    return DB::selectOne('
        SELECT *
        FROM `Room`
        WHERE `RID` = ?',
        [$room_id]
    );
}