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 getAllUnreadRepliesByUserId($id) { $sql = 'SELECT Post.id AS id, Post_Replay.id AS modelId, title, Post_Replay.content AS reply, Post_Replay.datetime, Post_Replay.Participant_id AS replier FROM 13027272d.Post, 13027272d.Post_Replay WHERE 13027272d.Post_Replay.Post_id = 13027272d.Post.id AND 13027272d.Post.Participant_id = ' . $id . ' AND is_read = 0 AND Post.Participant_id <> Post_Replay.Participant_id ORDER BY Post_Replay.datetime ASC;'; return PostReplay::findBySql($sql)->asArray()->all(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PostReplay::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'Post_id' => $this->Post_id, 'Participant_id' => $this->Participant_id, 'datetime' => $this->datetime]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($id) { $newReply = new PostReplay(); $newReply->Post_id = $id; $replied = false; if ($newReply->load(Yii::$app->request->post())) { $newReply->datetime = date("Y-m-d H:i:s"); $newReply->Participant_id = Yii::$app->user->id; $newReply->is_read = 0; if ($newReply->save()) { $replied = true; $newReply = new PostReplay(); } } return $this->render('view', ['model' => $this->findModel($id), 'newReply' => $newReply, 'replied' => $replied, 'allReplies' => PostReplay::getAllRepliesByPostId($id)]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PostReplay::find(); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $query->asArray()->all(); } $query->orFilterWhere(['like', 'content', $this->globalSearch])->orFilterWhere(['like', 'datetime', $this->globalSearch]); $raw = $query->asArray()->all(); $returnArr = []; foreach ($raw as $row) { $detail = substr($row['content'], 0, 200) . '...'; $arrayRow = ['type' => 'post', 'id' => $row['Post_id'], 'title' => 'Reply - ' . Post::getPostTileByPostId($row['Post_id']), 'detail' => $detail]; array_push($returnArr, $arrayRow); } return $returnArr; }
} else { $diff = strtotime('now') - strtotime($date->datetime); } if ($diff < 60) { return $diff . ' secs ago'; } else { if ($diff < 3600) { return intval($diff / 60) . ' mins ago'; } else { if ($diff < 86400) { return intval($diff / 3600) . ' hours ago'; } else { return intval($diff / 86400) . ' days ago'; } } } }], ['attribute' => 'Participant_id', 'label' => 'Users', 'format' => 'text', 'value' => function ($data) { $appReplies = \app\models\PostReplay::getAllRepliesPeopleByPostId($data->id); $returnString = \app\models\User::getUserFirstNameById($data->Participant_id); foreach ($appReplies as $row) { if ($row["Participant_id"] != $data->Participant_id) { $returnString .= ', ' . \app\models\User::getUserFirstNameById($row["Participant_id"]); } } return $returnString; }]]]); ?> </div>
public function getTopNotifications() { $replies = PostReplay::getAllUnreadReplies(); return json_encode($replies); }