@@ 46-59 (lines=14) @@ | ||
43 | ->getSingleResult(); |
|
44 | } |
|
45 | ||
46 | public function getArticleWithCountComment($slug) |
|
47 | { |
|
48 | return $this->createQueryBuilder('a') |
|
49 | ->select('a, c, t, u, count(cm.id) as countComments') |
|
50 | ->leftJoin('a.categories', 'c') |
|
51 | ->leftJoin('a.tags', 't') |
|
52 | ->leftJoin('a.comments', 'cm') |
|
53 | ->join('a.user', 'u') |
|
54 | ->where('a.slug = ?1') |
|
55 | ->groupBy('a, c, t, u') |
|
56 | ->setParameter(1, $slug) |
|
57 | ->getQuery() |
|
58 | ->getSingleResult(); |
|
59 | } |
|
60 | ||
61 | public function getArticlesSorted($sortBy, $param, $page = 1, $max = 10) |
|
62 | { |
|
@@ 117-129 (lines=13) @@ | ||
114 | ||
115 | } |
|
116 | ||
117 | public function getPopularArticles($max = 5) |
|
118 | { |
|
119 | return $this->createQueryBuilder('a') |
|
120 | ->select('a, u, avg(c.rating) as rating') |
|
121 | ->leftJoin('a.comments', 'c') |
|
122 | ->join('a.user', 'u') |
|
123 | ->groupBy('a, u') |
|
124 | ->orderBy('rating', 'DESC') |
|
125 | ->setFirstResult(0) |
|
126 | ->setMaxResults($max) |
|
127 | ->getQuery() |
|
128 | ->getResult(); |
|
129 | } |
|
130 | ||
131 | public function getRecentArticles($max = 5) |
|
132 | { |