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 ( 6db575...67b804 )
by Luis Ramón
02:52
created

StudentController::studentWorkdayAction()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 49
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 49
rs 8.5906
cc 6
eloc 33
nc 2
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\Agreement;
24
use AppBundle\Entity\Tracking;
25
use AppBundle\Entity\User;
26
use AppBundle\Entity\Workday;
27
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
28
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
29
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
30
use Symfony\Component\HttpFoundation\Request;
31
32
class StudentController extends Controller
33
{
34
    /**
35
     * @Route("/estudiante/{id}", name="student_detail", methods={"GET", "POST"})
36
     * @Security("is_granted('ROLE_GROUP_ADMIN', student.getStudentGroup())")
37
     */
38
    public function studentIndexAction(User $student, Request $request)
39
    {
40
        $form = $this->createForm('AppBundle\Form\Type\StudentUserType', $student, [
41
            'admin' => $this->isGranted('ROLE_ADMIN')
42
        ]);
43
44
        $form->handleRequest($request);
45
46 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...
47
48
            // Guardar el usuario en la base de datos
49
50
            // Probar a guardar los cambios
51
            try {
52
                $this->getDoctrine()->getManager()->flush();
53
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'student'));
54
                return $this->redirectToRoute('admin_group_students', ['id' => $student->getStudentGroup()->getId()]);
55
            } catch (\Exception $e) {
56
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'student'));
57
            }
58
        }
59
        return $this->render('group/form_student.html.twig',
60
            [
61
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
62
                'breadcrumb' => [
63
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
64
                    ['fixed' => (string) $student],
65
                ],
66
                'title' => (string) $student,
67
                'user' => $student,
68
                'form' => $form->createView()
69
            ]);
70
    }
71
72
    /**
73
     * @Route("/seguimiento", name="student_calendar", methods={"GET"})
74
     * @Security("user.getStudentAgreements() !== null and user.getStudentAgreements().count() > 0")
75
     */
76
    public function studentCalendarIndexAction()
77
    {
78
        $agreements = $this->getUser()->getStudentAgreements();
79
80
        if (count($agreements) == 1) {
81
            return $this->studentCalendarAgreementIndexAction($agreements[0]);
82
        }
83
84
        return $this->render('student/calendar_agreement_select.html.twig',
85
            [
86
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('student_calendar'),
87
                'user' => $this->getUser(),
88
                'elements' => $agreements
89
            ]);
90
    }
91
92
    /**
93
     * @Route("/seguimiento/{id}", name="student_calendar_agreement", methods={"GET"})
94
     * @Security("is_granted('AGREEMENT_ACCESS', agreement) and user.getStudentAgreements() !== null and user.getStudentAgreements().count() > 0")
95
     */
96
    public function studentCalendarAgreementIndexAction(Agreement $agreement)
97
    {
98
        $calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($agreement->getWorkdays());
99
        $title = (string) $agreement->getWorkcenter();
100
101
        return $this->render('student/calendar_agreement.html.twig',
102
            [
103
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('student_calendar'),
104
                'breadcrumb' => [
105
                    ['fixed' => $title],
106
                ],
107
                'title' => $title,
108
                'user' => $this->getUser(),
109
                'calendar' => $calendar,
110
                'agreement' => $agreement
111
            ]);
112
    }
113
114
    /**
115
     * @Route("/seguimiento/ficha/{id}", name="student_tracking", methods={"GET", "POST"})
116
     * @Security("is_granted('AGREEMENT_ACCESS', workday.getAgreement()) and user.getStudentAgreements() !== null and user.getStudentAgreements().count() > 0")
117
     */
118
    public function studentWorkdayAction(Workday $workday, Request $request)
119
    {
120
        $agreementHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->countHours($workday->getAgreement());
121
122
        $dow = ((6 + (int) $workday->getDate()->format('w')) % 7);
123
        
124
        $title = $this->get('translator')->trans('dow' . $dow, [], 'calendar') . ', ' . $workday->getDate()->format('d/m/Y');
125
        $em = $this->getDoctrine()->getManager();
126
        $em->getRepository('AppBundle:Tracking')->updateTrackingByWorkday($workday);
127
128
        $form = $this->createForm('AppBundle\Form\Type\WorkdayTrackingType', $workday, [
129
            'disabled' => $workday->isLocked() && !$this->isGranted('ROLE_TEACHING_TUTOR')
130
        ]);
131
        $form->handleRequest($request);
132
133
        if ($form->isSubmitted() && $form->isValid()) {
134
            /** @var Tracking $tracking */
135
            foreach ($workday->getTrackingActivities() as $tracking) {
136
                if ($tracking->getHours() == 0) {
137
                    $workday->removeTrackingActivity($tracking);
138
                    $em->remove($tracking);
139
                } else {
140
                    $em->persist($tracking);
141
                }
142
            }
143
            $em->flush();
144
        }
145
146
        $activitiesStats = $em->getRepository('AppBundle:Agreement')->getActivitiesStats($workday->getAgreement());
147
        $next = $em->getRepository('AppBundle:Workday')->getNext($workday);
148
        $previous = $em->getRepository('AppBundle:Workday')->getPrevious($workday);
149
        
150
        return $this->render('student/tracking_form.html.twig',
151
            [
152
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('student_calendar'),
153
                'breadcrumb' => [
154
                    ['fixed' => (string) $workday->getAgreement()->getWorkcenter(), 'path' => 'student_calendar_agreement', 'options' => ['id' => $workday->getAgreement()->getId()]],
155
                    ['fixed' => $title],
156
                ],
157
                'title' => $title,
158
                'user' => $this->getUser(),
159
                'workday' => $workday,
160
                'form' => $form->createView(),
161
                'agreement_hours' => $agreementHours,
162
                'activities_stats' => $activitiesStats,
163
                'next' => $next,
164
                'previous' => $previous
165
            ]);
166
    }
167
}
168