public function actionMarkNotificationRead()
 {
     $data = Yii::$app->request->post();
     $id = intval($data['id']);
     $modelId = intval($data['modelId']);
     $type = $data['type'];
     if ($type == 'post') {
         $model = PostReplay::findOne($modelId);
         $model->is_read = 1;
         if ($model->save()) {
             return 0;
         }
     }
     if ($type == 'announcement') {
         $model = AnnouncementHasParticipant::findOne(['Accouncement_id' => $modelId, 'Participant_id' => $id]);
         $model->is_read = 1;
         if ($model->save()) {
             return 0;
         }
     }
     if ($type == 'activity') {
         $model = ParticipantHasActivity::findOne(['Participant_id' => $id, 'Activity_id' => $modelId]);
         $model->is_read = 1;
         if ($model->save()) {
             return 0;
         }
     }
     return -1;
 }
 public function getUnreadAnnouncementByUserId($id)
 {
     $sql = 'SELECT id, title, datetime
             FROM 13027272d.Announcement, 13027272d.Announcement_has_Participant WHERE
             13027272d.Announcement_has_Participant.Accouncement_id = 13027272d.Announcement.id
             AND 13027272d.Announcement_has_Participant.Participant_id = ' . $id . '
             AND Announcement_has_Participant.Participant_id <> Announcement.Administrator_id
             AND is_read = 0
             ORDER BY datetime ASC;';
     return AnnouncementHasParticipant::findBySql($sql)->asArray()->all();
 }
 /**
  * Creates a new Announcement model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('announcementCreate')) {
         $model = new Announcement();
         $model->datetime = date("Y-m-d H:i:s");
         $model->Administrator_id = Yii::$app->user->id;
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             AnnouncementHasParticipant::registerAllUsersToAnnouncement($model->getPrimaryKey());
             return $this->redirect(['view', 'id' => $model->id, 'Administrator_id' => $model->Administrator_id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }