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 ( 3d1e73...9a0a1e )
by Luis Ramón
02:40
created

TrackingController::addAgreementCalendarAction()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 49
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 49
rs 8.7972
cc 4
eloc 33
nc 3
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\User;
25
use AppBundle\Entity\Workday;
26
use AppBundle\Form\Model\Calendar;
27
use Doctrine\Common\Collections\ArrayCollection;
28
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
29
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
30
use Symfony\Component\HttpFoundation\Request;
31
32
/**
33
 * @Route("/alumnado")
34
 * @Security("is_granted('ROLE_GROUP_TUTOR')")
35
 */
36
class TrackingController extends BaseController
37
{
38
    /**
39
     * @Route("/seguimiento/seleccion/{id}", name="admin_group_student_agreements", methods={"GET"})
40
     * @Security("is_granted('GROUP_MANAGE', student.getStudentGroup())")
41
     */
42
    public function studentAgreementIndexAction(User $student)
43
    {
44
        $agreements = $student->getStudentAgreements();
45
46
        return $this->render('group/calendar_agreement_select.html.twig',
47
            [
48
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
49
                'breadcrumb' => [
50
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
51
                    ['fixed' => (string) $student],
52
                ],
53
                'student' => $student,
54
                'elements' => $agreements,
55
                'route_name' => 'admin_group_student_calendar'
56
            ]);
57
    }
58
59
    /**
60
     * @Route("/seguimiento/acuerdo/{id}", name="admin_group_student_calendar", methods={"GET"})
61
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
62
     */
63
    public function studentCalendarAgreementIndexAction(Agreement $agreement)
64
    {
65
        $student = $agreement->getStudent();
66
67
        $calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($agreement->getWorkdays());
68
        $title = (string) $agreement;
69
70
        return $this->render('group/calendar_agreement.html.twig',
71
            [
72
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
73
                'breadcrumb' => [
74
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
75
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
76
                    ['fixed' => (string) $agreement->getWorkcenter()],
77
                ],
78
                'title' => $title,
79
                'user' => $this->getUser(),
80
                'calendar' => $calendar,
81
                'agreement' => $agreement,
82
                'route_name' => 'admin_group_student_tracking',
83
                'activities_stats' => $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getActivitiesStats($agreement)
84
            ]);
85
    }
86
87
    /**
88
     * @Route("/seguimiento/acuerdo/{id}/operacion", name="admin_group_student_workday_operation", methods={"POST"})
89
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
90
     */
91
    public function operationWorkdayAction(Agreement $agreement, Request $request)
92
    {
93
        if ($request->request->has('delete')) {
94
            return $this->deleteWorkdayAction($agreement, $request);
95
        }
96 View Code Duplication
        if ($request->request->has('week_lock') || $request->request->has('week_lock_print') || ($request->request->has('week_unlock'))) {
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...
97
            $this->lockWeekHelper($agreement, $request, !$request->request->has('week_unlock'));
98
            if ($request->request->has('week_lock_print')) {
99
                $data = $request->request->get('week_lock_print');
100
                $week = $data % 100;
101
                $year = intdiv($data, 100);
102
                return $this->redirectToRoute('my_student_weekly_report_download', ['id' => $agreement->getId(), 'week' => $week, 'year' => $year]);
103
            }
104
            return $this->redirectToRoute('admin_group_student_calendar', ['id' => $agreement->getId()]);
105
        }
106
        return $this->lockWorkdayAction($agreement, $request, $request->request->has('lock'), 'admin_group_student_calendar');
107
    }
108
109
    /**
110
     * @Route("/seguimiento/acuerdo/{id}/incorporar", name="admin_group_student_workday_add", methods={"GET", "POST"})
111
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
112
     */
113
    public function addAgreementCalendarAction(Agreement $agreement, Request $request)
114
    {
115
        $totalHours = $agreement->getStudent()->getStudentGroup()->getTraining()->getProgramHours();
116
        $agreementHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->countHours($agreement);
117
        $studentHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->countAgreementHours($agreement->getStudent());
118
119
        $calendar = new Calendar(max(0, $totalHours - $studentHours));
120
121
        $form = $this->createForm('AppBundle\Form\Type\CalendarType', $calendar, [
122
            'program_hours' => $totalHours
123
        ]);
124
125
        $form->handleRequest($request);
126
127
        $workdays = new ArrayCollection();
128
129
        if ($form->isSubmitted() && $form->isValid()) {
130
            $workdays = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->createCalendar($calendar, $agreement);
131
132
            if ($request->request->has('submit')) {
133
                $this->getDoctrine()->getManager()->flush();
134
                $agreement->setFromDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealFromDate($agreement));
135
                $agreement->setToDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealToDate($agreement));
136
                $this->getDoctrine()->getManager()->flush();
137
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar'));
138
                return $this->redirectToRoute('admin_group_student_calendar', ['id' => $agreement->getId()]);
139
            }
140
        }
