XdccRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 73
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B findLike() 0 49 5
A countAll() 0 8 1
1
<?php
2
3
namespace Xdaysaysay\CoreBundle\Entity\Repository;
4
5
use Xdaysaysay\CoreBundle\Entity\Xdcc;
6
7
/**
8
 * SerieRepository
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class XdccRepository extends \Doctrine\ORM\EntityRepository
14
{
15
    /**
16
     * @param array      $searchTerms
17
     * @param array      $orderBy
18
     * @param null       $limit
19
     * @param null       $offset
20
     * @param bool|false $count
21
     * @param array      $columnSearch
22
     *
23
     * @return int|Xdcc[]
24
     * @throws \Doctrine\ORM\NoResultException
25
     * @throws \Doctrine\ORM\NonUniqueResultException
26
     */
27
    public function findLike($searchTerms = [], $orderBy = [], $limit = null, $offset = null, $count = false, $columnSearch = array())
0 ignored issues
show
Unused Code introduced by
The parameter $columnSearch is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
        $array = [
30
            'id'          => 's.id',
31
            'chan_name'   => 't.chan_name',
32
            'server_name' => 's.name',
33
            'bot_name'    => 't.bot_name',
34
            'packs'       => 'nb_packs',
35
            'visible'     => 'x.visible',
36
        ];
37
38
        $nbPackQb = $this->_em->createQueryBuilder();
39
        $nbPackQb->select('COUNT(p.id)');
40
        $nbPackQb->from('XdaysaysayCoreBundle:Pack', 'p');
41
        $nbPackQb->where($nbPackQb->expr()->eq('p.xdcc', 'x'));
42
43
        $qb = $this->createQueryBuilder('x');
44
        $qb->addSelect('t');
45
        $qb->addSelect('s');
46
        $qb->addSelect('(' . $nbPackQb->getDQL() . ') AS HIDDEN nb_packs');
47
        $qb->leftJoin('x.teams', 't');
48
        $qb->leftJoin('x.server', 's');
49
50
        if (is_array($searchTerms)) {
51
            foreach ($searchTerms as $term) {
52
                if (!empty($term)) {
53
                    $qb->andWhere($qb->expr()->orX(
54
                        $qb->expr()->like('x.id', $qb->expr()->literal('%'.$term.'%')),
55
                        $qb->expr()->like('s.name', $qb->expr()->literal('%'.$term.'%')),
56
                        $qb->expr()->like('t.chan_name', $qb->expr()->literal('%'.$term.'%')),
57
                        $qb->expr()->like('t.bot_name', $qb->expr()->literal('%'.$term.'%'))
58
                    ));
59
                }
60
            }
61
        }
62
63
        $qb->orderBy($array[$orderBy[0]], ucwords($orderBy[1]));
64
        if (!$count) {
65
            $qb->setFirstResult($offset);
66
            $qb->setMaxResults($limit);
67
            return $qb->getQuery()->getResult();
68
        } else {
69
            $qb->select($qb->expr()->countDistinct('x.id'));
70
            $qb->addSelect('(' . $nbPackQb->getDQL() . ') AS HIDDEN nb_packs');
71
72
            $result = $qb->getQuery()->getScalarResult();
73
            return $result[0];
74
        }
75
    }
76
77
    public function countAll()
78
    {
79
        $qb = $this->_em->createQueryBuilder();
80
        $qb->select('count(x.id)')
81
            ->from('XdaysaysayCoreBundle:Xdcc', 'x');
82
83
        return $qb->getQuery()->getSingleScalarResult();
84
    }
85
}
86