PHP_SMART_HOME_V3/www/app/models/managers/SceneManager.php

42 lines
997 B
PHP
Raw Normal View History

2019-08-23 11:39:42 +00:00
<?php
class SceneManager{
public static $scenes;
2020-04-21 17:44:30 +00:00
public static function create ($icon, $name, $doCode) {
2019-08-23 11:39:42 +00:00
$scene = array (
'icon' => $icon,
'name' => $name,
'do_something' => $doCode,
);
try {
Db::add ('scenes', $scene);
} catch(PDOException $error) {
echo $error->getMessage();
die();
}
}
2020-04-21 17:44:30 +00:00
public static function getAllScenes () {
2019-08-23 11:39:42 +00:00
return Db::loadAll ("SELECT * FROM scenes");
}
2020-04-21 17:44:30 +00:00
public static function getScene ($sceneId) {
2019-08-23 11:39:42 +00:00
return Db::loadOne("SELECT * FROM scenes WHERE scene_id = ?", array($sceneId));
}
2020-04-21 17:44:30 +00:00
public static function execScene ($sceneId) {
2019-08-23 11:39:42 +00:00
$sceneData = SceneManager::getScene($sceneId);
$sceneDoJson = $sceneData['do_something'];
$sceneDoArray = json_decode($sceneDoJson);
foreach ($sceneDoArray as $deviceId => $deviceState) {
RecordManager::create($deviceId, 'on/off', $deviceState);
}
return true;
}
2020-04-21 17:44:30 +00:00
public static function delete($sceneId){
2019-08-23 11:39:42 +00:00
Db::command ('DELETE FROM scenes WHERE scene_id=?', array ($sceneId));
}
}
?>