141
142
        $student = $agreement->getStudent();
143
144
        $calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($workdays);
145
146
        return $this->render('group/calendar_agreement_workday_add.html.twig', [
147
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
148
            'breadcrumb' => [
149
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
150
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
151
                ['fixed' => (string) $agreement->getWorkcenter()],
152
                ['fixed' => $this->get('translator')->trans('form.add', [], 'calendar')]
153
            ],
154
            'agreement' => $agreement,
155
            'total_hours' => $totalHours,
156
            'agreement_hours' => $agreementHours,
157
            'student_hours' => $studentHours,
158
            'form' => $form->createView(),
159
            'calendar' => $calendar
160
        ]);
161
    }
162
163
    /**
164
     * @Route("/seguimiento/acuerdo/jornada/{id}", name="admin_group_student_tracking", methods={"GET", "POST"})
165
     * @Security("is_granted('AGREEMENT_ACCESS', workday.getAgreement())")
166
     */
167 View Code Duplication
    public function studentWorkdayAction(Workday $workday, 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...
168
    {
169
        $student = $workday->getAgreement()->getStudent();
170
171
        return $this->baseWorkdayAction($workday, $request, [
172
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
173
            'breadcrumb' => [
174
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
175
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
176
                ['fixed' => (string) $workday->getAgreement()->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
177
                ['fixed' => $workday->getDate()->format('d/m/Y')]
178
            ],
179
            'back_route_name' => 'admin_group_student_calendar'
180
        ]);
181
    }
182
183
    /**
184
     * @Route("/seguimiento/acuerdo/jornada/modificar/{id}", name="admin_group_student_workday_form", methods={"GET", "POST"})
185
     * @Security("is_granted('AGREEMENT_MANAGE', workday.getAgreement())")
186
     */
187
    public function agreementCalendarFormAction(Workday $workday, Request $request)
188
    {
189
        $form = $this->createForm('AppBundle\Form\Type\WorkdayType', $workday);
190
        $form->handleRequest($request);
191
192
        if ($form->isSubmitted() && $form->isValid()) {
193
            $this->getDoctrine()->getManager()->flush();
194
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar'));
195
            return $this->redirectToRoute('admin_group_student_calendar', ['id' => $workday->getAgreement()->getId()]);
196
        }
197
        $student = $workday->getAgreement()->getStudent();
198
199
        $dow = ((6 + (int) $workday->getDate()->format('w')) % 7);
200
        $title = $this->get('translator')->trans('dow' . $dow, [], 'calendar') . ', ' . $workday->getDate()->format('d/m/Y');
201
202
        return $this->render('group/calendar_agreement_workday_form.html.twig', [
203
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
204
            'breadcrumb' => [
205
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
206
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
207
                ['fixed' => (string) $workday->getAgreement()->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
208
                ['fixed' => $title],
209
            ],
210
            'form' => $form->createView(),
211
            'workday' => $workday
212
        ]);
213
    }
214
215
    /**
216
     * @Route("/seguimiento/acuerdo/nuevo/{id}", name="admin_group_student_agreement_new", methods={"GET", "POST"})
217
     * @Security("is_granted('GROUP_CREATE_AGREEMENT', student.getStudentGroup())")
218
     */
219
    public function agreementNewFormAction(User $student, Request $request)
220
    {
221
        $agreement = new Agreement();
222
        $agreement->setStudent($student);
223
        $this->getDoctrine()->getManager()->persist($agreement);
224
225
        return $this->agreementFormAction($agreement, $request);
226
    }
227
228
    /**
229
     * @Route("/seguimiento/acuerdo/modificar/{id}", name="admin_group_student_agreement_form", methods={"GET", "POST"})
230
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
231
     */
232
    public function agreementFormAction(Agreement $agreement, Request $request)
233
    {
234
        $form = $this->createForm('AppBundle\Form\Type\AgreementType', $agreement);
235
236
        $form->handleRequest($request);
237
238
        $student = $agreement->getStudent();
239
240
        if ($form->isSubmitted() && $form->isValid()) {
241
            // Probar a guardar los cambios
242
            try {
243
                $this->getDoctrine()->getManager()->flush();
244
                if ($request->request->has('report')) {
245
                    return $this->redirectToRoute('admin_group_teaching_program_report_download', ['id' => $agreement->getId()]);
246
                }
247
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'group'));
248
                return $this->redirectToRoute('admin_group_student_agreements', ['id' => $student->getId()]);
249
250
            } catch (\Exception $e) {
251
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'group'));
252
            }
253
        }
