Completed
Pull Request — master (#30)
by nonanerz
04:38
created

UserRepository::selectNotBlocked()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AppBundle\Repository;
4
5
use Doctrine\ORM\Query;
6
use AppBundle\Entity\DTO\Filter;
7
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
8
9
/**
10
 * UserRepository.
11
 *
12
 * This class was generated by the Doctrine ORM. Add your own custom
13
 * repository methods below.
14
 */
15
class UserRepository extends \Doctrine\ORM\EntityRepository implements UserLoaderInterface
16
{
17 4
    public function loadUserByUsername($username)
18
    {
19 4
        return $this->createQueryBuilder('user')
20 4
            ->andWhere('user.apiToken = :username')
21 4
            ->setParameter('username', $username)
22 4
            ->getQuery()
23 4
            ->getOneOrNullResult();
24
    }
25
26
    /**
27
     * @param Filter $filter
28
     *
29
     * @return Query
30
     */
31 3
    public function selectUsersByParams(Filter $filter):Query
32
    {
33 3
        $postsQuery = $this->createQueryBuilder('u');
34 3
        if ($filter->name) {
35
            $postsQuery->where(
36
                $postsQuery->expr()->like('u.firstName', ':name')
37
            )
38
                ->orWhere(
39
                    $postsQuery->expr()->like('u.lastName', ':name')
40
                )
41
                ->orWhere(
42
                    $postsQuery->expr()->like('u.email', ':name')
43
                )
44
                ->setParameter('name', '%'.$filter->name.'%');
45
        }
46
47 3
        return $postsQuery->getQuery();
48
    }
49
50
    public function selectNotBlocked()
51
    {
52
        return $this->createQueryBuilder('u')
53
            ->andWhere('u.enabled = TRUE')
54
            ->orderBy('u.lastName')
55
            ->getQuery()
56
            ->getResult();
57
    }
58
}
59