Skip to content

Commit 21c4ed6

Browse files
authored
Merge pull request #104 from Phpvarious/notifications
Notifications
2 parents 59c3c46 + cbe6038 commit 21c4ed6

File tree

2 files changed

+19
-82
lines changed

2 files changed

+19
-82
lines changed

core/api/mobile.api.php

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ function saveMenuFromAppV2($menu, $mobile)
343343
$retentionTime = config::byKey('retentionTime', 'mobile', null);
344344
if(isset($retentionTime) && $retentionTime != null) {
345345
log::add('mobile', 'debug', '| [INFO] Nettoyage des notifs et images > ');
346-
mobile::getNotificationsWithRetentioNTime($params['Iq'], $retentionTime);
346+
mobile::cleaningNotifications($params['Iq'], $retentionTime);
347347
}
348348

349349
$jsonrpc->makeSuccess($return);
@@ -676,85 +676,16 @@ function saveMenuFromAppV2($menu, $mobile)
676676
if ($jsonrpc->getMethod() == 'getNotificationsFromFile') {
677677
log::add('mobile', 'debug', '┌──────────▶︎ :fg-warning: Recuperation des Notifications :/fg: ──────────');
678678
$Iq = $params['Iq'];
679-
680-
if(isset($params['notifsTime'])){
681-
$retentionTime = $params['notifsTime'];
682-
config::save('retentionTime', $retentionTime, 'mobile');
683-
log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
684-
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
685-
$currentTime = time();
686-
687-
$pathImages = dirname(__FILE__) . '/../data/images/';
688-
if(is_dir($pathImages)){
689-
$images = glob($pathImages . '*.jpg');
690-
691-
foreach ($images as $image) {
692-
$fileCreationTime = filemtime($image);
693-
if ($fileCreationTime < ($currentTime - $retentionSeconds)) {
694-
unlink($file);
695-
}
696-
}
697-
}
698-
}
699-
700-
701-
702679
$filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json';
703680
$notifications = 'noNotifications';
704681
if (file_exists($filePath)) {
705682
$notifications = file_get_contents($filePath);
706-
if ($notifications) {
707-
$notifications = json_decode($notifications, true);
708-
$notificationsModified = false;
709-
710-
foreach ($notifications as $id => $value) {
711-
$notificationDate = strtotime($value['data']['date']);
712-
if(isset($retentionSeconds)){
713-
if (($currentTime - $notificationDate) > $retentionSeconds) {
714-
unset($notifications[$id]);
715-
$notificationsModified = true;
716-
} else {
717-
$dateNew = substr($value['data']['date'], 0, 10);
718-
$horaire = substr($value['data']['date'], -8);
719-
$horaireFormat = substr($horaire, 0, 5);
720-
$notifications[$id]['data']['newDate'] = $dateNew;
721-
$notifications[$id]['data']['horaireFormat'] = $horaireFormat;
722-
}
723-
}else{
724-
$dateNew = substr($value['data']['date'], 0, 10);
725-
$horaire = substr($value['data']['date'], -8);
726-
$horaireFormat = substr($horaire, 0, 5);
727-
$notifications[$id]['data']['newDate'] = $dateNew;
728-
$notifications[$id]['data']['horaireFormat'] = $horaireFormat;
729-
}
730-
// if (($currentTime - $notificationDate) > $retentionSeconds) {
731-
// unset($notifications[$id]);
732-
// $notificationsModified = true;
733-
// } else {
734-
// $dateNew = substr($value['data']['date'], 0, 10);
735-
// $horaire = substr($value['data']['date'], -8);
736-
// $horaireFormat = substr($horaire, 0, 5);
737-
// $notifications[$id]['data']['newDate'] = $dateNew;
738-
// $notifications[$id]['data']['horaireFormat'] = $horaireFormat;
739-
// }
740-
}
741-
if ($notificationsModified) {
742-
file_put_contents($filePath, $notifications);
743-
}
744-
745-
$notifications = json_encode($notifications);
746-
$jsonrpc->makeSuccess($notifications);
747-
log::add('mobile', 'debug', '| [INFO] Notifications > ' . $notifications);
748-
log::add('mobile', 'debug', '└───────────────────────────────────────────');
749-
}
750-
751683
}
752-
753-
//$jsonrpc->makeSuccess($notifications);
754-
684+
log::add('mobile', 'debug', '| [INFO] Notifications > ' . $notifications);
685+
log::add('mobile', 'debug', '└───────────────────────────────────────────');
686+
$jsonrpc->makeSuccess($notifications);
755687
}
756688

