/** * @param type - тип фотки: photo, club * @param photoId */ public static function actionView() { $post = Yii::$app->request->post(); $photo_id = $post['photo_id']; $type = $post['type']; if ($type == 'photo') { View::viewPhoto($photo_id); } elseif ($type == 'club') { View::viewPhotoClub($photo_id); } }
public function actionPhoto($photo_id) { $photo = ClubPhoto::getAllPhotoInfo($photo_id); $club_id = $photo['club_id']; $this->getClubInfo($club_id, $club, $role, $potentialMembers, $isOpen); if (!$club['club_id']) { throw new \yii\web\HttpException(404); } if (!$isOpen) { return $this->redirect("/club{$club_id}"); } View::viewPhotoClub($photo_id); $model = new CommentsClub(); $from = "comments_club"; $comments = Comments::getCommentsNew($photo_id, $from); $request = Yii::$app->request; if (!$club['is_closed_comments'] && $request->isAjax && $model->load($request->post()) && $model->validate()) { Yii::$app->response->format = Response::FORMAT_JSON; $model->date_time = date('Y-m-d H:i:s'); $model->id_user = Yii::$app->user->getId(); $model->text = htmlspecialchars($model->text); //визначення чи це простий комент чи це ре-комент $text = explode(":", $model->text); //перевіряємо чи введено коректне ім'я користувача якому дана відповідь $true_name = 0; foreach ($comments as $key) { if ($key['name'] == $text[0]) { $true_name = 1; } } if (!$true_name) { $model->answer_id = 0; } if ($model->save()) { ClubPhoto::updateComments($photo_id, 1); $latest_id = $model->id; $user = User::find()->select('avatar, name')->where(["id" => $model->id_user])->one(); echo json_encode(['text' => $model->text, 'id_user' => $model->id_user, 'name' => $user[name], 'avatar' => $user[avatar], 'id_comment' => $latest_id]); die; } else { echo 0; } } return $this->render('photo_page', ['club' => $club, 'photo' => $photo, 'comments' => $comments, 'model' => $model]); }