Passed
Push — master ( 06a804...32f36d )
by Julito
13:31
created

BranchSyncRepository::getTopBranch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 0
dl 0
loc 17
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Repository;
5
6
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
7
8
/**
9
 * Class BranchSyncRepository.
10
 *
11
 * @package Chamilo\CoreBundle\Repository
12
 */
13
class BranchSyncRepository extends NestedTreeRepository
14
{
15
    /**
16
     * @param string $keyword
17
     *
18
     * @return mixed
19
     */
20
    public function searchByKeyword($keyword)
21
    {
22
        $qb = $this->createQueryBuilder('a');
23
24
        //Selecting user info
25
        $qb->select('DISTINCT b');
26
27
        $qb->from('Chamilo\CoreBundle\Entity\BranchSync', 'b');
28
29
        //Selecting courses for users
30
        //$qb->innerJoin('u.courses', 'c');
31
32
        //@todo check app settings
33
        $qb->add('orderBy', 'b.branchName ASC');
34
        $qb->where('b.branchName LIKE :keyword');
35
        $qb->setParameter('keyword', "%$keyword%");
36
        $q = $qb->getQuery();
37
38
        return $q->execute();
39
    }
40
41
    /**
42
     * Gets the first branch with parent_id = NULL.
43
     *
44
     * @return mixed
45
     */
46
    public function getTopBranch()
47
    {
48
        $qb = $this->createQueryBuilder('a');
49
50
        //Selecting user info
51
        $qb->select('DISTINCT b');
52
53
        $qb->from('Chamilo\CoreBundle\Entity\BranchSync', 'b');
54
        $qb->where('b.parentId IS NULL');
55
        $qb->add('orderBy', 'b.id ASC');
56
        $qb->setMaxResults(1);
57
        $q = $qb->getQuery()->getResult();
58
        if (empty($q)) {
59
            return null;
60
        } else {
61
            foreach ($q as $result) {
62
                return $result;
63
            }
64
        }
65
    }
66
}
67