Completed
Push — master ( 133170...772a04 )
by Dominik
06:01 queued 04:25
created

SentEmailRepository::search()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.5806
c 0
b 0
f 0
ccs 0
cts 18
cp 0
cc 4
eloc 17
nc 2
nop 1
crap 20
1
<?php
2
3
namespace Azine\EmailBundle\Entity\Repositories;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\QueryBuilder;
7
8
/**
9
 * SentEmailRepository
10
 *
11
 * This class was generated by the Doctrine ORM. Add your own custom
12
 * repository methods below.
13
 */
14
class SentEmailRepository extends EntityRepository
15
{
16
    /**
17
     * Search SentEmails by search params.
18
     * @param $searchParams
19
     * @return array of SentEmail
20
     */
21
    public function search($searchParams = [])
22
    {
23
        $queryBuilder = $this->createQueryBuilder('e');
24
25
        if (!empty($searchParams)) {
26
27
            $searchAttributes = [
28
                'recipients',
29
                'template',
30
                'sent',
31
                'variables',
32
                'token'
33
            ];
34
35
            foreach ($searchAttributes as $attribute) {
36
                if (empty($searchParams[$attribute])) {
37
                    continue;
38
                }
39
40
                $attributeValue = $searchParams[$attribute];
41
42
                $queryBuilder->andWhere('e.'.$attribute.' LIKE :'.$attribute)
43
                    ->setParameter($attribute, '%'.$attributeValue.'%');
44
            }
45
        }
46
47
        $sentEmails = $queryBuilder->getQuery()->getResult();
48
        return $sentEmails;
49
    }
50
}
51