Esempio n. 1
0
 /**
  * Send the notification
  */
 public function send()
 {
     $Client = new Client();
     $failures = array();
     $result = array();
     $data = ["registration_ids" => [], "data" => ["title" => $this->data['subject'], "message" => $this->data['body']]];
     foreach ($this->data['recipients'] as $user_id => $userdata) {
         $ThisUser = UserFactory::CreateUser($user_id);
         $subscriptions = Notifications::getPushSubscriptions($ThisUser);
         foreach ($subscriptions as $sub) {
             $data['registration_ids'][] = $sub['registration_id'];
         }
     }
     if (empty($data['registration_ids'])) {
         return;
     }
     try {
         $response = $Client->post($sub['endpoint'], ["headers" => ["Content-Type" => "application/json", "Authorization" => "key=" . GOOGLE_SERVER_KEY], "json" => $data]);
         $body = $response->getBody();
         $result = json_decode($body, true);
         $this->removeStaleSubscriptions($result, $data['registration_ids']);
         $return = array("stat" => true, "failures" => $result);
     } catch (RequestException $e) {
         $return = ["stat" => false, "failures" => ["message" => $e->getMessage(), "body" => $e->getRequest()->getBody()]];
     }
     return $return;
 }
 /**
  * @depends testCreateNotification
  * @depends test_createUser
  */
 public function testGetNotifications($Notification, $User)
 {
     $Notifications = new Notifications();
     $Notifications->getNotificationsWithStatus();
     $Notifications->getNotificationsByTransport();
     $Notifications->Recipient = $User;
     $Notifications->getNotificationsForUser();
     $Notifications->getAllNotifications();
     $Notifications->getPastNotificationsForUser($User);
     $Notifications->setPushSubscription($User, "21312323132131321");
     $Notifications->getPushSubscriptions($User);
     $Notifications->setPushSubscription($User, "21312323132131321", false);
 }