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

MyStudentController::operationWorkdayAction()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 11
Ratio 73.33 %

Importance

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