Completed
Push — dev ( f52950...8c0d10 )
by
unknown
05:00 queued 04:55
created

SurveyRepository::selectLastSurveys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AppBundle\Repository;
4
5
use AppBundle\Entity\DTO\SurveyFilter;
6
use AppBundle\Entity\Survey\Survey;
7
8
/**
9
 * SurveyRepository.
10
 *
11
 * This class was generated by the Doctrine ORM. Add your own custom
12
 * repository methods below.
13
 */
14
class SurveyRepository extends \Doctrine\ORM\EntityRepository
15
{
16
    public function selectSurveysByParams($filter)
17
    {
18
        $query = $this->createQueryBuilder('Surveys')
19
            ->select('s, t, u')
20
            ->from('AppBundle:Survey\Survey', 's')
21
            ->join('s.type', 't')
22
            ->join('s.user', 'u')
23
            ->where('s.status = ?1')
24
            ->setParameter('1', 'submitted')
25
            ->orderBy('s.updatedAt', 'DESC');
26
27
        if ($filter->type && $filter->type != 'All') {
28
            $query->andWhere('t.name = ?2')
29
                ->setParameter('2', $filter->type)
30
            ;
31
        }
32
33 View Code Duplication
        if ($filter->start && $filter->end) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
34
            $query->andWhere('s.createdAt BETWEEN ?3 AND ?4')
35
                ->setParameter('3', $filter->getStart())
36
                ->setParameter('4', $filter->getEnd());
37
        }
38
39
        return $query->getQuery()->getResult();
40
    }
41
42
    public function selectLastSurveys()
43
    {
44
        $query = $this->createQueryBuilder('s')
45
            ->where('s.status = ?1')
46
            ->setParameter('1', 'submitted')
47
            ->orderBy('s.updatedAt', "DESC")
48
            ->setMaxResults(5);
49
50
        return $query->getQuery()->getResult();
51
    }
52
53 2
    public function findSurveyByUser($user)
54
    {
55 2
        $query = $this->createQueryBuilder('s')
56 2
            ->where('s.user = :user')
57 2
            ->setParameter('user', $user)
58 2
            ->orderBy('s.updatedAt', 'DESC')
59 2
            ->getQuery();
60
61 2
        return $query->getResult();
62
    }
63
}
64