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 — develop ( 3c014b...f94ec5 )
by Luis Ramón
05:10 queued 30s
created

GroupController::deleteWorkdayAction()   B

Complexity

Conditions 5
Paths 11

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 37
rs 8.439
cc 5
eloc 24
nc 11
nop 2
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\Controller;
22
23
use AppBundle\Entity\Group;
24
use AppBundle\Entity\User;
25
use Doctrine\ORM\EntityManager;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
27
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
28
use Symfony\Component\HttpFoundation\Request;
29
30
/**
31
 * @Route("/alumnado")
32
 * @Security("is_granted('ROLE_GROUP_TUTOR')")
33
 */
34
class GroupController extends BaseController
35
{
36
    /**
37
     * @Route("", name="admin_tutor_group", methods={"GET"})
38
     */
39
    public function groupIndexAction(Request $request)
40
    {
41
        /** @var EntityManager $em */
42
        $em = $this->getDoctrine()->getManager();
43
44
        /** @var User $user */
45
        $user = $this->getUser();
46
47
        $qb = $em->getRepository('AppBundle:Group')
48
            ->createQueryBuilder('g')
49
            ->innerJoin('g.training', 't')
50
            ->innerJoin('t.department', 'd')
51
            ->orderBy('d.name')
52
            ->addOrderBy('t.name')
53
            ->addOrderBy('g.name');
54
55
        if (!$user->isGlobalAdministrator()) {
56
            $qb = $qb
57
                ->where('g.id IN (:groups)')
58
                ->orWhere('d.head = :user')
59
                ->setParameter('groups', $user->getTutorizedGroups()->toArray())
60
                ->setParameter('user', $user);
61
        }
62
63
        $items = $qb->getQuery()->getResult();
64
65
        if (count($items) == 1) {
66
            return $this->groupDetailIndexAction($items[0], $request);
67
        }
68
69
        return $this->render('group/group_index.html.twig',
70
            [
71
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
72
                'title' => null,
73
                'elements' => $items
74
            ]);
75
    }
76
77
    /**
78
     * @Route("/grupo/{id}", name="admin_group_students", methods={"GET"})
79
     * @Security("is_granted('GROUP_MANAGE', group)")
80
     */
81 View Code Duplication
    public function groupDetailIndexAction(Group $group, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        /** @var EntityManager $em */
84
        $em = $this->getDoctrine()->getManager();
85
86
        $usersQuery = $em->createQuery('SELECT u FROM AppBundle:User u WHERE u.studentGroup = :group')
87
            ->setParameter('group', $group);
88
89
        $paginator = $this->get('knp_paginator');
90
        $pagination = $paginator->paginate(
91
            $usersQuery,
92
            $request->query->getInt('page', 1),
93
            $this->getParameter('page.size'),
94
            [
95
                'defaultSortFieldName' => 'u.lastName',
96
                'defaultSortDirection' => 'asc'
97
            ]
98
        );
99
100
        return $this->render('group/manage_students.html.twig', [
101
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
102
            'breadcrumb' => [
103
                ['fixed' => (string) $group],
104
            ],
105
            'title' => $group->getName(),
106
            'pagination' => $pagination
107
        ]);
108
109
    }
110
111
    /**
112
     * @Route("/alumnado/estudiante/{id}", name="student_detail", methods={"GET", "POST"})
113
     * @Security("is_granted('GROUP_MANAGE', student.getStudentGroup())")
114
     */
115
    public function studentIndexAction(User $student, Request $request)
116
    {
117
        $form = $this->createForm('AppBundle\Form\Type\StudentUserType', $student, [
118
            'admin' => $this->isGranted('ROLE_ADMIN')
119
        ]);
120
121
        $form->handleRequest($request);
122
123 View Code Duplication
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
125
            // Guardar el usuario en la base de datos
126
127
            // Probar a guardar los cambios
128
            try {
129
                $this->getDoctrine()->getManager()->flush();
130
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'student'));
131
                return $this->redirectToRoute('admin_group_students', ['id' => $student->getStudentGroup()->getId()]);
132
            } catch (\Exception $e) {
133
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'student'));
134
            }
135
        }
136
        return $this->render('group/form_student.html.twig',
137
            [
138
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
139
                'breadcrumb' => [
140
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
141
                    ['fixed' => (string) $student],
142
                ],
143
                'title' => (string) $student,
144
                'user' => $student,
145
                'form' => $form->createView()
146
            ]);
147
    }
148
}
149