From ab92a58289c2e0ac98c9359387caf8d3a0d3f068 Mon Sep 17 00:00:00 2001 From: GamerClassN7 Date: Thu, 22 Oct 2020 17:59:45 +0200 Subject: [PATCH] Little Tweeks --- app/api/CronApi.php | 22 ++++++++-------- app/api/RoomsApi.php | 36 ++++++++++++++------------- app/models/managers/DeviceManager.php | 5 +++- app/plugins/DatabaseBackup.php | 2 +- app/plugins/ExamplePlugin.php | 2 +- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/app/api/CronApi.php b/app/api/CronApi.php index ba680e0..d115b2a 100644 --- a/app/api/CronApi.php +++ b/app/api/CronApi.php @@ -7,7 +7,7 @@ class CronApi extends ApiController //Log Cleaning $logKeeper = new LogMaintainer(); $logKeeper->purge(LOGTIMOUT); - + //Database Backup Cleanup $backupWorker = new DatabaseBackup(); $backupWorker->purge(5); @@ -20,18 +20,20 @@ class CronApi extends ApiController //Run Plugins $result = []; $dir = $_SERVER['DOCUMENT_ROOT'] . BASEDIR . 'app/plugins/'; - $pluginsFiles = array_diff(scandir($dir), ['..','.']); + $pluginsFiles = array_diff(scandir($dir), ['..', '.']); foreach ($pluginsFiles as $key => $pluginFile) { $className = str_replace(".php", "", $pluginFile); - echo " test s " . $className . '\\n'; - if(class_exists($className)){ - $pluginMakeClass = new $className; - if (method_exists($pluginMakeClass,'make')){ - $result[$className] = $pluginMakeClass->make(); - } - } + if (!class_exists($className)) { + continue; + } + $pluginMakeClass = new $className; + if (!method_exists($pluginMakeClass, 'make')) { + + continue; + } + $result[$className] = $pluginMakeClass->make(); } - + //Print Result $this->response($result); } diff --git a/app/api/RoomsApi.php b/app/api/RoomsApi.php index ffa9656..2bbefc3 100644 --- a/app/api/RoomsApi.php +++ b/app/api/RoomsApi.php @@ -1,36 +1,37 @@ requireAuth(); $response = []; $roomIds = []; $roomsData = RoomManager::getRoomsDefault(); - + foreach ($roomsData as $roomKey => $room) { $roomIds[] = $room['room_id']; } - + //Translation Of Numeric Walues $subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds); foreach ($subDevicesData as $subDeviceKey => $subDevice) { foreach ($subDevice as $key => $value) { if (strpos($subDevicesData[$subDeviceKey][$key]['type'], '-') !== false) { $type = ""; - foreach(explode('-', $subDevicesData[$subDeviceKey][$key]['type']) as $word){ + foreach (explode('-', $subDevicesData[$subDeviceKey][$key]['type']) as $word) { $type .= ucfirst($word); } - if(class_exists($type)){ - $deviceClass = new $type; - if (method_exists($deviceClass,'translate')){ - $subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']); - } - } else { + if (!class_exists($type)) { continue; } - } else { - continue; + $deviceClass = new $type; + if (!method_exists($deviceClass, 'translate')) { + continue; + } + $subDevicesData[$subDeviceKey][$key]['value'] = $deviceClass->translate($subDevicesData[$subDeviceKey][$key]['value']); } } } @@ -45,10 +46,11 @@ class RoomsApi extends ApiController{ } $this->response($response); } - - public function update($roomId){ + + public function update($roomId) + { //$this->requireAuth(); - + $subDevicesData = SubDeviceManager::getSubdevicesByRoomIds([$roomId]); $this->response($subDevicesData); } diff --git a/app/models/managers/DeviceManager.php b/app/models/managers/DeviceManager.php index 415896c..ed976d1 100644 --- a/app/models/managers/DeviceManager.php +++ b/app/models/managers/DeviceManager.php @@ -33,13 +33,16 @@ class DeviceManager{ WHERE devices.approved != ? ORDER BY $sort $sortType", Array(2)); } - public static function create ($name, $token) { + public static function create ($name, $token, $type = "") { $defaultRoom = RoomManager::getDefaultRoomId(); $device = array ( 'name' => $name, 'token' => $token, 'room_id' => $defaultRoom, ); + if (!empty($type)) { + $device['type'] = $type; + } try { Db::add ('devices', $device); return Db::loadOne("SELECT device_id FROM devices WHERE token = ?", array($token))['device_id']; diff --git a/app/plugins/DatabaseBackup.php b/app/plugins/DatabaseBackup.php index 01c3f04..e3b5dc9 100644 --- a/app/plugins/DatabaseBackup.php +++ b/app/plugins/DatabaseBackup.php @@ -44,7 +44,7 @@ class DatabaseBackup foreach ($files as $file) { $zip->addFile($file); } - echo $zip->close(); + $zip->close(); foreach ($files as $file) { unlink($file); } diff --git a/app/plugins/ExamplePlugin.php b/app/plugins/ExamplePlugin.php index e8d09e4..ca00c3e 100644 --- a/app/plugins/ExamplePlugin.php +++ b/app/plugins/ExamplePlugin.php @@ -1,5 +1,5 @@