PHP_SMART_HOME_V3/app/views/Automation.php

63 lines
1.9 KiB
PHP
Raw Normal View History

2019-08-23 11:39:42 +00:00
<?php
2019-09-19 12:48:31 +00:00
$files = scandir('app/class/');
2019-08-23 11:39:42 +00:00
$files = array_diff($files, array('.', '..'));
foreach($files as $file) {
2019-09-19 12:48:31 +00:00
include_once 'app/class/'. $file;
2019-08-23 11:39:42 +00:00
}
class Automation extends Template
{
function __construct()
{
global $userManager;
2019-10-11 12:12:05 +00:00
global $langMng;
2019-08-23 11:39:42 +00:00
if (!$userManager->isLogin()){
2019-10-11 14:32:05 +00:00
header('Location: ' . BASEDIR . 'login');
2019-08-23 11:39:42 +00:00
}
$automations = [];
$automationsData = AutomationManager::getAll();
foreach ($automationsData as $automationKey => $automationData) {
2019-08-24 11:07:07 +00:00
$doSomething = [];
foreach (json_decode($automationData['do_something']) as $deviceId => $subDeviceState) {
$subDeviceMasterDeviceData = DeviceManager::getDeviceById($deviceId);
$doSomething[$deviceId] = [
2019-08-25 12:08:00 +00:00
'name' => $subDeviceMasterDeviceData['name'],
2019-08-24 11:07:07 +00:00
'state' => $subDeviceState,
];
}
2019-08-23 11:39:42 +00:00
$automations[$automationData['automation_id']] = [
2019-10-08 16:23:57 +00:00
'name' => $automationData['name'],
2019-08-24 11:07:07 +00:00
'onDays' => json_decode($automationData['on_days']),
2019-08-23 11:39:42 +00:00
'ifSomething' => $automationData['if_something'],
2019-08-24 11:07:07 +00:00
'doSomething' => $doSomething,
2019-08-23 11:39:42 +00:00
'active' => $automationData['active'],
];
}
$approvedSubDevices = [];
$allDevicesData = DeviceManager::getAllDevices();
foreach ($allDevicesData as $deviceKey => $deviceValue) {
if (!$deviceValue['approved']) continue;
$allSubDevicesData = SubDeviceManager::getAllSubDevices($deviceValue['device_id']);
foreach ($allSubDevicesData as $subDeviceKey => $subDeviceValue) {
$approvedSubDevices[$subDeviceValue['subdevice_id']] = [
2019-09-20 17:35:35 +00:00
'name' => $allDevicesData[$deviceKey]['name'],
2019-08-23 11:39:42 +00:00
'type' => $subDeviceValue['type'],
2019-08-24 11:07:07 +00:00
'masterDevice' => $subDeviceValue['device_id'],
2019-08-23 11:39:42 +00:00
];
}
}
$template = new Template('automation');
2019-10-11 14:38:20 +00:00
$template->prepare('baseDir', BASEDIR);
2019-08-23 11:39:42 +00:00
$template->prepare('title', 'Automation');
2019-10-11 12:12:05 +00:00
$template->prepare('langMng', $langMng);
2019-08-23 11:39:42 +00:00
$template->prepare('automations', $automations);
$template->prepare('subDevices', $approvedSubDevices);
$template->render();
}
}