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;
 }