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.

MyStudentController::attendanceForm()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 9.28
c 0
b 0
f 0
cc 3
nc 3
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\Agreement;
24
use AppBundle\Entity\User;
25
use AppBundle\Entity\Workday;
26
use AppBundle\Form\Model\Attendance;
27
use Doctrine\ORM\EntityManager;
28
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
29
use Symfony\Component\Form\FormInterface;
30
use Symfony\Component\HttpFoundation\Request;
31
use Symfony\Component\Routing\Annotation\Route;
32
33
class MyStudentController extends BaseController
34
{
35
    /**
36
     * @Route("/estudiantes", name="my_student_index", methods={"GET"})
37
     */
38
    public function myStudentIndexAction()
39
    {
40
        $users = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->getAgreementRelatedStudents($this->getUser());
41
42
        if (count($users) === 1) {
43
            return $this->myStudentAgreementIndexAction($users[0][0]);
44
        }
45
        return $this->render('student/index.html.twig', [
46
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
47
            'title' => null,
48
            'elements' => $users
49
        ]);
50
    }
51
52
    /**
53
     * @Route("/estudiantes/{id}", name="my_student_agreements", methods={"GET"})
54
     * @Security("is_granted('USER_TRACK', student)")
55
     */
56
    public function myStudentAgreementIndexAction(User $student)
57
    {
58
        $users = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->getAgreementRelatedStudents($this->getUser());
59
        $agreements = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getTutorizedAgreements($student, $this->getUser());
60
61
        if (count($agreements) == 1) {
62
            return $this->myStudentAgreementCalendarAction($agreements[0]);
63
        }
64
65
        $title = $student->getFullDisplayName();
66
        return $this->render('student/calendar_agreement_select.html.twig',
67
            [
68
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
69
                'breadcrumb' => [
70
                    ['fixed' => $title]
71
                ],
72
                'student' => $student,
73
                'title' => $title,
74
                'elements' => $agreements,
75
                'route_name' => 'my_student_agreement_calendar',
76
                'back_route_name' => count($users) === 1 ? 'frontpage' : 'my_student_index',
77
                'back_route_params' => [],
78
            ]);
79
    }
80
81
    /**
82
     * @Route("/estudiantes/seguimiento/{id}", name="my_student_agreement_calendar", methods={"GET"})
83
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
84
     */
85
    public function myStudentAgreementCalendarAction(Agreement $agreement)
86
    {
87
        $users = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->getAgreementRelatedStudents($this->getUser());
88
        $calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($agreement->getWorkdays());
89
        $agreements = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getTutorizedAgreements($agreement->getStudent(), $this->getUser());
90
        $title = (string) $agreement;
91
92
        $parent = (count($users) === 1 ? 'frontpage' : 'my_student_index');
93
94
        return $this->render('student/tutor_calendar_agreement.html.twig',
95
            [
96
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
97
                'breadcrumb' => [
98
                    ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
99
                    ['fixed' => (string) $agreement->getWorkcenter()],
100
                ],
101
                'title' => $title,
102
                'user' => $this->getUser(),
103
                'calendar' => $calendar,
104
                'agreement' => $agreement,
105
                'route_name' => 'my_student_agreement_tracking',
106
                'back_route_name' => count($agreements) === 1 ? $parent : 'my_student_agreements',
107
                'back_route_params' => count($agreements) === 1 ? [] : ['id' => $agreement->getStudent()->getId()],
108
                'activities_stats' => $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getActivitiesStats($agreement)
109
            ]);
110
    }
111
112
    /**
113
     * @Route("/estudiantes/seguimiento/{id}/operacion", name="my_student_agreement_calendar_operation", methods={"POST"})
114
     * @Security("is_granted('AGREEMENT_LOCK', agreement) or is_granted('AGREEMENT_UNLOCK', agreement)")
115
     */
116
    public function operationWorkdayAction(Agreement $agreement, Request $request)
117
    {
118 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...
119
            $this->lockWeekHelper($agreement, $request, !$request->request->has('week_unlock'));
120
121
            if ($request->request->has('week_lock_print')) {
122
                $data = $request->request->get('week_lock_print');
123
                $week = $data % 100;
124
                $year = intdiv($data, 100);
125
                return $this->redirectToRoute('my_student_weekly_report_download', ['id' => $agreement->getId(), 'week' => $week, 'year' => $year]);
126
            }
127
            $this->redirectToRoute('my_student_agreement_calendar', ['id' => $agreement->getId()]);
128
        }
129
        return $this->lockWorkdayAction($agreement, $request, $request->request->has('lock'), 'my_student_agreement_calendar');
130
    }
