Completed
Pull Request — master (#9)
by Nicolas
02:22
created

CategoryRepository::getAllWithPublishedPosts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Smart\ContentBundle\Entity\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Smart\ContentBundle\Entity\Category;
7
8
/**
9
 * Nicolas Bastien <[email protected]>
10
 */
11
class CategoryRepository extends EntityRepository
12
{
13
    /**
14
     * @param int|null $limit
15
     * @return Category[]
16
     */
17
    public function getAllWithPublishedPosts($limit = null)
18
    {
19
        return $this->createQueryBuilder('c')
20
            ->leftJoin('c.posts', 'p')
21
            ->andWhere('p.publishedAt IS NOT NULL')
22
            ->andWhere('p.enabled = 1')
23
            ->orderBy('c.title', 'ASC')
24
            ->setMaxResults($limit)
25
            ->getQuery()
26
            ->getResult();
27
    }
28
}
29