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 ( 8bab74...824325 )
by Luis Ramón
02:22
created

downloadTeachingProgramReportAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 1
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_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
            return $this->lockWeekAction($agreement, $request, $request->request->has('week_lock'), 'my_student_agreement_calendar');
118
        }
119
        return $this->lockWorkdayAction($agreement, $request, $request->request->has('lock'), 'my_student_agreement_calendar');
120
    }
121
    /**
122
     * @Route("/estudiantes/seguimiento/jornada/{id}", name="my_student_agreement_tracking", methods={"GET", "POST"})
123
     * @Security("is_granted('AGREEMENT_ACCESS', workday.getAgreement())")
124
     */
125
    public function studentWorkdayAction(Workday $workday, Request $request)
126
    {
127
        $agreement = $workday->getAgreement();
128
        return $this->baseWorkdayAction($workday, $request, [
129
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
130
            'breadcrumb' => [
131
                ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
132
                ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'my_student_agreement_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
133
                ['fixed' => $workday->getDate()->format('d/m/Y')]
134
            ],
135
            'back_route_name' => 'my_student_agreement_calendar'
136
        ]);
137
    }
138
    
139
    /**
140
     * @Route("/estudiantes/informe/{id}", name="my_student_agreement_report_form", methods={"GET", "POST"})
141
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
142
     */
143
    public function studentReportAction(Agreement $agreement, Request $request)
144
    {
145
        $breadcrumb = [
146
            ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
147
            ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
148
            ['fixed' => $this->get('translator')->trans('form.report', [], 'student')]
149
        ];
150
151
        $routes = ['my_student_agreement_calendar', 'my_student_agreement_report_download'];
152
153
        return $this->workTutorReportAction($agreement, $request, $breadcrumb, $routes, 'student/report_form.html.twig');
154
    }
155
156
    /**
157
     * @Route("/alumnado/seguimiento/informe/descargar/{id}", name="admin_group_agreement_report_download", methods={"GET"})
158
     * @Route("/estudiantes/informe/descargar/{id}", name="my_student_agreement_report_download", methods={"GET"})
159
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
160
     */
161
    public function downloadStudentReportAction(Agreement $agreement)
162
    {
163
        $translator = $this->get('translator');
164
165
        $title = $translator->trans('form.report', [], 'student') . ' - ' . $agreement->getStudent();
166
167
        $mpdf = $this->get('sasedev_mpdf');
168
        $mpdf->init();
169
        $this->fillWorkingTutorReport($mpdf, $translator, $agreement, $title);
170
171
        $title = str_replace(' ', '_', $title);
172
        return $mpdf->generateInlineFileResponse($title . '.pdf');
173
    }
174
175
    /**
176
     * @Route("/estudiantes/ficha/descargar/{id}/{year}/{week}", name="my_student_weekly_report_download", methods={"GET"})
177
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
178
     */
179
    public function downloadWeeklyReportAction(Agreement $agreement, $year, $week)
180
    {
181
        /** @var EntityManager $em */
182
        $em = $this->getDoctrine()->getManager();
183
184
        $isLocked = $em->getRepository('AppBundle:Workday')->isWeekLocked($agreement, $week, $year);
185
186
        if (false === $isLocked) {
187
            $this->denyAccessUnlessGranted('AGREEMENT_LOCK', $agreement);
188
        }
189
190
        $weekDays = $em->getRepository('AppBundle:Workday')->getWorkdaysInWeek($agreement, $week, $year);
191
192
        if (0 === count($weekDays)) {
193
            throw $this->createNotFoundException();
194
        }
195
196
        $weekInfo = $em->getRepository('AppBundle:Workday')->getWeekInformation($weekDays[0]);
197
198
        $translator = $this->get('translator');
199
200
        $title = $translator->trans('form.weekly_report', [], 'student') . ' - ' . $agreement->getStudent() . ' - Semana ' . str_pad($weekInfo['current'], 2, '0', STR_PAD_LEFT);
201
202
        $mpdf = $this->get('sasedev_mpdf');
203
        $mpdf->init();
204
205
        $this->fillWeeklyReport($mpdf, $translator, $agreement, $weekDays, $title, $isLocked, $weekInfo);
206
207
        $title = str_replace(' ', '_', $title);
208
        return $mpdf->generateInlineFileResponse($title . '.pdf');
209
    }
210
211
    /**
212
     * @Route("/alumnado/seguimiento/programa/descargar/{id}", name="admin_group_teaching_program_report_download", methods={"GET"})
213
     * @Route("/estudiantes/programa/descargar/{id}", name="my_student_teaching_program_report_download", methods={"GET"})
214
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
215
     */
216
    public function downloadTeachingProgramReportAction(Agreement $agreement)
