GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AgreementRepository::getTutorizedAgreements()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
class AgreementRepository extends EntityRepository
8
{
9
    public function countHours(Agreement $agreement)
10
    {
11
        return $this->getEntityManager()
12
            ->createQuery('SELECT SUM(w.hours) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement')
13
            ->setParameter('agreement', $agreement)
14
            ->getSingleScalarResult();
15
    }
16
17 View Code Duplication
    public function getRealFromDate(Agreement $agreement)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
18
    {
19
        $date = $this->getEntityManager()
20
            ->createQuery('SELECT MIN(w.date) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement')
21
            ->setParameter('agreement', $agreement)
22
            ->getSingleScalarResult();
23
24
        return null === $date ?: new \DateTime($date);
25
    }
26
27 View Code Duplication
    public function getRealToDate(Agreement $agreement)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
28
    {
29
        $date = $this->getEntityManager()
30
            ->createQuery('SELECT MAX(w.date) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE w.agreement = :agreement')
31
            ->setParameter('agreement', $agreement)
32
            ->getSingleScalarResult();
33
34
        return null === $date ?: new \DateTime($date);
35
    }
36
37
    public function getActivitiesStats(Agreement $agreement)
38
    {
39
        $activities = $agreement->getActivities();
40
41
        $result = $this->getEntityManager()
42
            ->createQuery('SELECT a, SUM(CASE WHEN w.agreement = :agreement THEN t.hours ELSE 0 END), SUM(CASE WHEN w.agreement = :agreement THEN 1 ELSE 0 END) FROM AppBundle:Activity a LEFT JOIN AppBundle:Tracking t WITH t.activity = a.id LEFT JOIN AppBundle:Workday w WITH t.workday = w WHERE a.id IN (:activities) GROUP BY a.code, a.id')
43
            ->setParameter('agreement', $agreement)
44
            ->setParameter('activities', $activities)
45
            ->getResult();
46
47
        return $result;
48
    }
49
50
    public function delete(Agreement $agreement)
51
    {
52
        // borrar informe si estaba cumplimentado
53
        if ($agreement->getReport()) {
54
            $this->getEntityManager()->remove($agreement->getReport());
55
        }
56
57
        // borrar calendario
58
        foreach ($agreement->getWorkdays() as $workday) {
59
            $this->getEntityManager()->remove($workday);
60
        }
61
62
        // borrar actividades de plan de formación individualizado
63
        $agreement->getActivities()->clear();
64
65
        // borrar acuerdo
66
        $this->getEntityManager()->remove($agreement);
67
    }
68
69
    public function getTutorizedAgreements(User $student, User $user)
70
    {
71
        $em = $this->getEntityManager();
72
        return $em->createQuery('SELECT a FROM AppBundle:Agreement a WHERE a.student = :student AND (a.educationalTutor = :user OR a.workTutor = :user) ORDER BY a.fromDate, a.toDate')
73
            ->setParameter('user', $user)
74
            ->setParameter('student', $student)
75
            ->getResult();
76
77
    }
78
79 View Code Duplication
    public function getAgreementsByWorkcenterAndEducationalTutor(Workcenter $workcenter = null, User $tutor = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
80
    {
81
        if (null === $workcenter || null === $tutor) {
82
            return [];
83
        }
84
85
        $em = $this->getEntityManager();
86
        return $em->createQuery('SELECT a
87
              FROM AppBundle:Agreement a JOIN a.student s WHERE a.workcenter = :workcenter AND a.educationalTutor = :tutor ORDER BY a.quarter, s.lastName, s.firstName')
88
            ->setParameter('workcenter', $workcenter)
89
            ->setParameter('tutor', $tutor)
90
            ->getResult();
91
    }
92
93
    public function getAgreementsDateRangeByEducationalTutorAndQuarters(User $tutor = null, array $quarters = null)
94
    {
95
        if (null === $tutor) {
96
            return [];
97
        }
98
99 View Code Duplication
        if (null === $quarters) {
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...
100
            $quarters = [Agreement::FIRST_QUARTER, Agreement::SECOND_QUARTER, Agreement::THIRD_QUARTER];
101
        }
102
103
        $em = $this->getEntityManager();
104
        return $em->createQuery('SELECT MIN(a.fromDate), MAX(a.toDate)
105
              FROM AppBundle:Agreement a WHERE a.educationalTutor = :tutor AND a.quarter IN (:quarters)')
106
            ->setParameter('tutor', $tutor)
107
            ->setParameter('quarters', $quarters)
108
            ->getResult();
109
    }
110
111
}
112