Completed
Push — master ( 9420d2...f7d146 )
by Alex
03:34
created

CategoryRepository::findFrontCategories()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 24
rs 8.9713
cc 2
eloc 14
nc 2
nop 1
1
<?php
2
3
/*
4
* This file is part of the OrbitaleCmsBundle package.
5
*
6
* (c) Alexandre Rock Ancelet <[email protected]>
7
*
8
* For the full copyright and license information, please view the LICENSE
9
* file that was distributed with this source code.
10
*/
11
12
namespace Orbitale\Bundle\CmsBundle\Repository;
13
14
use Orbitale\Bundle\CmsBundle\Entity\Category;
15
16
class CategoryRepository extends AbstractCmsRepository
17
{
18
    /**
19
     * @param array $slugs
20
     *
21
     * @return Category[]
22
     */
23
    public function findFrontCategories(array $slugs)
24
    {
25
        $qb = $this->createQueryBuilder('category')
26
            ->where('category.enabled = :enabled')
27
            ->setParameter('enabled', true)
28
            ->andWhere('category.slug IN ( :slugs )')
29
            ->setParameter('slugs', $slugs)
30
        ;
31
32
        /** @var Category[] $results */
33
        $results = $qb
34
            ->getQuery()
35
            ->useResultCache($this->cacheEnabled, $this->cacheTtl)
36
            ->getResult()
37
        ;
38
39
        $resultsSortedBySlug = [];
40
41
        foreach ($results as $category) {
42
            $resultsSortedBySlug[$category->getSlug()] = $category;
43
        }
44
45
        return $resultsSortedBySlug;
46
    }
47
}
48