217
    {
218
        $translator = $this->get('translator');
219
220
        $title = $translator->trans('form.training_program', [], 'training_program_report') . ' - ' . $agreement->getStudent() . ' - ' . $agreement->getWorkcenter();
221
222
        $mpdf = $this->get('sasedev_mpdf');
223
        $mpdf->init('', 'A4-L');
224
225
        $obj = $mpdf->getMpdf();
226
        $obj->SetImportUse();
227
        $obj->SetDocTemplate('pdf/Programa_Formativo_seneca_vacio.pdf', true);
228
        $mpdf->useTwigTemplate('student/training_program_report.html.twig', [
229
            'agreement' => $agreement,
230
            'title' => $title,
231
            'learning_program' => $this->getDoctrine()->getRepository('AppBundle:LearningOutcome')->getLearningProgramFromAgreement($agreement)
232
        ]);
233
234
        $title = str_replace(' ', '_', $title);
235
        return $mpdf->generateInlineFileResponse($title . '.pdf');
236
    }
237
238
    /**
239
     * @Route("/alumnado/seguimiento/actividades/descargar/{id}", name="admin_group_activity_report_download", methods={"GET"})
240
     * @Route("/estudiantes/actividades/descargar/{id}", name="my_student_activity_report_download", methods={"GET"})
241
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
242
     */
243
    public function downloadActivityReportAction(Agreement $agreement)
244
    {
245
        $translator = $this->get('translator');
246
247
        $title = $translator->trans('form.activity_report', [], 'activity_report') . ' - ' . $agreement->getStudent();
248
249
        $mpdf = $this->get('sasedev_mpdf');
250
        $mpdf->init('', 'A4');
251
252
        $obj = $mpdf->getMpdf();
253
        $obj->SetImportUse();
254
        $obj->SetDocTemplate('pdf/A4_vacio.pdf', true);
255
256
        $agreements = $agreement->getStudent()->getStudentAgreements();
257
258
        $educationalTutors = [$agreement->getEducationalTutor()];
259
        $totalHours = $this->getDoctrine()->getRepository('AppBundle:User')->countAgreementHours($agreement->getStudent());
260
261
        $activities = [];
262
        $documentDate = null;
263
264
        /** @var Agreement $a */
265
        foreach($agreements as $a) {
266
            $activities[] = [$a, $this->getDoctrine()->getRepository('AppBundle:Agreement')->getActivitiesStats($a)];
267
            if (null === $documentDate || $a->getToDate() > $documentDate) {
268
                $documentDate = $a->getToDate();
269
            }
270
        }
271
272
        $mpdf->useTwigTemplate('student/activity_report.html.twig', [
273
            'agreement' => $agreement,
274
            'title' => $title,
275
            'activities' => $activities,
276
            'educational_tutors' => $educationalTutors,
277
            'total_hours' => $totalHours,
278
            'document_date' => $documentDate
279
        ]);
280
281
        $title = str_replace(' ', '_', $title);
282
        return $mpdf->generateInlineFileResponse($title . '.pdf');
283
    }
284
285
    /**
286
     * @Route("/estudiantes/detalle/{id}", name="my_student_detail", methods={"GET"})
287
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
288
     */
289 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...
290
    {
291
        $student = $agreement->getStudent();
292
        $form = $this->createForm('AppBundle\Form\Type\StudentUserType', $student, [
293
            'admin' => false,
294
            'disabled' => true
295
        ]);
296
297
        return $this->render('student/student_detail.html.twig',
298
            [
299
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
300
                'breadcrumb' => [
301
                    ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
302
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
303
                    ['fixed' => $this->get('translator')->trans('student.detail', [], 'group')]
304
                ],
305
                'title' => (string) $student,
306
                'user' => $student,
307
                'agreement' => $agreement,
308
                'form' => $form->createView()
309
            ]);
310
    }
311
312
    /**
313
     * @Route("/estudiantes/centro/{id}", name="workcenter_detail", methods={"GET"})
314
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
315
     */
316 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...
317
    {
318
        $workcenter = $agreement->getWorkcenter();
319
        $form = $this->createForm('AppBundle\Form\Type\WorkcenterType', $workcenter, [
320
            'disabled' => true
321
        ]);
322
323
        return $this->render('student/workcenter_detail.html.twig',
324
            [
325
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
326
                'breadcrumb' => [
327
                    ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
328
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
329
                    ['fixed' => $this->get('translator')->trans('form.workcenter', [], 'company')]
330
                ],
331
                'title' => (string) $workcenter,
332
                'workcenter' => $workcenter,
333
                'agreement' => $agreement,
334
                'form' => $form->createView()
335
            ]);
336
    }
337
}
338