findConPartesAunNoNotificadosPorUsuario()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
crap 2
1
<?php
2
/*
3
  GESTCONV - Aplicación web para la gestión de la convivencia en centros educativos
4
5
  Copyright (C) 2015: 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 AppBundle\Utils\RepositoryUtils;
24
use Doctrine\ORM\EntityRepository;
25
26
/**
27
 * AlumnoRepository
28
 *
29
 * Clase repositorio para añadir métodos adicionales
30
 */
31
class AlumnoRepository extends EntityRepository
32
{
33
    public function findConPartesAunNoNotificados()
34
    {
35
        return $this->getEntityManager()
36
            ->getRepository('AppBundle:Alumno')
37
            ->createQueryBuilder('a')
38
            ->innerJoin('AppBundle:Parte', 'p', 'WITH', 'p.alumno = a')
39
            ->where('p.fechaAviso IS NULL')
40
            ->orderBy('a.apellido1', 'ASC')
41
            ->addOrderBy('a.apellido2', 'ASC')
42
            ->addOrderBy('a.nombre', 'ASC');
43
    }
44
45 View Code Duplication
    public function findConPartesAunNoNotificadosPorUsuario(Usuario $usuario)
46
    {
47
        $orX = $this->getEntityManager()->createQueryBuilder()
48
            ->expr()->orX()
49
            ->add('p.usuario = :usuario')
50
            ->add('a.grupo = :grupo');
51
52
        return $this->findConPartesAunNoNotificados()
53
            ->innerJoin('AppBundle:Grupo', 'g', 'WITH', 'a.grupo = g')
54
            ->andWhere($orX)
55
            ->setParameter('grupo', $usuario->getTutoria())
56
            ->setParameter('usuario', $usuario);
57
    }
58
59
    public function findAllConPartesAunNoNotificados()
60
    {
61
        return $this->findConPartesAunNoNotificados()
62
            ->getQuery()
63
            ->getResult();
64
    }
65
66
    public function findAllConPartesAunNoNotificadosPorUsuario(Usuario $usuario)
67
    {
68
        return $this->findConPartesAunNoNotificadosPorUsuario($usuario)
69
            ->getQuery()
70
            ->getResult();
71
    }
72
73
    public function findAllConPartesPendientesSancion()
74
    {
75
        return $this->getEntityManager()
76
            ->getRepository('AppBundle:Parte')
77
            ->createQueryBuilder('p')
78
            ->select('a')
79
            ->addSelect('COUNT(p.id)')
80
            ->addSelect('MIN(p.fechaSuceso)')
81
            ->addSelect('MAX(p.fechaSuceso)')
82
            ->addSelect('SUM(p.prioritario)')
83
            ->innerJoin('AppBundle:Alumno', 'a')
84
            ->where('p.fechaAviso IS NOT NULL')
85
            ->andWhere('p.sancion IS NULL')
86
            ->andWhere('p.alumno = a')
87
            ->andWhere('p.prescrito = false')
88
            ->groupBy('a.id')
89
            ->orderBy('a.apellido1', 'ASC')
90
            ->addOrderBy('a.apellido2', 'ASC')
91
            ->addOrderBy('a.nombre', 'ASC')
92
            ->getQuery()
93
            ->getResult();
94
    }
95
96
    public function findConSancionesAunNoNotificadas()
97
    {
98
        return $this->getEntityManager()
99
            ->getRepository('AppBundle:Alumno')
100
            ->createQueryBuilder('a')
101
            ->leftJoin('a.partes', 'p')
102
            ->leftJoin('p.sancion', 's')
103
            ->where('s.fechaComunicado IS NULL')
104
            ->andWhere('s.motivosNoAplicacion IS NULL')
105
            ->andWhere('p.alumno = a')
106
            ->andWhere('p.sancion = s')
107
            ->orderBy('a.apellido1', 'ASC')
108
            ->addOrderBy('a.apellido2', 'ASC')
109
            ->addOrderBy('a.nombre', 'ASC');
110
    }
111
112
    public function findAllConSancionesAunNoNotificadas()
113
    {
114
        return $this->findConSancionesAunNoNotificadas()
115
            ->getQuery()
116
            ->getResult();
117
    }
118
119
    public function findAllConSancionesAunNoNotificadasPorTutoria($usuario)
120
    {
121
        return $this->findConSancionesAunNoNotificadas()
122
            ->join('a.grupo', 'g')
123
            ->andWhere('a.grupo = :grupo')
124
            ->setParameter('grupo', $usuario->getTutoria())
125
            ->getQuery()
126
            ->getResult();
127
    }
128
129
    public function getResumenConvivencia($tutor, $fechas)
130
    {
131
        $data = $this->getEntityManager()
132
            ->getRepository('AppBundle:Alumno')
133
            ->createQueryBuilder('a')
134
            ->select('a');
135
136
        $data = RepositoryUtils::resumenConvivencia($data, $fechas)
137
            ->leftJoin('AppBundle:Parte', 'p', 'WITH', 'p.alumno = a')
138
            ->leftJoin('AppBundle:Sancion', 's', 'WITH', 'p.sancion = s');
139
140
        if ($tutor) {
141
            $data = $data
142
                ->andWhere('a.grupo = :grupo')
143
                ->setParameter('grupo', $tutor->getTutoria());
144
        }
145
146
        $data = $data
147
            ->addOrderBy('a.apellido1')
148
            ->addOrderBy('a.apellido2')
149
            ->addOrderBy('a.nombre')
150
            ->groupBy('a.id')
151
            ->getQuery()
152
            ->getResult();
153
154
        return $data;
155
    }
156
157
    public function getSancionadosPorFecha($fechas)
158
    {
159
        $data = $this->getEntityManager()
160
            ->getRepository('AppBundle:Sancion')
161
            ->createQueryBuilder('s')
162
            ->select('s, p, a, g')
163
            ->addSelect('COUNT(p)')
164
            ->leftJoin('s.partes', 'p')
165
            ->leftJoin('p.alumno', 'a')
166
            ->leftJoin('a.grupo', 'g');
167
168
        if ($fechas['desde']) {
169
            $data = $data
170
                ->andWhere('s.fechaSancion >= :desde')
171
                ->setParameter('desde', $fechas['desde']);
172
        }
173
174
        if ($fechas['hasta']) {
175
            $data = $data
176
                ->andWhere('s.fechaSancion <= :hasta')
177
                ->setParameter('hasta', $fechas['hasta']);
178
        }
179
180
        $data = $data
181
            ->addOrderBy('a.apellido1')
182
            ->addOrderBy('a.apellido2')
183
            ->addOrderBy('a.nombre')
184
            ->groupBy('s.id')
185
            ->getQuery()
186
            ->getResult();
187
188
        return $data;
189
    }
190
}
191