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.

VisitController::visitWorkcenterSummaryAction()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

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