PHP_SMART_HOME_V3/app/class/RoomManager.php

32 lines
718 B
PHP
Raw Normal View History

2019-08-23 11:39:42 +00:00
<?php
class RoomManager{
public static $rooms;
2019-11-27 16:05:49 +00:00
function getDefaultRoomId() {
$defaultRoom = Db::loadOne("SELECT id FROM rooms WHERE default = 1");
return $defaultRoom['id'];
}
2019-08-23 11:39:42 +00:00
function getAllRooms () {
$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;
}
public function create ($name) {
$room = array (
'name' => $name,
);
try {
Db::add ('rooms', $room);
} catch(PDOException $error) {
echo $error->getMessage();
die();
}
}
public function delete ($roomId) {
Db::command ('DELETE FROM rooms WHERE room_id=?', array ($roomId));
}
}
?>