From 1e973d2d8f1dbf89318c517e8d63043809b03b9e Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Fri, 21 Feb 2020 14:25:25 +0100 Subject: [PATCH] Automation Execution Time & Owner --- app/class/AutomationManager.php | 6 ++++-- app/class/UserManager.php | 10 ++++++++++ app/templates/part/automationButton.phtml | 6 ++++++ app/views/Automation.php | 9 ++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/class/AutomationManager.php b/app/class/AutomationManager.php index 95149e7..8b1bdf3 100644 --- a/app/class/AutomationManager.php +++ b/app/class/AutomationManager.php @@ -18,8 +18,10 @@ class AutomationManager{ } public function create ($name, $onDays, $doCode, $ifCode, $automationId = "") { + $userId = UserManager::getUserData('user_id'); $scene = array ( 'name' => $name, + 'owner_id' => $userId, 'on_days' => $onDays, 'if_something' => $ifCode, 'do_something' => $doCode, @@ -55,7 +57,7 @@ class AutomationManager{ $run = false; $restart = false; - if ($automation['active'] == 1 && $automation['locked'] != 1){ + if ($automation['active'] == 1 && $automation['locked'] != 1){ Db::edit('automation', array('locked' => 1), 'WHERE automation_id = ?', array($automation['automation_id'])); if (in_array($dayNameNow, $actionDays)){ if (in_array($onValue['type'], ['sunSet', 'sunRise', 'time','now'])) { @@ -160,7 +162,7 @@ class AutomationManager{ } $logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was executed"); - Db::edit('automation', array('executed' => 1), 'WHERE automation_id = ?', array($automation['automation_id'])); + Db::edit('automation', array('executed' => 1, 'execution_time' => date("Y-m-d H:i:s")), 'WHERE automation_id = ?', array($automation['automation_id'])); } else if ($restart) { $logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was restarted"); Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id'])); diff --git a/app/class/UserManager.php b/app/class/UserManager.php index d19bda1..ee04c23 100644 --- a/app/class/UserManager.php +++ b/app/class/UserManager.php @@ -21,6 +21,16 @@ class UserManager } } + public function getUserId ($userId) { + try { + $user = Db::loadOne ("SELECT * FROM users WHERE user_id = ?", [$userId]); + return $user; + } catch(PDOException $error) { + echo $error->getMessage(); + die(); + } + } + public function getAvatarUrl(){ $email = self::getUserData('email'); return 'https://secure.gravatar.com/avatar/' . md5( strtolower( trim( $email ) ) ); diff --git a/app/templates/part/automationButton.phtml b/app/templates/part/automationButton.phtml index 2947597..002aaab 100644 --- a/app/templates/part/automationButton.phtml +++ b/app/templates/part/automationButton.phtml @@ -50,6 +50,12 @@
+
+ +
+
+ +
diff --git a/app/views/Automation.php b/app/views/Automation.php index 844c25c..abbbad7 100644 --- a/app/views/Automation.php +++ b/app/views/Automation.php @@ -27,12 +27,19 @@ class Automation extends Template 'state' => $subDeviceState, ]; } + //TODO: Transaltion add + $executionTime = 'never'; + if ($automationData['execution_time'] != '0000-00-00 00:00:00') { + $executionTime = date(DATEFORMAT,strtotime($automationData['execution_time'])); + } $automations[$automationData['automation_id']] = [ 'name' => $automationData['name'], + 'owner_name' => $userManager->getUserId($automationData['owner_id'])['username'], 'onDays' => json_decode($automationData['on_days']), 'ifSomething' => $automationData['if_something'], 'doSomething' => $doSomething, 'active' => $automationData['active'], + 'execution_time' => $executionTime, ]; } @@ -52,7 +59,7 @@ class Automation extends Template $template = new Template('automation'); $template->prepare('baseDir', BASEDIR); - $template->prepare('debugMod', DEBUGMOD); + $template->prepare('debugMod', DEBUGMOD); $template->prepare('title', 'Automation'); $template->prepare('langMng', $langMng); $template->prepare('userManager', $userManager);