Example #1
0
 public function token_post()
 {
     $this->auth();
     try {
         if (!$this->post('device_token')) {
             throw new Exception('Missing Parameters', 400);
         }
         $this->response($this->device_tokens_model->add_token($this->user_id, $this->post('device_token')), 200);
     } catch (Exception $e) {
         $this->response($e->getMessage(), $e->getCode());
     }
 }
Example #2
0
 protected function send_notification($type, $event_id)
 {
     $recipients = $this->dt_model->get_tokens_for_send($type, $event_id, $this->user_id);
     $emails = [];
     $tokens = [];
     foreach ($recipients as $user) {
         if ($user['push_allowed']) {
             $tokens[] = $user['token'];
         }
         if ($user['email_allowed']) {
             $emails[] = $user['email'];
         }
     }
     if ($tokens) {
         $this->send_push($type, $tokens, $event_id);
     }
     if ($emails) {
         $this->send_email(implode(', ', $emails), lang("{$type}_subject"), sprintf(lang("{$type}_email"), $this->user['username'], $event_id));
     }
     return true;
 }