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 — user-entity ( e0a2c2...8f70fe )
by Luis Ramón
03:27
created

UserRepository::countTrackedHours()   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\ORM\EntityRepository;
24
use Symfony\Component\Security\Core\User\UserInterface;
25
use Symfony\Component\Security\Core\User\UserProviderInterface;
26
27
class UserRepository extends EntityRepository implements UserProviderInterface
28
{
29
    public function loadUserByUsername($username) {
30
31
        if (!$username) {
32
            return null;
33
        }
34
        return $this->getEntityManager()
35
            ->createQuery('SELECT u FROM AppBundle:User u 
36
                           WHERE u.loginUsername = :username
37
                           OR u.email = :username')
38
            ->setParameters([
39
                'username' => $username
40
            ])
41
            ->getOneOrNullResult();
42
    }
43
44
    public function refreshUser(UserInterface $user) {
45
        return $this->loadUserByUsername($user->getUsername());
46
    }
47
48
    public function supportsClass($class) {
49
        return $class === 'AppBundle\Entity\User';
50
    }
51
52
    public function createNewUser()
53
    {
54
        $user = new User();
55
        $this->getEntityManager()->persist($user);
56
57
        return $user;
58
    }
59
60
    public function countAgreementHours(User $user)
61
    {
62
        return $this->getEntityManager()
63
            ->createQuery('SELECT SUM(w.hours) FROM AppBundle:Workday w INNER JOIN w.agreement a WHERE a.student = :user')
64
            ->setParameter('user', $user)
65
            ->getSingleScalarResult();
66
    }
67
68
    public function countTrackedHours(User $user)
69
    {
70
        return $this->getEntityManager()
71
            ->createQuery('SELECT SUM(t.hours) FROM AppBundle:Tracking t INNER JOIN AppBundle:Workday w INNER JOIN w.agreement a WHERE a.student = :user')
72
            ->setParameter('user', $user)
73
            ->getSingleScalarResult();
74
    }
75
76
    public function getAgreementRelatedStudents(User $user)
77
    {
78
        $em = $this->getEntityManager();
79
        return $em->createQuery('SELECT DISTINCT u,
80
              (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),
81
              (SELECT SUM(w3.hours) FROM AppBundle:Workday w3 INNER JOIN w3.agreement a3 WHERE a3.student = u)
82
              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')
83
            ->setParameter('user', $user)
84
            ->getResult();
85
    }
86
}
87