public function testGetRandomNotification() { $result = $this->beaconNotificationDao->getRandomNotification(); $notification = new BeaconNotification(); $notification->fromArray($result); $this->assertTrue($notification instanceof BeaconNotification); $this->assertTrue(!is_null($notification->getDefinition())); }
public function execute($request) { $this->notificationEnabled = false; $count = 0; $notification = null; do { if (isset($notification) && $notification) { $this->getBeaconNotificationService()->deleteNotificationByName($notification->getName()); } $notificationArr = $this->getBeaconNotificationService()->getRandomNotification(); if (!$notificationArr) { break; } $notification = new BeaconNotification(); $notification->fromArray($notificationArr); } while (time() > strtotime($notification->getExpiryDate()) && ++$count < self::MAX_TRIES); if (isset($notification) && $count < self::MAX_TRIES) { $this->notificationEnabled = true; $notificationXML = new SimpleXMLElement($notification->getDefinition()); $this->notificationHeader = $this->getBeaconNotificationService()->sanitizeNotificationSection(trim($notificationXML->content->header . "")); $this->notificationBody = $this->getBeaconNotificationService()->sanitizeNotificationSection(trim($notificationXML->content->body . "")); } }
public function resolveNotificationMessages($messages) { $idArray = array(); $beaconNotificationService = new BeaconNotificationService(); foreach ($messages as $message) { try { $messageBody = new SimpleXMLElement($message['definition']); $name = $message['name']; $idArray[] = $message['id']; $notification = new BeaconNotification(); if ($message['operation'] == 'DELETE') { $result = $beaconNotificationService->deleteNotificationByName($name); continue; } else { if ($message['operation'] == 'UPDATE') { $notification = $beaconNotificationService->getNotificationByName($name); if ($notification == null || !$notification) { $notification = new BeaconNotification(); } } } $notification->setName($name); $notification->setDefinition($message['definition']); $period = trim($messageBody->settings->period . ""); $expiry = time() + (int) $period; $time = new DateTime(); $time->setTimestamp($expiry); $notification->setExpiryDate($time->format('Y-m-d H:i:s')); $notification->save(); } catch (Exception $exc) { echo $exc->getTraceAsString(); } } return $idArray; }