Пример #1
0
 /**
  * Marks notification as seen
  */
 public function markAsSeen()
 {
     if ($this->record->group_key != '') {
         // Ensure to update all grouped notifications
         Notification::updateAll(['seen' => 1], ['class' => $this->record->class, 'user_id' => $this->record->user_id, 'group_key' => $this->record->group_key]);
     } else {
         $this->record->seen = 1;
         $this->record->save();
     }
     // Automatically mark similar notifications (same source) as seen
     $similarNotifications = Notification::find()->where(['source_class' => $this->record->source_class, 'source_pk' => $this->record->source_pk, 'user_id' => $this->record->user_id])->andWhere(['!=', 'seen', '1']);
     foreach ($similarNotifications->all() as $n) {
         $n->getClass()->markAsSeen();
     }
 }
Пример #2
0
 /**
  * Marks all notifications as seen
  */
 public function actionMarkAsSeen()
 {
     Yii::$app->response->format = 'json';
     $count = Notification::updateAll(['seen' => 1], ['user_id' => Yii::$app->user->id]);
     return ['success' => true, 'count' => $count];
 }