254
255
        $title = (null === $agreement->getId())
256
            ? $this->get('translator')->trans('form.new_agreement', [], 'group')
257
            : (string) $agreement->getWorkcenter();
258
259
        return $this->render('group/form_agreement.html.twig',
260
            [
261
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
262
                'breadcrumb' => [
263
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
264
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
265
                    ['fixed' => $title]
266
                ],
267
                'form' => $form->createView(),
268
                'agreement' => $agreement
269
            ]);
270
    }
271
272
    /**
273
     * @Route("/seguimiento/acuerdo/eliminar/{id}", name="admin_group_student_agreement_delete", methods={"GET", "POST"})
274
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
275
     */
276 View Code Duplication
    public function agreementDeleteAction(Agreement $agreement, 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...
277
    {
278
        $student = $agreement->getStudent();
279
280
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
281
282
            // Eliminar el acuerdo de la base de datos
283
            $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->delete($agreement);
284
            try {
285
                $this->getDoctrine()->getManager()->flush();
286
                $this->addFlash('success', $this->get('translator')->trans('alert.agreement_deleted', [], 'group'));
287
            } catch (\Exception $e) {
288
                $this->addFlash('error', $this->get('translator')->trans('alert.agreement_not_deleted', [], 'group'));
289
            }
290
            return $this->redirectToRoute('admin_group_student_agreements', ['id' => $student->getId()]);
291
        }
292
293
        $title = (string) $agreement->getWorkcenter();
294
295
        return $this->render('group/delete_agreement.html.twig', [
296
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
297
            'breadcrumb' => [
298
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
299
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
300
                ['fixed' => $title]
301
            ],
302
            'title' => $title,
303
            'agreement' => $agreement
304
        ]);
305
    }
306
307
    /**
308
     * @Route("/seguimiento/acuerdo/estudiante/{id}", name="admin_group_student_agreement_student_info", methods={"GET"})
309
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
310
     */
311
    public function agreementStudentDetailAction(Agreement $agreement)
312
    {
313
        $student = $agreement->getStudent();
314
        $form = $this->createForm('AppBundle\Form\Type\StudentUserType', $student, [
315
            'admin' => false,
316
            'disabled' => true
317
        ]);
318
319
        return $this->render('student/student_detail.html.twig',
320
            [
321
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
322
                'breadcrumb' => [
323
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
324
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
325
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
326
                    ['fixed' => $this->get('translator')->trans('student.detail', [], 'group')]
327
                ],
328
                'title' => (string) $student,
329
                'user' => $student,
330
                'agreement' => $agreement,
331
                'form' => $form->createView(),
332
                'back' => 'admin_group_student_calendar'
333
            ]);
334
    }
335
336
337
    /**
338
     * @Route("/seguimiento/acuerdo/centro/{id}", name="admin_group_student_agreement_workcenter_info", methods={"GET"})
339
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
340
     */
341
    public function workCenterDetailAction(Agreement $agreement)
342
    {
343
        $workcenter = $agreement->getWorkcenter();
344
        $student = $agreement->getStudent();
345
346
        $form = $this->createForm('AppBundle\Form\Type\WorkcenterType', $workcenter, [
347
            'disabled' => true
348
        ]);
349
350
        return $this->render('student/workcenter_detail.html.twig',
351
            [
352
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
353
                'breadcrumb' => [
354
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
355
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
356
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
357
                    ['fixed' => $this->get('translator')->trans('form.workcenter', [], 'company')]
358
                ],
359
                'title' => (string) $workcenter,
360
                'workcenter' => $workcenter,
361
                'agreement' => $agreement,
362
                'form' => $form->createView(),
363
                'back' => 'admin_group_student_calendar'
364
            ]);
365
    }
366
}
367