1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Repository; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\DTO\Filter; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* FormRequestRepository. |
9
|
|
|
* |
10
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
11
|
|
|
* repository methods below. |
12
|
|
|
*/ |
13
|
|
|
class FormRequestRepository extends \Doctrine\ORM\EntityRepository |
14
|
|
|
{ |
15
|
|
|
public function selectRequestFormsByParams(Filter $filter) |
16
|
|
|
{ |
17
|
|
|
$query = $this->createQueryBuilder('f') |
18
|
|
|
->leftJoin('f.user', 'u') |
19
|
|
|
->orderBy('f.createdAt', 'DESC') |
20
|
|
|
; |
21
|
|
|
|
22
|
|
|
if ($filter->type && $filter->type != 'All') { |
23
|
|
|
$query->andWhere('f.type = ?1') |
24
|
|
|
->setParameter('1', $filter->type) |
25
|
|
|
; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if ($filter->decision && $filter->decision != 'All') { |
29
|
|
|
$query->andWhere('f.status = ?2') |
30
|
|
|
->setParameter('2', $filter->decision) |
31
|
|
|
; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
if ($filter->start && $filter->end) { |
|
|
|
|
35
|
|
|
$query->andWhere('f.createdAt BETWEEN ?3 AND ?4') |
36
|
|
|
->setParameter('3', $filter->getStart()) |
37
|
|
|
->setParameter('4', $filter->getEnd()) |
38
|
|
|
; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $query->getQuery(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function selectLastRequestForms() |
45
|
|
|
{ |
46
|
|
|
$query = $this->createQueryBuilder('r') |
47
|
|
|
->where('r.status = ?1') |
48
|
|
|
->setParameter('1', 'pending') |
49
|
|
|
->orderBy('r.updatedAt', "DESC") |
50
|
|
|
->setMaxResults(5); |
51
|
|
|
|
52
|
|
|
return $query->getQuery()->getResult(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.