/** * Displays a single Message model. * @param $receiver * @return mixed * @internal param int $id */ public function actionView($receiver) { $receiverUser = User::findOne($receiver); $models = Message::find()->where(['user_id' => Yii::$app->user->id, 'friend_id' => $receiver])->all(); return $this->render('view', ['models' => $models, 'receiver' => $receiverUser]); }
public function actionBulkDelete() { /** @var $model \app\modules\message\models\Message */ Yii::$app->response->format = Response::FORMAT_JSON; if (!isset($_POST['keys'])) { return ['status' => 0]; } $keys = Yii::$app->request->getBodyParam('keys'); if (!is_array($keys) || empty($keys)) { return ['status' => 0]; } $messageIds = []; if (($modelMessageUser = MessageUser::find()->where(['_id' => $keys])->all()) != null) { foreach ($modelMessageUser as $dataMessageUser) { $messageIds[] = $dataMessageUser->message_id; } } if (empty($messageIds)) { return ['status' => 0]; } $userId = Yii::$app->user->id; if (($modelMessage = Message::find()->where(['_id' => $messageIds])->all()) == null) { return ['status' => 0]; } foreach ($modelMessage as $model) { // Neu day chi la nguoi nhan if ($model->created_by != $userId) { MessageUser::updateAll(['is_delete' => 1], ['message_id' => $model->primaryKey, 'user_id' => $userId]); continue; } // Neu day la nguoi tao message // Xoa du lieu lien quan Message::deleteAll(['message_id' => $model->primaryKey]); MessageUser::deleteAll(['message_id' => $model->primaryKey]); // Xoa message chinh $model->delete(); } return ['status' => 1]; }