PHP_SMART_HOME_V3/www/app/views/Automation.php

67 lines
2.2 KiB
PHP
Raw Normal View History

2019-08-23 11:39:42 +00:00
<?php
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()){
2020-04-28 09:52:14 +00:00
header('Location: ' . BASEURL . '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,
];
}
2020-02-21 13:25:25 +00:00
//TODO: Transaltion add
$executionTime = 'never';
if ($automationData['execution_time'] != '0000-00-00 00:00:00') {
$executionTime = date(DATEFORMAT,strtotime($automationData['execution_time']));
}
2019-08-23 11:39:42 +00:00
$automations[$automationData['automation_id']] = [
2019-10-08 16:23:57 +00:00
'name' => $automationData['name'],
2020-02-21 13:25:25 +00:00
'owner_name' => $userManager->getUserId($automationData['owner_id'])['username'],
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'],
2020-02-21 13:25:25 +00:00
'execution_time' => $executionTime,
2019-08-23 11:39:42 +00:00
];
}
$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);
2020-02-21 13:25:25 +00:00
$template->prepare('debugMod', DEBUGMOD);
2019-08-23 11:39:42 +00:00
$template->prepare('title', 'Automation');
2019-10-11 12:12:05 +00:00
$template->prepare('langMng', $langMng);
2020-01-17 07:12:40 +00:00
$template->prepare('userManager', $userManager);
2019-08-23 11:39:42 +00:00
$template->prepare('automations', $automations);
$template->prepare('subDevices', $approvedSubDevices);
$template->render();
}
}