131
    /**
132
     * @Route("/estudiantes/seguimiento/jornada/{id}", name="my_student_agreement_tracking", methods={"GET", "POST"})
133
     * @Security("is_granted('AGREEMENT_ACCESS', workday.getAgreement())")
134
     */
135
    public function studentWorkdayAction(Workday $workday, Request $request)
136
    {
137
        $agreement = $workday->getAgreement();
138
        return $this->baseWorkdayAction($workday, $request, [
139
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
140
            'breadcrumb' => [
141
                ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
142
                ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'my_student_agreement_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
143
                ['fixed' => $workday->getDate()->format('d/m/Y')]
144
            ],
145
            'back_route_name' => 'my_student_agreement_calendar'
146
        ]);
147
    }
148
    
149
    /**
150
     * @Route("/estudiantes/informe/{id}", name="my_student_agreement_report_form", methods={"GET", "POST"})
151
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
152
     */
153
    public function studentReportAction(Agreement $agreement, Request $request)
154
    {
155
        $breadcrumb = [
156
            ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
157
            ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
158
            ['fixed' => $this->get('translator')->trans('form.report', [], 'student')]
159
        ];
160
161
        $routes = ['my_student_agreement_calendar', 'my_student_agreement_report_download'];
162
163
        return $this->workTutorReportAction($agreement, $request, $breadcrumb, $routes, 'student/report_form.html.twig');
164
    }
165
166
    /**
167
     * @Route("/alumnado/seguimiento/informe/descargar/{id}", name="admin_group_agreement_report_download", methods={"GET"})
168
     * @Route("/estudiantes/informe/descargar/{id}", name="my_student_agreement_report_download", methods={"GET"})
169
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
170
     */
171
    public function downloadStudentReportAction(Agreement $agreement)
172
    {
173
        $translator = $this->get('translator');
174
175
        $title = $translator->trans('form.report', [], 'student') . ' - ' . $agreement->getStudent();
176
177
        $mpdf = $this->get('sasedev_mpdf');
178
        $mpdf->init();
179
        $this->fillWorkingTutorReport($mpdf, $translator, $agreement, $title);
180
181
        $title = str_replace(' ', '_', $title);
182
        return $mpdf->generateInlineFileResponse($title . '.pdf');
183
    }
184
185
    /**
186
     * @Route("/estudiantes/ficha/descargar/{id}/{year}/{week}", name="my_student_weekly_report_download", methods={"GET"})
187
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
188
     */
189
    public function downloadWeeklyReportAction(Agreement $agreement, $year, $week)
190
    {
191
        /** @var EntityManager $em */
192
        $em = $this->getDoctrine()->getManager();
193
194
        $isLocked = $em->getRepository('AppBundle:Workday')->isWeekLocked($agreement, $week, $year);
195
196
        if (false === $isLocked) {
197
            $this->denyAccessUnlessGranted('AGREEMENT_LOCK', $agreement);
198
        }
199
200
        $weekDays = $em->getRepository('AppBundle:Workday')->getWorkdaysInWeek($agreement, $week, $year);
201
202
        if (0 === count($weekDays)) {
203
            throw $this->createNotFoundException();
204
        }
205
206
        $weekInfo = $em->getRepository('AppBundle:Workday')->getWeekInformation($weekDays[0]);
207
208
        $translator = $this->get('translator');
209
210
        $title = $translator->trans('form.weekly_report', [], 'student') . ' - ' . $agreement->getStudent() . ' - Semana ' . str_pad($weekInfo['current'], 2, '0', STR_PAD_LEFT);
211
212
        $mpdf = $this->get('sasedev_mpdf');
213
        $mpdf->init();
214
215
        $this->fillWeeklyReport($mpdf, $translator, $agreement, $weekDays, $title, $isLocked, $weekInfo);
216
217
        $title = str_replace(' ', '_', $title);
218
        return $mpdf->generateInlineFileResponse($title . '.pdf');
219
    }
220
221
    /**
222
     * @Route("/alumnado/seguimiento/programa/descargar/{id}", name="admin_group_teaching_program_report_download", methods={"GET"})
223
     * @Route("/estudiantes/programa/descargar/{id}", name="my_student_teaching_program_report_download", methods={"GET"})
224
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
225
     */
