PHP_SMART_HOME_V3/app/models/managers/RoomManager.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2020-05-16 15:18:27 +00:00
<?php
class RoomManager{
public static $rooms;
static function getDefaultRoomId() {
2020-10-05 19:12:06 +00:00
$defaultRoom = Db::loadOne("SELECT `room_id` FROM `rooms` WHERE `default` = 1");
2020-05-16 15:18:27 +00:00
return $defaultRoom['room_id'];
}
static function getAllRooms () {
2020-07-20 10:54:07 +00:00
//TODO: ignore Widgets withoud data
2020-05-16 15:18:27 +00: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;
}
static function getRoomsDefault () {
2020-07-20 10:54:07 +00:00
//TODO: ignore Widgets withoud data
2020-07-20 09:07:32 +00:00
$allRoom = Db::loadAll ("SELECT rooms.room_id, rooms.name, COUNT(devices.device_id) as device_count FROM rooms LEFT JOIN devices ON (devices.room_id=rooms.room_id) GROUP BY rooms.room_id;");
2020-05-16 15:18:27 +00:00
return $allRoom;
}
public static function getRoomName ($room_id) {
//TODO: ignore Widgets withoud data
$allRoom = Db::loadAlone ("SELECT name FROM rooms WHERE room_id=?", array ($room_id));
return $allRoom;
}
2020-05-16 15:18:27 +00:00
public static function create ($name) {
$room = array (
'name' => $name,
);
try {
Db::add ('rooms', $room);
} catch(PDOException $error) {
echo $error->getMessage();
die();
}
}
public static function delete ($roomId) {
Db::command ('DELETE FROM rooms WHERE room_id=?', array ($roomId));
}
}
?>