Automation Execution Time & Owner
This commit is contained in:
		@@ -18,8 +18,10 @@ class AutomationManager{
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function create ($name, $onDays, $doCode, $ifCode, $automationId = "") {
 | 
						public function create ($name, $onDays, $doCode, $ifCode, $automationId = "") {
 | 
				
			||||||
 | 
							$userId = UserManager::getUserData('user_id');
 | 
				
			||||||
		$scene = array (
 | 
							$scene = array (
 | 
				
			||||||
			'name' => $name,
 | 
								'name' => $name,
 | 
				
			||||||
 | 
								'owner_id' => $userId,
 | 
				
			||||||
			'on_days' => $onDays,
 | 
								'on_days' => $onDays,
 | 
				
			||||||
			'if_something' => $ifCode,
 | 
								'if_something' => $ifCode,
 | 
				
			||||||
			'do_something' => $doCode,
 | 
								'do_something' => $doCode,
 | 
				
			||||||
@@ -160,7 +162,7 @@ class AutomationManager{
 | 
				
			|||||||
						}
 | 
											}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was executed");
 | 
											$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) {
 | 
										} else if ($restart) {
 | 
				
			||||||
						$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was restarted");
 | 
											$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was restarted");
 | 
				
			||||||
						Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
 | 
											Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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(){
 | 
						public function getAvatarUrl(){
 | 
				
			||||||
		$email = self::getUserData('email');
 | 
							$email = self::getUserData('email');
 | 
				
			||||||
		return 'https://secure.gravatar.com/avatar/' . md5( strtolower( trim( $email ) ) );
 | 
							return 'https://secure.gravatar.com/avatar/' . md5( strtolower( trim( $email ) ) );
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,6 +50,12 @@
 | 
				
			|||||||
                <div class="col">
 | 
					                <div class="col">
 | 
				
			||||||
                    <?php echo implode(', ',$AUTOMATIONDATA['onDays']);?>
 | 
					                    <?php echo implode(', ',$AUTOMATIONDATA['onDays']);?>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="col">
 | 
				
			||||||
 | 
					                    <?php echo $AUTOMATIONDATA['owner_name'];?>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div class="col">
 | 
				
			||||||
 | 
					                    <?php echo $AUTOMATIONDATA['execution_time'];?>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div class="row">
 | 
					            <div class="row">
 | 
				
			||||||
                <div class="col">
 | 
					                <div class="col">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,12 +27,19 @@ class Automation extends Template
 | 
				
			|||||||
					'state' => $subDeviceState,
 | 
										'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']] = [
 | 
								$automations[$automationData['automation_id']] = [
 | 
				
			||||||
				'name' => $automationData['name'],
 | 
									'name' => $automationData['name'],
 | 
				
			||||||
 | 
									'owner_name' => $userManager->getUserId($automationData['owner_id'])['username'],
 | 
				
			||||||
				'onDays' => json_decode($automationData['on_days']),
 | 
									'onDays' => json_decode($automationData['on_days']),
 | 
				
			||||||
				'ifSomething' => $automationData['if_something'],
 | 
									'ifSomething' => $automationData['if_something'],
 | 
				
			||||||
				'doSomething' => $doSomething,
 | 
									'doSomething' => $doSomething,
 | 
				
			||||||
				'active' => $automationData['active'],
 | 
									'active' => $automationData['active'],
 | 
				
			||||||
 | 
									'execution_time' => $executionTime,
 | 
				
			||||||
			];
 | 
								];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user