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.
Completed
Push — master ( 1078c4...9acd08 )
by Luis Ramón
02:46
created

UserRepository::getEducationalTutorsByStudent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2016: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Entity;
22
23
use Doctrine\Common\Collections\Collection;
24
use Doctrine\ORM\EntityRepository;
25
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
26
use Symfony\Component\Security\Core\User\UserInterface;
27
28
class UserRepository extends EntityRepository implements UserLoaderInterface
29
{
30
    public function loadUserByUsername($username) {
31
32
        if (!$username) {
33
            return null;
34
        }
35
        return $this->getEntityManager()
36
            ->createQuery('SELECT u FROM AppBundle:User u 
37
                           WHERE u.loginUsername = :username
38
                           OR u.email = :username')
39
            ->setParameters([
40
                'username' => $username
41
            ])
42
            ->getOneOrNullResult();
43
    }
44
45
    public function refreshUser(UserInterface $user) {
46
        return $this->loadUserByUsername($user->getUsername());
47
    }
48
49
    public function supportsClass($class) {
50
        return $class === 'AppBundle\Entity\User';
51
    }
52
53
    public function createNewUser()
54
    {
55
        $user = new User();
56
        $this->getEntityManager()->persist($user);
57
58
        return $user;
59
    }
60
61
    public function countAgreementHours(User $user)
62
    {
63
        return $this->getEntityManager()
64
            ->createQuery('SELECT SUM(w.hours) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE a.student = :user')
65
            ->setParameter('user', $user)
66
            ->getSingleScalarResult();
67
    }
68
69
    public function countTrackedHours(User $user)
70
    {
71
        return $this->getEntityManager()
72
            ->createQuery('SELECT SUM(t.hours) FROM AppBundle:Tracking t INNER JOIN AppBundle:Workday w INNER JOIN w.agreement a WHERE a.student = :user')
73
            ->setParameter('user', $user)
74
            ->getSingleScalarResult();
75
    }
76
77
    public function getAgreementRelatedStudents(User $user)
78
    {
79
        $em = $this->getEntityManager();
80
        return $em->createQuery('SELECT DISTINCT u,
81
              (SELECT SUM(t2.hours) FROM AppBundle:Tracking t2 INNER JOIN AppBundle:Workday w2 WITH t2.workday = w2 INNER JOIN w2.agreement a2 WITH w2.agreement = a2 WHERE a2.student = u),
82
              (SELECT SUM(w3.hours) FROM AppBundle:Workday w3 INNER JOIN w3.agreement a3 WHERE a3.student = u)
83
              FROM AppBundle:User u JOIN AppBundle:Agreement a WITH a.student = u WHERE a.educationalTutor = :user OR a.workTutor = :user ORDER BY u.lastName, u.firstName')
84
            ->setParameter('user', $user)
85
            ->getResult();
86
    }
87
88
    public function getEducationalTutorsAgreementSummary()
89
    {
90
        $em = $this->getEntityManager();
91
        return $em->createQuery('SELECT u,
92
              (SELECT COUNT(a1) FROM AppBundle:Agreement a1 WHERE a1.educationalTutor = u),
93
              (SELECT COUNT(DISTINCT a2.student) FROM AppBundle:Agreement a2 WHERE a2.educationalTutor = u)
94
              FROM AppBundle:User u WHERE u IN (SELECT DISTINCT IDENTITY(a.educationalTutor) FROM AppBundle:Agreement a) ORDER BY u.lastName, u.firstName')
95
            ->getResult();
96
    }
97
98
    public function getEducationalTutorsByStudent(User $student)
99
    {
100
        $em = $this->getEntityManager();
101
        return $em->createQuery('SELECT u FROM AppBundle:User u WHERE u IN (SELECT DISTINCT IDENTITY(a.educationalTutor) FROM AppBundle:Agreement a INNER JOIN a.educationalTutor u2 WITH a.educationalTutor = u2 WHERE a.student = :student) ORDER BY u.lastName, u.firstName')
102
            ->setParameter('student', $student)
103
            ->getResult();
104
    }
105
106
    public function getEducationalTutorsByDepartmentsAgreementSummary(Collection $departments)
107
    {
108
        $em = $this->getEntityManager();
109
        return $em->createQuery('SELECT u,
110
              (SELECT COUNT(a1) FROM AppBundle:Agreement a1 WHERE a1.educationalTutor = u),
111
              (SELECT COUNT(DISTINCT a2.student) FROM AppBundle:Agreement a2 WHERE a2.educationalTutor = u)
112
              FROM AppBundle:User u WHERE u IN (SELECT DISTINCT IDENTITY(a.educationalTutor) FROM AppBundle:Agreement a JOIN AppBundle:User s WITH a.student = s JOIN AppBundle:Group g WITH s.studentGroup = g JOIN AppBundle:Training t WITH g.training = t JOIN AppBundle:Department d WITH t.department = d WHERE d IN (:departments)) ORDER BY u.lastName, u.firstName')
113
            ->setParameter('departments', $departments)
114
            ->getResult();
115
    }
116
117
    public function getEducationalTutorsExpenseSummary()
118
    {
119
        $em = $this->getEntityManager();
120
        return $em->createQuery('SELECT u,
121
              (SELECT SUM(e1.distance) FROM AppBundle:Expense e1 WHERE e1.teacher = u),
122
              (SELECT SUM(e2.distance * e2.reviewed) FROM AppBundle:Expense e2 WHERE e2.teacher = u),
123
              (SELECT SUM(e3.distance * e3.paid) FROM AppBundle:Expense e3 WHERE e3.teacher = u)
124
              FROM AppBundle:User u WHERE u IN (SELECT DISTINCT IDENTITY(a.educationalTutor) FROM AppBundle:Agreement a) ORDER BY u.lastName, u.firstName')
125
            ->getResult();
126
    }
127
128
    public function getEducationalTutorsByDepartmentsExpenseSummary(Collection $departments)
129
    {
130
        $em = $this->getEntityManager();
131
        return $em->createQuery('SELECT u,
132
              (SELECT SUM(e1.distance) FROM AppBundle:Expense e1 WHERE e1.teacher = u),
133
              (SELECT SUM(e2.distance * e2.reviewed) FROM AppBundle:Expense e2 WHERE e2.teacher = u),
134
              (SELECT SUM(e3.distance * e3.paid) FROM AppBundle:Expense e3 WHERE e3.teacher = u)
135
              FROM AppBundle:User u WHERE u IN (SELECT DISTINCT IDENTITY(a.educationalTutor) FROM AppBundle:Agreement a JOIN AppBundle:User s WITH a.student = s JOIN AppBundle:Group g WITH s.studentGroup = g JOIN AppBundle:Training t WITH g.training = t JOIN AppBundle:Department d WITH t.department = d WHERE d IN (:departments)) ORDER BY u.lastName, u.firstName')
136
            ->setParameter('departments', $departments)
137
            ->getResult();
138
    }
139
140
    public function getStudentsByWorkcenterAndEducationalTutor(Workcenter $workcenter = null, User $tutor = null)
141
    {
142
        if (null === $workcenter || null === $tutor) {
143
            return [];
144
        }
145
146
        $em = $this->getEntityManager();
147
        return $em->createQuery('SELECT u
148
              FROM AppBundle:User u WHERE u IN (SELECT DISTINCT IDENTITY(a.student) FROM AppBundle:Agreement a WHERE a.workcenter = :workcenter AND a.educationalTutor = :tutor) ORDER BY u.lastName, u.firstName')
149
            ->setParameter('workcenter', $workcenter)
150
            ->setParameter('tutor', $tutor)
151
            ->getResult();
152
    }
153
}
154