226 View Code Duplication
    public function downloadTeachingProgramReportAction(Agreement $agreement)
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...
227
    {
228
        $translator = $this->get('translator');
229
230
        $title = $translator->trans('form.training_program', [], 'training_program_report') . ' - ' . $agreement->getStudent() . ' - ' . $agreement->getWorkcenter();
231
232
        $mpdf = $this->get('sasedev_mpdf');
233
        $mpdf->init('', 'A4-L');
234
235
        $obj = $mpdf->getMpdf();
236
        $obj->SetImportUse();
237
        $obj->SetDocTemplate('pdf/Programa_Formativo_seneca_vacio.pdf', true);
238
        $mpdf->useTwigTemplate('student/training_program_report.html.twig', [
239
            'agreement' => $agreement,
240
            'title' => $title,
241
            'learning_program' => $this->getDoctrine()->getRepository('AppBundle:LearningOutcome')->getLearningProgramFromAgreement($agreement),
242
            'academic_year' => $this->getParameter('academic.year')
243
        ]);
244
245
        $title = str_replace(' ', '_', $title);
246
        return $mpdf->generateInlineFileResponse($title . '.pdf');
247
    }
248
249
    /**
250
     * @Route("/alumnado/seguimiento/actividades/descargar/{id}", name="admin_group_activity_report_download", methods={"GET"})
251
     * @Route("/estudiantes/actividades/descargar/{id}", name="my_student_activity_report_download", methods={"GET"})
252
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
253
     */
254
    public function downloadActivityReportAction(Agreement $agreement)
255
    {
256
        $translator = $this->get('translator');
257
258
        $title = $translator->trans('form.activity_report', [], 'activity_report') . ' - ' . $agreement->getStudent();
259
260
        $mpdf = $this->get('sasedev_mpdf');
261
        $mpdf->init('', 'A4');
262
263
        $obj = $mpdf->getMpdf();
264
        $obj->SetImportUse();
265
        $obj->SetDocTemplate('pdf/A4_vacio.pdf', true);
266
267
        $agreements = $agreement->getStudent()->getStudentAgreements();
268
269
        $educationalTutors = [$agreement->getEducationalTutor()];
270
        $totalHours = $this->getDoctrine()->getRepository('AppBundle:User')->countAgreementHours($agreement->getStudent());
271
272
        $activities = [];
273
        $documentDate = null;
274
275
        /** @var Agreement $a */
276
        foreach ($agreements as $a) {
277
            $activities[] = [$a, $this->getDoctrine()->getRepository('AppBundle:Agreement')->getActivitiesStats($a)];
278
            if (null === $documentDate || $a->getToDate() > $documentDate) {
279
                $documentDate = $a->getToDate();
280
            }
281
        }
282
283
        $mpdf->useTwigTemplate('student/activity_report.html.twig', [
284
            'agreement' => $agreement,
285
            'title' => $title,
286
            'activities' => $activities,
287
            'educational_tutors' => $educationalTutors,
288
            'total_hours' => $totalHours,
289
            'document_date' => $documentDate,
290
            'academic_year' => $this->getParameter('academic.year')
291
        ]);
292
293
        $title = str_replace(' ', '_', $title);
294
        return $mpdf->generateInlineFileResponse($title . '.pdf');
295
    }
296
297
    /**
298
     * @Route("/estudiantes/detalle/{id}", name="my_student_detail", methods={"GET"})
299
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
300
     */
301
    public function myStudentDetailAction(Agreement $agreement)
302
    {
303
        $student = $agreement->getStudent();
304
        $form = $this->createForm('AppBundle\Form\Type\StudentUserType', $student, [
305
            'admin' => false,
306
            'disabled' => true
307
        ]);
308
309
        return $this->render('student/student_detail.html.twig',
310
            [
311
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
312
                'breadcrumb' => [
313
                    ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
314
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'my_student_agreement_calendar', 'options' => ['id' => $agreement->getId()]],
315
                    ['fixed' => $this->get('translator')->trans('student.detail', [], 'group')]
316
                ],
317
                'title' => (string) $student,
318
                'user' => $student,
319
                'agreement' => $agreement,
320
                'form' => $form->createView(),
321
                'back' => 'my_student_agreement_calendar'
322
            ]);
323
    }
324
325
    /**
326
     * @Route("/estudiantes/centro/{id}", name="workcenter_detail", methods={"GET"})
327
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
328
     */
329
    public function workCenterDetailAction(Agreement $agreement)
330
    {
331
        $workcenter = $agreement->getWorkcenter();
332
        $form = $this->createForm('AppBundle\Form\Type\WorkcenterType', $workcenter, [
333
            'disabled' => true
334
        ]);
335
        $form2 = $this->createForm('AppBundle\Form\Type\WorkTutorType', $agreement->getWorkTutor(), [
336
            'disabled' => true
337
        ]);
338
339
        return $this->render('student/workcenter_detail.html.twig',
340
            [
341
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
342
                'breadcrumb' => [
343
                    ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
344
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'my_student_agreement_calendar', 'options' => ['id' => $agreement->getId()]],
345
                    ['fixed' => $this->get('translator')->trans('form.workcenter', [], 'company')]
346
                ],
347
                'title' => (string) $workcenter,
348
                'agreement' => $agreement,
349
                'form' => $form->createView(),
350
                'form2' => $form2->createView(),
351
                'back' => 'my_student_agreement_calendar'
352
            ]);