757-
758689
if ($jsonrpc->getMethod() == 'deleteNotificationInJsonFile') {
759690
log::add('mobile', 'debug', '┌────▶︎ deleteNotificationInJsonFile ──────');
760691
$Iq = $params['Iq'];
@@ -772,8 +703,8 @@ function saveMenuFromAppV2($menu, $mobile)
772703
$notifications = json_encode($notificationsArray);
773704
file_put_contents($filePath, $notifications);
774705
}
775-
log::add('mobile', 'debug', '└───────────────────────────────────────────');
776706
}
707+
log::add('mobile', 'debug', '└───────────────────────────────────────────');
777708
$jsonrpc->makeSuccess('ok');
778709
}
779710

core/class/mobile.class.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,14 @@ public static function discovery_multi($cmds)
306306
}
307307

308308

309-
public static function getNotificationsWithRetentioNTime($Iq, $retentionTime){
309+
public static function cleaningNotifications($Iq, $retentionTime){
310310
log::add('mobile', 'debug', '┌──────────▶︎ :fg-warning: Nettoyage des Notifications et Images :/fg: ──────────');
311-
312311
log::add('mobile', 'debug', '| Durée de retention actuelle : '. $retentionTime . ' jours');
312+
313313
$retentionSeconds = intVal($retentionTime) * 24 * 60 * 60;
314314
$currentTime = time();
315315

316-
$pathImages = dirname(__FILE__) . '/../data/images/';
316+
$pathImages = dirname(__FILE__) . '/../../data/images/';
317317
if(is_dir($pathImages)){
318318
$images = glob($pathImages . '*.jpg');
319319
foreach ($images as $image) {
@@ -322,8 +322,8 @@ public static function getNotificationsWithRetentioNTime($Iq, $retentionTime){
322322
unlink($image);
323323
}
324324
}
325-
}
326-
325+
}
326+
327327
$filePath = dirname(__FILE__) . '/../data/notifications/' . $Iq . '.json';
328328
$notifications = 'noNotifications';
329329
if (file_exists($filePath)) {
@@ -339,9 +339,11 @@ public static function getNotificationsWithRetentioNTime($Iq, $retentionTime){
339339
$notificationsModified = true;
340340
}
341341
}
342-
342+
$notifications = json_encode($notifications);
343+
if ($notificationsModified) {
344+
file_put_contents($filePath, $notifications);
345+
}
343346
}
344-
345347
}
346348
log::add('mobile', 'debug', '| Fin du nettoyage des Notifications et Images');
347349
log::add('mobile', 'debug', '└───────────────────────────────────────────');
@@ -636,6 +638,8 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ
636638
if(isset($Iq)) log::add('mobile', 'debug', '||| IQ for jsonPublish > ' . $Iq);
637639

638640
$dateNotif = date("Y-m-d H:i:s");
641+
$newDate = date("Y-m-d");
642+
$horaireFormat = date("H:i");
639643
$badge = 0;
640644
if ($timeout != 'nok') {
641645
$timeout = date('Y-m-d H:i:s', strtotime("$dateNotif + $timeout SECONDS"));
@@ -736,7 +740,9 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ
736740
'boxName' => config::byKey('name'),
737741
'boxApiKey' => jeedom::getHardwareKey(),
738742
"askParams" => $askParams,
739-
'textToDisplay' => 'none'
743+
'textToDisplay' => 'none',
744+
'newDate' => $newDate,
745+
'horaireFormat' => $horaireFormat
740746
];
741747

742748
$notification = [

0 commit comments

Comments
 (0)