Passed
Pull Request — 1.11.x (#4515)
by Angel Fernando Quiroz
08:51
created

CWikiCategoryRepository::findByCourse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nop 2
nc 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CourseBundle\Entity\Repository;
6
7
use Chamilo\CoreBundle\Entity\Course;
8
use Chamilo\CoreBundle\Entity\Session;
9
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
10
11
class CWikiCategoryRepository extends NestedTreeRepository
12
{
13
    public function findByCourse(Course $course, ?Session $session): array
14
    {
15
        return $this->findBy(['course' => $course, 'session' => $session], ['lft' => 'ASC']);
16
    }
17
18
    public function countByCourse(Course $course, ?Session $session): int
19
    {
20
        return $this->count(['couse' => $course, 'session' => $session]);
21
    }
22
23
    /**
24
     * @return array|string
25
     */
26
    public function buildCourseTree(Course $course, ?Session $session, array $options = [])
27
    {
28
        $whereParams = ['course' => $course];
29
30
        if ($session) {
31
            $whereParams['session'] = $session;
32
        }
33
34
        $qb = $this->createQueryBuilder('c')
35
            ->where('c.course = :course')
36
            ->andWhere($session ? 'c.session = :session' : 'c.session IS NULL')
37
            ->orderBy('c.lft', 'ASC')
38
            ->setParameters($whereParams)
39
            ->getQuery()
40
        ;
41
42
        return $this->buildTree($qb->getArrayResult(), $options);
43
    }
44
}
45