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 ( 756135...7b3c84 )
by Luis Ramón
03:29
created

VisitController::visitFormAction()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 25
Code Lines 18

Duplication

Lines 6
Ratio 24 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 25
rs 8.5806
cc 4
eloc 18
nc 2
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
 * @Security("is_granted('ROLE_TEACHING_TUTOR')")
33
 */
34
class VisitController extends Controller
35
{
36
    /**
37
     * @Route("/visitas", name="visit_index", methods={"GET"})
38
     */
39
    public function teacherIndexAction()
40
    {
41
        /** @var User $user */
42
        $user = $this->getUser();
43
        if ($this->isGranted('ROLE_ADMIN')) {
44
            $visits = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->getEducationalTutors();
45
        } elseif ($this->isGranted('ROLE_DEPARTMENT_HEAD')) {
46
            $visits = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->getEducationalTutorsByDepartments($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("/visitas/{id}", name="visit_workcenter_index", methods={"GET"})
60
     * @Security("is_granted('USER_VISIT_TRACK', tutor)")
61
     */
62
    public function visitIndexAction(User $tutor)
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("/visitas/{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')->getVisitRelatedWorkcenters($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
            'elements' => $workcenters,
99
            'back_route_name' => $this->isGranted('ROLE_DEPARTMENT_HEAD') ? 'visit_index' : 'frontpage'
100
        ]);
101
    }
102
    
103
    /**
104
     * @Route("/visitas/{id}/modificar/{visit}", name="visit_form", methods={"GET", "POST"})
105
     * @Security("is_granted('USER_VISIT_TRACK', tutor) and visit.getTutor() == tutor")
106
     */
107
    public function visitFormAction(User $tutor, Visit $visit, Request $request)
108
    {
109
        $form = $this->createForm('AppBundle\Form\Type\VisitType', $visit);
110
        $form->handleRequest($request);
111
112 View Code Duplication
        if ($form->isValid() && $form->isSubmitted()) {
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...
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("/visitas/{id}/registrar", name="visit_form_new", methods={"GET", "POST"})
135
     * @Security("is_granted('USER_VISIT_TRACK', tutor)")
136
     */
137
    public function visitNewAction(User $tutor, Request $request)
138
    {
139
        $visit = new Visit();
140
        $visit->setTutor($tutor);
141
        $visit->setDate(new \DateTime());
142
143
        return $this->visitFormAction($tutor, $visit, $request);
144
    }
145
}
146