RepositoryUtils::resumenConvivencia()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 24
cp 0
rs 8.8571
cc 3
eloc 20
nc 4
nop 2
crap 12
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\Utils;
22
23
use Doctrine\ORM\QueryBuilder;
24
25
class RepositoryUtils {
26
27
    static public function resumenConvivencia(QueryBuilder $qb, $fechas)
28
    {
29
        $data = $qb
30
            ->addSelect('COUNT(p.id)')
31
            ->addSelect('COUNT(p.fechaAviso)')
32
            ->addSelect('COUNT(DISTINCT s.id)')
33
            ->addSelect('COUNT(s.fechaComunicado)')
34
            ->addSelect('COUNT(s.motivosNoAplicacion)')
35
            ->addSelect('COUNT(DISTINCT s.fechaInicioSancion)')
36
            ->addSelect('SUM(p.prescrito)')
37
            ->addSelect('MAX(p.fechaSuceso)')
38
            ->addSelect('MAX(s.fechaSancion)');
39
40
        if ($fechas['desde']) {
41
            $data = $data
42
                ->andWhere('p.fechaSuceso >= :desde')
43
                ->setParameter('desde', $fechas['desde']);
44
        }
45
46
        if ($fechas['hasta']) {
47
            $data = $data
48
                ->andWhere('p.fechaSuceso <= :hasta')
49
                ->setParameter('hasta', $fechas['hasta']);
50
        }
51
52
        return $data;
53
    }
54
}
55