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 — master ( 946e53...2c9141 )
by Luis Ramón
16:58
created

VisitController::visitDeleteAction()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 31
Code Lines 20

Duplication

Lines 31
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 31
loc 31
rs 8.5806
cc 4
eloc 20
nc 4
nop 3
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\User;
24
use AppBundle\Entity\Visit;
25
use AppBundle\Entity\Workcenter;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
27
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
28
use Symfony\Component\HttpFoundation\Request;
29
use Symfony\Component\Routing\Annotation\Route;
30
31
/**
32
 * @Route("/visitas")
33
 * @Security("is_granted('ROLE_EDUCATIONAL_TUTOR')")
34
 */
35
class VisitController extends Controller
36
{
37
    /**
38
     * @Route("", name="visit_index", methods={"GET"})
39
     */
40 View Code Duplication
    public function teacherIndexAction()
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...
41
    {
42
        /** @var User $user */
43
        $user = $this->getUser();
44
        if ($this->isGranted('ROLE_ADMIN')) {
45
            $visits = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->getEducationalTutorsAgreementSummary();
46
        } elseif ($this->isGranted('ROLE_DEPARTMENT_HEAD')) {
47
            $visits = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->getEducationalTutorsByDepartmentsAgreementSummary($user->getDirects());
48
        } else {
49
            return $this->visitIndexAction($user);
50
        }
51
52
        return $this->render('visit/tutor_index.html.twig', [
53
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('visit_index'),
54
            'title' => null,
55
            'elements' => $visits
56
        ]);
57
    }
58
59
    /**
60
     * @Route("/{id}", name="visit_workcenter_index", methods={"GET"})
61
     * @Security("is_granted('USER_VISIT_TRACK', tutor)")
62
     */
63 View Code Duplication
    public function visitIndexAction(User $tutor)
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...
64
    {
65
        $workcenters = $this->getDoctrine()->getManager()->getRepository('AppBundle:Visit')->getRelatedVisits($tutor);
66
67
        $title = (string) $tutor;
68
69
        return $this->render('visit/visit_index.html.twig', [
70
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('visit_index'),
71
            'breadcrumb' => [
72
                ['fixed' => $title]
73
            ],
74
            'title' => $this->get('translator')->trans('browse.workcenter', ['%user%' => $title], 'visit'),
75
            'tutor' => $tutor,
76
            'elements' => $workcenters,
77
            'back_route_name' => $this->isGranted('ROLE_DEPARTMENT_HEAD') ? 'visit_index' : 'frontpage'
78
        ]);
79
    }
80
81
    /**
82
     * @Route("/{id}/resumen", name="visit_workcenter_summary_index", methods={"GET"})
83
     * @Security("is_granted('USER_VISIT_TRACK', tutor)")
84
     */
85
    public function visitWorkcenterSummaryAction(User $tutor)
86
    {
87
        $workcenters = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workcenter')->getVisitRelatedWorkcenters($tutor);
88
89
        $title = (string) $tutor;
90
91
        return $this->render('visit/workcenter_summary.html.twig', [
92
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('visit_index'),
93
            'breadcrumb' => [
94
                ['fixed' => $title, 'path' => 'visit_workcenter_index', 'options' => ['id' => $tutor->getId()]],
95
                ['fixed' => $this->get('translator')->trans('browse.summary', [], 'visit')]
96
            ],
97
            'title' => $this->get('translator')->trans('browse.workcenter', ['%user%' => $title], 'visit'),
98
            'tutor' => $tutor,
99
            'elements' => $workcenters,
100
            'back_route_name' => $this->isGranted('ROLE_DEPARTMENT_HEAD') ? 'visit_index' : 'frontpage'
101
        ]);
102
    }
103
    
104
    /**
105
     * @Route("/{id}/modificar/{visit}", name="visit_form", methods={"GET", "POST"})
106
     * @Security("is_granted('USER_VISIT_TRACK', tutor) and visit.getTutor() == tutor")
107
     */
108 View Code Duplication
    public function visitFormAction(User $tutor, Visit $visit, 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...
109
    {
110
        $form = $this->createForm('AppBundle\Form\Type\VisitType', $visit);
111
        $form->handleRequest($request);
112
113
        if ($form->isValid() && $form->isSubmitted()) {
114
            $this->getDoctrine()->getManager()->persist($visit);
115
            $this->getDoctrine()->getManager()->flush();
116
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'visit'));
117
            return $this->redirectToRoute('visit_workcenter_index', ['id' => $tutor->getId()]);
118
        }
119
        $title = $this->get('translator')->trans($visit->getId() ? 'form.view' : 'form.new', [], 'visit');
120
121
        return $this->render('visit/form_visit.html.twig', [
122
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('visit_index'),
123
            'breadcrumb' => [
124
                ['fixed' => (string) $tutor, 'path' => 'visit_workcenter_index', 'options' => ['id' => $tutor->getId()]],
125
                ['fixed' => $title]
126
            ],
127
            'title' => $title,
128
            'visit' => $visit,
129
            'form' => $form->createView(),
130
            'tutor' => $tutor
131
        ]);
132
    }
133
134
    /**
135
     * @Route("/{id}/eliminar/{visit}", name="visit_delete", methods={"GET", "POST"})
136
     * @Security("is_granted('USER_VISIT_TRACK', tutor) and visit.getTutor() == tutor")
137
     */
138 View Code Duplication
    public function visitDeleteAction(User $tutor, Visit $visit, 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...
139
    {
140
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
141
142
            $em = $this->getDoctrine()->getManager();
143
144
            // Eliminar la visita de la base de datos
145
            $em->remove($visit);
146
            try {
147
                $em->flush();
148
                $this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], 'visit'));
149
            } catch (\Exception $e) {
150
                $this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], 'visit'));
151
            }
152
            return $this->redirectToRoute('visit_workcenter_index', ['id' => $tutor->getId()]);
153
        }
154
155
        $title = $visit->getDate()->format('d/m/Y');
156
157
        return $this->render('visit/delete_visit.html.twig', [
158
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('visit_index'),
159
            'breadcrumb' => [
160
                ['fixed' => (string) $tutor, 'path' => 'visit_workcenter_index', 'options' => ['id' => $tutor->getId()]],
161
                ['fixed' => $title, 'path' => 'visit_form', 'options' => ['id' => $tutor->getId(), 'visit' => $visit->getId()]],
162
                ['fixed' => $this->get('translator')->trans('form.delete', [], 'visit')]
163
            ],
164
            'title' => $title,
165
            'tutor' => $tutor,
166
            'visit' => $visit
167
        ]);
168
    }
169
170
    /**
171
     * @Route("/{id}/registrar", name="visit_form_new", methods={"GET", "POST"})
172
     * @Security("is_granted('USER_VISIT_TRACK', tutor)")
173
     */
174
    public function visitNewAction(User $tutor, Request $request)
175
    {
176
        $visit = new Visit();
177
        $visit->setTutor($tutor);
178
        $visit->setDate(new \DateTime());
179
180
        return $this->visitFormAction($tutor, $visit, $request);
181
    }
182
}
183