|
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\Component\Security\Core\User\UserInterface; |
|
26
|
|
|
use Symfony\Component\Security\Core\User\UserProviderInterface; |
|
27
|
|
|
|
|
28
|
|
|
class UserRepository extends EntityRepository implements UserProviderInterface |
|
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 getEducationalTutorsByDepartmentsAgreementSummary(Collection $departments) |
|
99
|
|
|
{ |
|
100
|
|
|
$em = $this->getEntityManager(); |
|
101
|
|
|
return $em->createQuery('SELECT u, |
|
102
|
|
|
(SELECT COUNT(a1) FROM AppBundle:Agreement a1 WHERE a1.educationalTutor = u), |
|
103
|
|
|
(SELECT COUNT(DISTINCT a2.student) FROM AppBundle:Agreement a2 WHERE a2.educationalTutor = u) |
|
104
|
|
|
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') |
|
105
|
|
|
->setParameter('departments', $departments) |
|
106
|
|
|
->getResult(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getEducationalTutorsExpenseSummary() |
|
110
|
|
|
{ |
|
111
|
|
|
$em = $this->getEntityManager(); |
|
112
|
|
|
return $em->createQuery('SELECT u, |
|
113
|
|
|
(SELECT SUM(e1.distance) FROM AppBundle:Expense e1 WHERE e1.teacher = u), |
|
114
|
|
|
(SELECT SUM(e2.distance * e2.reviewed) FROM AppBundle:Expense e2 WHERE e2.teacher = u), |
|
115
|
|
|
(SELECT SUM(e3.distance * e3.paid) FROM AppBundle:Expense e3 WHERE e3.teacher = u) |
|
116
|
|
|
FROM AppBundle:User u WHERE u IN (SELECT DISTINCT IDENTITY(a.educationalTutor) FROM AppBundle:Agreement a) ORDER BY u.lastName, u.firstName') |
|
117
|
|
|
->getResult(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function getEducationalTutorsByDepartmentsExpenseSummary(Collection $departments) |
|
121
|
|
|
{ |
|
122
|
|
|
$em = $this->getEntityManager(); |
|
123
|
|
|
return $em->createQuery('SELECT u, |
|
124
|
|
|
(SELECT SUM(e1.distance) FROM AppBundle:Expense e1 WHERE e1.teacher = u), |
|
125
|
|
|
(SELECT SUM(e2.distance * e2.reviewed) FROM AppBundle:Expense e2 WHERE e2.teacher = u), |
|
126
|
|
|
(SELECT SUM(e3.distance * e3.paid) FROM AppBundle:Expense e3 WHERE e3.teacher = u) |
|
127
|
|
|
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') |
|
128
|
|
|
->setParameter('departments', $departments) |
|
129
|
|
|
->getResult(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getStudentsByWorkcenterAndEducationalTutor(Workcenter $workcenter = null, User $tutor = null) |
|
133
|
|
|
{ |
|
134
|
|
|
if (null === $workcenter || null === $tutor) { |
|
135
|
|
|
return []; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
$em = $this->getEntityManager(); |
|
139
|
|
|
return $em->createQuery('SELECT u |
|
140
|
|
|
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') |
|
141
|
|
|
->setParameter('workcenter', $workcenter) |
|
142
|
|
|
->setParameter('tutor', $tutor) |
|
143
|
|
|
->getResult(); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|