353
    }
354
355
    private function attendanceForm(Request $request, Agreement $agreement, FormInterface $form)
356
    {
357
        $title = $this->get('translator')->trans('form.attendance_report', [], 'student');
358
359
        $routeName = $request->get('_route');
360
        if ($routeName === 'admin_group_attendance_report') {
361
            $breadcrumb = [
362
                ['fixed' => $agreement->getStudent()->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $agreement->getStudent()->getStudentGroup()->getId()]],
363
                ['fixed' => (string) $agreement->getStudent(), 'path' => 'admin_group_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
364
                ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
365
                ['fixed' => $title]
366
            ];
367
            $menuItem = $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group');
368
            $backRoute = 'admin_group_student_calendar';
369
        } elseif ($routeName === 'my_student_attendance_report') {
370
            $breadcrumb = [
371
                ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
372
                ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'my_student_agreement_calendar', 'options' => ['id' => $agreement->getId()]],
373
                ['fixed' => $title]
374
            ];
375
            $menuItem = $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index');
376
            $backRoute = 'my_student_agreement_calendar';
377
        } else {
378
            $breadcrumb = [
379
                ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'student_calendar_agreement', 'options' => ['id' => $agreement->getId()]],
380
                ['fixed' => $title]
381
            ];
382
            $menuItem = $this->get('app.menu_builders_chain')->getMenuItemByRouteName('student_calendar');
383
            $backRoute = 'student_calendar_agreement';
384
        }
385
        return $this->render('student/attendance.html.twig',
386
            [
387
                'menu_item' => $menuItem,
388
                'breadcrumb' => $breadcrumb,
389
                'title' => (string) $title,
390
                'agreement' => $agreement,
391
                'form' => $form->createView(),
392
                'back' => $backRoute
393
            ]);
394
    }
395
396
    /**
397
     * @Route("/alumnado/seguimiento/asistencia/{id}", name="admin_group_attendance_report", methods={"GET"})
398
     * @Route("/estudiantes/asistencia/{id}", name="my_student_attendance_report", methods={"GET"})
399
     * @Route("/asistencia/{id}", name="attendance_report", methods={"GET"})
400
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
401
     */
402
    public function attendanceReportAction(Request $request, Agreement $agreement)
403
    {
404
        $form = $this->createForm('AppBundle\Form\Type\AttendanceType', new Attendance());
405
406
        return $this->attendanceForm($request, $agreement, $form);
407
    }
408
409
    /**
410
     * @Route("/alumnado/seguimiento/asistencia/{id}", name="admin_group_attendance_report_download", methods={"POST"})
411
     * @Route("/estudiantes/asistencia/{id}", name="my_student_attendance_report_download", methods={"POST"})
412
     * @Route("/asistencia/{id}", name="attendance_report_download", methods={"POST"})
413
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
414
     */
415
    public function downloadAttendanceReportAction(Request $request, Agreement $agreement)
416
    {
417
        $attendance = new Attendance();
418
        $form = $this->createForm('AppBundle\Form\Type\AttendanceType', $attendance);
419
        $form->handleRequest($request);
420
421
        if ($form->isSubmitted() && $form->isValid()) {
422
            $translator = $this->get('translator');
423
424
            $title = $translator->trans('report.title', [], 'attendance_report') . ' - ' . $agreement->getStudent();
425
426
            $mpdf = $this->get('sasedev_mpdf');
427
            $mpdf->init('', 'A4-L');
428
429
            $obj = $mpdf->getMpdf();
430
            $obj->SetImportUse();
431
            $obj->SetDocTemplate('pdf/Modelo_de_acreditacion_de_asistencia_a_la_empresa_FCT_vacio.pdf', true);
432
433
            $mpdf->useTwigTemplate('student/attendance_report.html.twig', [
434
                'agreement' => $agreement,
435
                'attendance' => $attendance,
436
                'title' => $title,
437
                'academic_year' => $this->getParameter('academic.year')
438
            ]);
439
440
            $title = str_replace(' ', '_', $title);
441
            return $mpdf->generateInlineFileResponse($title . '.pdf');
442
        } else {
443
            return $this->attendanceForm($request, $agreement, $form);
444
        }
445
    }
446
}
447