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 ( 0638d8...c8dbbd )
by Luis Ramón
09:14
created

MyStudentController::myStudentIndexAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
416
417
        $mpdf->useTwigTemplate('student/attendance_report.html.twig', [
418
            'agreement' => $agreement,
419
            'attendance' => $attendance,
420
            'title' => $title,
421
            'academic_year' => $this->getParameter('academic.year')
422
        ]);
423
424
        $title = str_replace(' ', '_', $title);
425
        return $mpdf->generateInlineFileResponse($title . '.pdf');
426
    }
427
}
428