PHP_SMART_HOME_V3/app/models/RoomManager.php

32 lines
758 B
PHP
Raw Normal View History

2019-08-23 13:39:42 +02:00
<?php
class RoomManager{
public static $rooms;
2020-04-21 19:44:30 +02:00
static function getDefaultRoomId() {
2019-11-28 14:34:32 +01:00
$defaultRoom = Db::loadOne("SELECT room_id FROM rooms WHERE 'default' = 1");
return $defaultRoom['room_id'];
2019-11-27 17:05:49 +01:00
}
2020-04-21 19:44:30 +02:00
static function getAllRooms () {
2019-08-23 13:39:42 +02:00
$allRoom = Db::loadAll ("SELECT rooms.*, COUNT(devices.device_id) as device_count FROM rooms LEFT JOIN devices ON (devices.room_id=rooms.room_id) GROUP BY rooms.room_id");
return $allRoom;
}
2020-04-21 19:44:30 +02:00
public static function create ($name) {
2019-08-23 13:39:42 +02:00
$room = array (
'name' => $name,
);
try {
Db::add ('rooms', $room);
} catch(PDOException $error) {
echo $error->getMessage();
die();
}
}
2020-04-21 19:44:30 +02:00
public static function delete ($roomId) {
2019-08-23 13:39:42 +02:00
Db::command ('DELETE FROM rooms WHERE room_id=?', array ($roomId));
}
}
?>