From 83757a469dd14f870f111ee4f337e003d90ad13d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 25 Apr 2023 01:51:28 +0000 Subject: [PATCH] bug fixes and subscription improvements --- Admin/Install/Workflow.install.json | 29 ++++++++++++++++++++++++ Controller/ApiController.php | 35 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Admin/Install/Workflow.install.json b/Admin/Install/Workflow.install.json index b5fea35..38eef25 100755 --- a/Admin/Install/Workflow.install.json +++ b/Admin/Install/Workflow.install.json @@ -30,6 +30,35 @@ } } } + }, + "1008000002": { + "name": "Inform users", + "description": { + "en": "Inform users about changes", + "de": "Informiere Nutzer Ă¼ber Ă„nderungen" + }, + "function_type": "Api", + "function": "informUsers", + "module": "OnlineResourceWatcher", + "inputs": [ + "unit", + "{*}" + ], + "outputs": [ + "resources[]", + "{*}" + ], + "settings": { + "unit": { + "type": "input", + "subtype": "number", + "default": null, + "title": { + "en": "Unit", + "de": "Unit" + } + } + } } } } \ No newline at end of file diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 9e9474f..8c33292 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -186,6 +186,41 @@ final class ApiController extends Controller $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Resources', 'Resources were checked.', null); } + /** + * Inform users about changed resources + * + * @param mixed $var Generic variable + * + * @return void + * + * @since 1.0.0 + */ + public function informUsers(mixed $var = null) : void + { + $dateTime = new \DateTime('now'); + $dateTime = $dateTime->modify('-1 hour'); + + $reports = ReportMapper::getAll() + ->where('status', ReportStatus::CHANGE) + ->where('createdAt', $dateTime, '>=') + ->execute(); + + foreach ($reports as $report) { + // @todo: get templates + // @todo: get users to inform + // @todo: inform users + } + } + + /** + * Checks resources for changes + * + * @param mixed $var Generic variable + * + * @return array + * + * @since 1.0.0 + */ public function checkResources(mixed $var = null) : array { $changed = [];