2020-05-15 20:45:31 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-22 15:59:45 +00:00
|
|
|
class RoomsApi extends ApiController
|
|
|
|
{
|
2020-10-31 20:37:29 +00:00
|
|
|
|
|
|
|
public function default()
|
2020-10-22 15:59:45 +00:00
|
|
|
{
|
2020-10-22 14:42:49 +00:00
|
|
|
//$this->requireAuth();
|
2020-05-16 20:11:20 +00:00
|
|
|
$response = [];
|
|
|
|
$roomIds = [];
|
|
|
|
$roomsData = RoomManager::getRoomsDefault();
|
2020-10-31 20:37:29 +00:00
|
|
|
|
2020-05-16 20:11:20 +00:00
|
|
|
foreach ($roomsData as $roomKey => $room) {
|
|
|
|
$roomIds[] = $room['room_id'];
|
|
|
|
}
|
2020-10-31 20:37:29 +00:00
|
|
|
|
2020-10-22 14:42:49 +00:00
|
|
|
//Translation Of Numeric Walues
|
2020-05-16 20:11:20 +00:00
|
|
|
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
|
2020-10-22 14:42:49 +00:00
|
|
|
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
|
|
|
|
foreach ($subDevice as $key => $value) {
|
2020-10-25 10:51:44 +00:00
|
|
|
$type = null;
|
2020-10-22 14:42:49 +00:00
|
|
|
if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) {
|
2020-10-25 10:51:44 +00:00
|
|
|
$type = $subDevicesData[$subDeviceKey][$key]['type'];
|
|
|
|
} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) {
|
|
|
|
$type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'];
|
|
|
|
} else {
|
|
|
|
continue;
|
2020-10-22 14:42:49 +00:00
|
|
|
}
|
2020-10-31 20:37:29 +00:00
|
|
|
|
2020-10-25 10:51:44 +00:00
|
|
|
$cammelCaseClass = "";
|
|
|
|
foreach (explode('-', $type) as $word) {
|
|
|
|
$cammelCaseClass .= ucfirst($word);
|
|
|
|
}
|
|
|
|
if (!class_exists($cammelCaseClass)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$deviceClass = new $cammelCaseClass;
|
|
|
|
if (!method_exists($deviceClass, 'translate')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']);
|
2020-10-22 14:42:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-31 20:37:29 +00:00
|
|
|
|
2020-05-16 20:11:20 +00:00
|
|
|
foreach ($roomsData as $roomKey => $roomData) {
|
2020-07-20 11:08:17 +00:00
|
|
|
if ($roomData['device_count'] == 0) continue;
|
|
|
|
$response[] = [
|
|
|
|
'room_id' => $roomData['room_id'],
|
|
|
|
'name' => $roomData['name'],
|
|
|
|
'widgets' => isset($subDevicesData[$roomData['room_id']]) ? $subDevicesData[$roomData['room_id']] : [],
|
|
|
|
];
|
2020-05-15 20:45:31 +00:00
|
|
|
}
|
2020-05-16 20:11:20 +00:00
|
|
|
$this->response($response);
|
2020-05-15 20:45:31 +00:00
|
|
|
}
|
2020-10-31 20:37:29 +00:00
|
|
|
|
2020-10-22 15:59:45 +00:00
|
|
|
public function update($roomId)
|
|
|
|
{
|
2020-05-24 17:35:19 +00:00
|
|
|
//$this->requireAuth();
|
2020-10-31 20:37:29 +00:00
|
|
|
|
2020-05-24 17:44:58 +00:00
|
|
|
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds([$roomId]);
|
|
|
|
$this->response($subDevicesData);
|
2020-05-24 17:35:19 +00:00
|
|
|
}
|
2020-05-15 20:45:31 +00:00
|
|
|
}
|