Ejemplo n.º 1
0
 public function subscribe($chanelAlias)
 {
     $chanel = $this->getChanel($chanelAlias);
     $subscriber = $this->getCurSubscriber();
     $subscribe = Notifications\Subscribe::get([['subscriber_id', $subscriber->id], ['chanel_id', $chanel->id]]);
     if ($subscribe) {
         $response = new Server\Result();
         $response->successMsg = 'Вы уже подписаны';
         $response->send();
     }
     $subscribe = new Notifications\Subscribe();
     $subscribe->subscriber_id = $subscriber->id;
     $subscribe->chanel_id = $chanel->id;
     $subscribe->save();
     $response = new Server\Result();
     $response->successMsg = 'Вы были подписаны на уведомления';
     $response->send();
 }
Ejemplo n.º 2
0
 public function checkAction()
 {
     $result = new Server\Result();
     $device = $this->Notifications->getCurDevice();
     $subscriber = $this->Notifications->getCurSubscriber();
     $subscribes = Notifications\Subscribe::getList(['where' => ['subscriber_id', $subscriber->id]]);
     $chanelsIds = [];
     foreach ($subscribes as $subscribe) {
         $chanelsIds[$subscribe->chanel_id] = $subscribe->chanel_id;
     }
     $result->content = [];
     if ($chanelsIds) {
         $notifications = Notifications\Notification::getList(['where' => [['date_create', $device->date_last_check, '>='], ['chanel_id', implode(',', $chanelsIds), 'IN']]]);
         foreach ($notifications as $notification) {
             $result->content[] = $notification->_params;
         }
     }
     $device->date_last_check = date('Y-m-d H:i:s');
     $device->save();
     $result->send();
 }