Example #1
0
 public static function getComments($user_id, $type, $limit, $contentId, $contentType)
 {
     if ($contentId) {
         $date = (new Query())->select('date_time')->from('comments_' . $contentType)->where(['id' => $contentId])->scalar();
     }
     if ($type == 'user') {
         $articles_id = false;
         $photos_id = false;
         $club_photos_id = false;
     } else {
         $articles_id = Blog::getAllArticlesIdByAuthor($user_id);
         $photos_id = Photo::getAllPhotosIdByAuthor($user_id);
         $club_photos_id = ClubPhoto::getAllClubPhotosIdByAuthor($user_id);
     }
     $comment_blog_query = CommentsBlog::getCommentsQuery($user_id, $type, $articles_id);
     $comment_photo_query = CommentsPhoto::getCommentsQuery($user_id, $type, $photos_id);
     $comment_club_query = CommentsClub::getCommentsQuery($user_id, $type, $club_photos_id);
     $all_comments = $comment_blog_query->union($comment_photo_query, true)->union($comment_club_query, true);
     $sql = (new Query())->from(['ac' => $all_comments])->limit($limit)->orderBy('comment_date_time desc');
     if ($contentId) {
         $sql->andWhere(['<', 'comment_date_time', $date]);
     }
     $all_comments = $sql->all();
     foreach ($all_comments as &$comment) {
         self::DateCommentsInCorrectFormat($comment);
     }
     return $all_comments;
 }
Example #2
0
 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]);
 }