Notifications Icons Added
This commit is contained in:
		
							
								
								
									
										19
									
								
								api.php
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								api.php
									
									
									
									
									
								
							@@ -101,16 +101,26 @@ if ($token == null || $token == "") {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//Vstupní Checky
 | 
					//Vstupní Checky
 | 
				
			||||||
if (!DeviceManager::registeret($token)) {
 | 
					if (!DeviceManager::registeret($token)) {
 | 
				
			||||||
 | 
						$notificationMng = new NotificationManager;
 | 
				
			||||||
 | 
						$notificationData = [];
 | 
				
			||||||
	$notificationData = [
 | 
						$notificationData = [
 | 
				
			||||||
		'title' => 'Info',
 | 
							'title' => 'Info',
 | 
				
			||||||
		'body' => 'New device Detected',
 | 
							'body' => 'New device Detected Found',
 | 
				
			||||||
		'icon' => '',
 | 
							'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
 | 
				
			||||||
	];
 | 
						];
 | 
				
			||||||
	$deviceId = DeviceManager::create($token, $token);
 | 
						$deviceId = DeviceManager::create($token, $token);
 | 
				
			||||||
	foreach ($values as $key => $value) {
 | 
						foreach ($values as $key => $value) {
 | 
				
			||||||
		if (!SubDeviceManager::getSubDeviceByMaster($deviceId, $key)) {
 | 
							if (!SubDeviceManager::getSubDeviceByMaster($deviceId, $key)) {
 | 
				
			||||||
			SubDeviceManager::create($deviceId, $key, UNITS[$key]);
 | 
								SubDeviceManager::create($deviceId, $key, UNITS[$key]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ($notificationData != []) {
 | 
				
			||||||
 | 
								$subscribers = $notificationMng::getSubscription();
 | 
				
			||||||
 | 
								foreach ($subscribers as $key => $subscriber) {
 | 
				
			||||||
 | 
									$logManager->write("[NOTIFICATION] SENDING TO" . $subscriber['id'] . " ");
 | 
				
			||||||
 | 
									$notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//Notification for newly added Device
 | 
						//Notification for newly added Device
 | 
				
			||||||
@@ -161,7 +171,7 @@ if ($values != null || $values != "") {
 | 
				
			|||||||
				$notificationData = [
 | 
									$notificationData = [
 | 
				
			||||||
					'title' => 'Info',
 | 
										'title' => 'Info',
 | 
				
			||||||
					'body' => 'Someone just open up '.$device['name'],
 | 
										'body' => 'Someone just open up '.$device['name'],
 | 
				
			||||||
					'icon' => '',
 | 
										'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
 | 
				
			||||||
				];
 | 
									];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
@@ -169,7 +179,7 @@ if ($values != null || $values != "") {
 | 
				
			|||||||
				$notificationData = [
 | 
									$notificationData = [
 | 
				
			||||||
					'title' => 'Alert',
 | 
										'title' => 'Alert',
 | 
				
			||||||
					'body' => 'Wather leak detected by '.$device['name'],
 | 
										'body' => 'Wather leak detected by '.$device['name'],
 | 
				
			||||||
					'icon' => '',
 | 
										'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
 | 
				
			||||||
				];
 | 
									];
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -225,7 +235,6 @@ if ($values != null || $values != "") {
 | 
				
			|||||||
	echo json_encode(array(
 | 
						echo json_encode(array(
 | 
				
			||||||
		'device' => [
 | 
							'device' => [
 | 
				
			||||||
			'hostname' => $device['name'],
 | 
								'hostname' => $device['name'],
 | 
				
			||||||
			'sleepTime' => $device['sleep_time'],
 | 
					 | 
				
			||||||
			'ipAddress' => $device['ip_address'],
 | 
								'ipAddress' => $device['ip_address'],
 | 
				
			||||||
			'subnet' => $device['subnet'],
 | 
								'subnet' => $device['subnet'],
 | 
				
			||||||
			'gateway' => $device['gateway'],
 | 
								'gateway' => $device['gateway'],
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -129,7 +129,7 @@ class Ajax extends Template
 | 
				
			|||||||
				$notificationData = [
 | 
									$notificationData = [
 | 
				
			||||||
					'title' => 'Alert',
 | 
										'title' => 'Alert',
 | 
				
			||||||
					'body' => 'test notification',
 | 
										'body' => 'test notification',
 | 
				
			||||||
					'icon' => '',
 | 
										'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
 | 
				
			||||||
				];
 | 
									];
 | 
				
			||||||
				$notificationMng = new NotificationManager;
 | 
									$notificationMng = new NotificationManager;
 | 
				
			||||||
				$subscribers = $notificationMng::getSubscription();
 | 
									$subscribers = $notificationMng::getSubscription();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user