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 ( 0c8258...8d1f3d )
by Luis Ramón
24:24 queued 21:31
created

MyStudentController::downloadWeeklyReportAction()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 4
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 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
        if ($request->request->has('week_lock') || ($request->request->has('week_unlock'))) {
117
            return $this->lockWeekAction($agreement, $request, $request->request->has('week_lock'), 'my_student_agreement_calendar');
118
        } else {
119
            return $this->lockWorkdayAction($agreement, $request, $request->request->has('lock'), 'my_student_agreement_calendar');
120
        }
121
    }
122
    /**
123
     * @Route("/estudiantes/seguimiento/jornada/{id}", name="my_student_agreement_tracking", methods={"GET", "POST"})
124
     * @Security("is_granted('AGREEMENT_ACCESS', workday.getAgreement())")
125
     */
126
    public function studentWorkdayAction(Workday $workday, Request $request)
127
    {
128
        $agreement = $workday->getAgreement();
129
        return $this->baseWorkdayAction($workday, $request, [
130
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('my_student_index'),
131
            'breadcrumb' => [
132
                ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
133
                ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'my_student_agreement_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
134
                ['fixed' => $workday->getDate()->format('d/m/Y')]
135
            ],
136
            'back_route_name' => 'my_student_agreement_calendar'
137
        ]);
138
    }
139
    
140
    /**
141
     * @Route("/estudiantes/informe/{id}", name="my_student_agreement_report_form", methods={"GET", "POST"})
142
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
143
     */
144
    public function studentReportAction(Agreement $agreement, Request $request)
145
    {
146
        $breadcrumb = [
147
            ['fixed' => $agreement->getStudent()->getFullDisplayName(), 'path' => 'my_student_agreements', 'options' => ['id' => $agreement->getStudent()->getId()]],
148
            ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
149
            ['fixed' => $this->get('translator')->trans('form.report', [], 'student')]
150
        ];
151
152
        $routes = ['my_student_agreement_calendar', 'my_student_agreement_report_download'];
153
154
        return $this->workTutorReportAction($agreement, $request, $breadcrumb, $routes, 'student/report_form.html.twig');
155
    }
156
157
    /**
158
     * @Route("/alumnado/seguimiento/informe/descargar/{id}", name="admin_group_agreement_report_download", methods={"GET"})
159
     * @Route("/estudiantes/informe/descargar/{id}", name="my_student_agreement_report_download", methods={"GET"})
160
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
161
     */
162
    public function downloadStudentReportAction(Agreement $agreement)
163
    {
164
        $translator = $this->get('translator');
165
166
        $title = $translator->trans('form.report', [], 'student') . ' - ' . $agreement->getStudent();
167
168
        $mpdf = $this->get('sasedev_mpdf');
169
        $mpdf->init();
170
        $this->fillWorkingTutorReport($mpdf, $translator, $agreement, $title);
171
172
        $title = str_replace(' ', '_', $title);
173
        return $mpdf->generateInlineFileResponse($title . '.pdf');
174
    }
175
176
    /**
177
     * @Route("/estudiantes/ficha/descargar/{id}/{year}/{week}", name="my_student_weekly_report_download", methods={"GET"})
178
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
179
     */
180
    public function downloadWeeklyReportAction(Agreement $agreement, $year, $week)
181
    {
182
        /** @var EntityManager $em */
183
        $em = $this->getDoctrine()->getManager();
184
185
        $isLocked = $em->getRepository('AppBundle:Workday')->isWeekLocked($agreement, $week, $year);
186
187
        if (false === $isLocked) {
188
            $this->denyAccessUnlessGranted('AGREEMENT_LOCK', $agreement);
189
        }
190
191
        $weekDays = $em->getRepository('AppBundle:Workday')->getWorkdaysInWeek($agreement, $week, $year);
192
193
        if (0 === count($weekDays)) {
194
            throw $this->createNotFoundException();
195
        }
196
197
        $weekInfo = $em->getRepository('AppBundle:Workday')->getWeekInformation($weekDays[0]);
198
199
        $translator = $this->get('translator');
200
201
        $title = $translator->trans('form.weekly_report', [], 'student') . ' - ' . $agreement->getStudent() . ' - Semana ' . str_pad($weekInfo['current'], 2, '0', STR_PAD_LEFT);
202
203
        $mpdf = $this->get('sasedev_mpdf');
204
        $mpdf->init();
205
206
        $this->fillWeeklyReport($mpdf, $translator, $agreement, $weekDays, $title, $isLocked, $weekInfo);
207
208
        $title = str_replace(' ', '_', $title);
209
        return $mpdf->generateInlineFileResponse($title . '.pdf');
210
    }
211
212
    /**
213
     * @Route("/alumnado/seguimiento/programa/descargar/{id}", name="admin_group_teaching_program_report_download", methods={"GET"})
214
     * @Route("/estudiantes/programa/descargar/{id}", name="my_student_teaching_program_report_download", methods={"GET"})
215
     * @Security("is_granted('AGREEMENT_REPORT', agreement)")
216
     */
217
    public function downloadTeachingProgramReportAction(Agreement $agreement)
218
    {
219
        $translator = $this->get('translator');
220
221
        $title = $translator->trans('form.training_program', [], 'report') . ' - ' . $agreement->getStudent() . ' - ' . $agreement->getWorkcenter();
222
223
        $mpdf = $this->get('sasedev_mpdf');
224
        $mpdf->init('', 'A4-L');
225
226
        $obj = $mpdf->getMpdf();
227
        //$obj->setAutoTopMargin = 'stretch';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
228
        //$obj->setAutoBottomMargin = 'stretch';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
229
        $obj->SetImportUse();
230
        $obj->SetDocTemplate('pdf/Programa_Formativo_seneca_vacio.pdf', true);
231
        $mpdf->useTwigTemplate('student/training_program_report.html.twig', [
232
            'agreement' => $agreement,
233
            'title' => $title,
234
            'learning_program' => $this->getDoctrine()->getRepository('AppBundle:LearningOutcome')->getLearningProgramFromAgreement($agreement)
235
        ]);
236
237
        $title = str_replace(' ', '_', $title);
238
        return $mpdf->generateInlineFileResponse($title . '.pdf');
239
    }
240
}
241