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 ( df9de4...2d045c )
by Luis Ramón
03:21
created

TrackingController::agreementDeleteAction()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 19

Duplication

Lines 30
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 30
loc 30
rs 8.5806
cc 4
eloc 19
nc 4
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 AppBundle\Form\Model\Calendar;
27
use Doctrine\Common\Collections\ArrayCollection;
28
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
29
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
30
use Symfony\Component\HttpFoundation\Request;
31
32
/**
33
 * @Route("/alumnado")
34
 * @Security("is_granted('ROLE_GROUP_TUTOR')")
35
 */
36
class TrackingController extends BaseController
37
{
38
    /**
39
     * @Route("/seguimiento/seleccion/{id}", name="admin_group_student_agreements", methods={"GET"})
40
     * @Security("is_granted('GROUP_MANAGE', student.getStudentGroup())")
41
     */
42
    public function studentAgreementIndexAction(User $student)
43
    {
44
        $agreements = $student->getStudentAgreements();
45
46
        return $this->render('group/calendar_agreement_select.html.twig',
47
            [
48
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
49
                'breadcrumb' => [
50
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
51
                    ['fixed' => (string) $student],
52
                ],
53
                'student' => $student,
54
                'elements' => $agreements,
55
                'route_name' => 'admin_group_student_calendar'
56
            ]);
57
    }
58
59
    /**
60
     * @Route("/seguimiento/acuerdo/{id}", name="admin_group_student_calendar", methods={"GET"})
61
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
62
     */
63
    public function studentCalendarAgreementIndexAction(Agreement $agreement)
64
    {
65
        $student = $agreement->getStudent();
66
67
        $calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($agreement->getWorkdays());
68
        $title = (string) $agreement;
69
70
        return $this->render('group/calendar_agreement.html.twig',
71
            [
72
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
73
                'breadcrumb' => [
74
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
75
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
76
                    ['fixed' => (string) $agreement->getWorkcenter()],
77
                ],
78
                'title' => $title,
79
                'user' => $this->getUser(),
80
                'calendar' => $calendar,
81
                'agreement' => $agreement,
82
                'route_name' => 'admin_group_student_tracking',
83
                'activities_stats' => $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getActivitiesStats($agreement)
84
            ]);
85
    }
86
87
    /**
88
     * @Route("/seguimiento/acuerdo/{id}/operacion", name="admin_group_student_workday_operation", methods={"POST"})
89
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
90
     */
91
    public function operationWorkdayAction(Agreement $agreement, Request $request)
92
    {
93
        if ($request->request->has('delete')) {
94
            return $this->deleteWorkdayAction($agreement, $request);
95
        }
96 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...
97
            return $this->lockWeekAction($agreement, $request, $request->request->has('week_lock'), 'admin_group_student_calendar');
98
        }
99
        return $this->lockWorkdayAction($agreement, $request, $request->request->has('lock'), 'admin_group_student_calendar');
100
    }
101
102
    /**
103
     * @Route("/seguimiento/acuerdo/{id}/incorporar", name="admin_group_student_workday_add", methods={"GET", "POST"})
104
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
105
     */
106
    public function addAgreementCalendarAction(Agreement $agreement, Request $request)
107
    {
108
        $totalHours = $agreement->getStudent()->getStudentGroup()->getTraining()->getProgramHours();
109
        $agreementHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->countHours($agreement);
110
        $studentHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->countAgreementHours($agreement->getStudent());
111
112
        $calendar = new Calendar(max(0, $totalHours - $studentHours));
113
114
        $form = $this->createForm('AppBundle\Form\Type\CalendarType', $calendar, [
115
            'program_hours' => $totalHours
116
        ]);
117
118
        $form->handleRequest($request);
119
120
        $workdays = new ArrayCollection();
121
122
        if ($form->isSubmitted() && $form->isValid()) {
123
            $workdays = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->createCalendar($calendar, $agreement);
124
125
            if ($request->request->has('submit')) {
126
                $this->getDoctrine()->getManager()->flush();
127
                $agreement->setFromDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealFromDate($agreement));
128
                $agreement->setToDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealToDate($agreement));
129
                $this->getDoctrine()->getManager()->flush();
130
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar'));
131
                return $this->redirectToRoute('admin_group_student_calendar', ['id' => $agreement->getId()]);
132
            }
133
        }
134
135
        $student = $agreement->getStudent();
136
137
        $calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($workdays);
138
139
        return $this->render('group/calendar_agreement_workday_add.html.twig', [
140
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
141
            'breadcrumb' => [
142
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
143
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
144
                ['fixed' => (string) $agreement->getWorkcenter()],
145
                ['fixed' => $this->get('translator')->trans('form.add', [], 'calendar')]
146
            ],
147
            'agreement' => $agreement,
148
            'total_hours' => $totalHours,
149
            'agreement_hours' => $agreementHours,
150
            'student_hours' => $studentHours,
151
            'form' => $form->createView(),
152
            'calendar' => $calendar
153
        ]);
154
    }
155
156
    /**
157
     * @Route("/seguimiento/acuerdo/jornada/{id}", name="admin_group_student_tracking", methods={"GET", "POST"})
158
     * @Security("is_granted('AGREEMENT_ACCESS', workday.getAgreement())")
159
     */
160 View Code Duplication
    public function studentWorkdayAction(Workday $workday, Request $request)
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...
161
    {
162
        $student = $workday->getAgreement()->getStudent();
163
164
        return $this->baseWorkdayAction($workday, $request, [
165
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
166
            'breadcrumb' => [
167
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
168
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
169
                ['fixed' => (string) $workday->getAgreement()->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
170
                ['fixed' => $workday->getDate()->format('d/m/Y')]
171
            ],
172
            'back_route_name' => 'admin_group_student_calendar'
173
        ]);
174
    }
175
176
    /**
177
     * @Route("/seguimiento/acuerdo/jornada/modificar/{id}", name="admin_group_student_workday_form", methods={"GET", "POST"})
178
     * @Security("is_granted('AGREEMENT_MANAGE', workday.getAgreement())")
179
     */
180
    public function agreementCalendarFormAction(Workday $workday, Request $request)
181
    {
182
        $form = $this->createForm('AppBundle\Form\Type\WorkdayType', $workday);
183
        $form->handleRequest($request);
184
185
        if ($form->isSubmitted() && $form->isValid()) {
186
            $this->getDoctrine()->getManager()->flush();
187
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar'));
188
            return $this->redirectToRoute('admin_group_student_calendar', ['id' => $workday->getAgreement()->getId()]);
189
        }
190
        $student = $workday->getAgreement()->getStudent();
191
192
        $dow = ((6 + (int) $workday->getDate()->format('w')) % 7);
193
        $title = $this->get('translator')->trans('dow' . $dow, [], 'calendar') . ', ' . $workday->getDate()->format('d/m/Y');
194
195
        return $this->render('group/calendar_agreement_workday_form.html.twig', [
196
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
197
            'breadcrumb' => [
198
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
199
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
200
                ['fixed' => (string) $workday->getAgreement()->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
201
                ['fixed' => $title],
202
            ],
203
            'form' => $form->createView(),
204
            'workday' => $workday
205
        ]);
206
    }
207
208
    /**
209
     * @Route("/seguimiento/acuerdo/nuevo/{id}", name="admin_group_student_agreement_new", methods={"GET", "POST"})
210
     * @Security("is_granted('GROUP_CREATE_AGREEMENT', student.getStudentGroup())")
211
     */
212
    public function agreementNewFormAction(User $student, Request $request)
213
    {
214
        $agreement = new Agreement();
215
        $agreement->setStudent($student);
216
        $this->getDoctrine()->getManager()->persist($agreement);
217
218
        return $this->agreementFormAction($agreement, $request);
219
    }
220
221
    /**
222
     * @Route("/seguimiento/acuerdo/modificar/{id}", name="admin_group_student_agreement_form", methods={"GET", "POST"})
223
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
224
     */
225
    public function agreementFormAction(Agreement $agreement, Request $request)
226
    {
227
        $form = $this->createForm('AppBundle\Form\Type\AgreementType', $agreement);
228
229
        $form->handleRequest($request);
230
231
        $student = $agreement->getStudent();
232
233
        if ($form->isSubmitted() && $form->isValid()) {
234
            // Probar a guardar los cambios
235
            try {
236
                $this->getDoctrine()->getManager()->flush();
237
                if ($request->request->has('report')) {
238
                    return $this->redirectToRoute('admin_group_teaching_program_report_download', ['id' => $agreement->getId()]);
239
                }
240
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'group'));
241
                return $this->redirectToRoute('admin_group_student_agreements', ['id' => $student->getId()]);
242
243
            } catch (\Exception $e) {
244
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'group'));
245
            }
246
        }
247
248
        $title = (null === $agreement->getId())
249
            ? $this->get('translator')->trans('form.new_agreement', [], 'group')
250
            : (string) $agreement->getWorkcenter();
251
252
        return $this->render('group/form_agreement.html.twig',
253
            [
254
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
255
                'breadcrumb' => [
256
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
257
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
258
                    ['fixed' => $title]
259
                ],
260
                'form' => $form->createView(),
261
                'agreement' => $agreement
262
            ]);
263
    }
264
265
    /**
266
     * @Route("/seguimiento/acuerdo/eliminar/{id}", name="admin_group_student_agreement_delete", methods={"GET", "POST"})
267
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
268
     */
269 View Code Duplication
    public function agreementDeleteAction(Agreement $agreement, Request $request)
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...
270
    {
271
        $student = $agreement->getStudent();
272
273
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
274
275
            // Eliminar el acuerdo de la base de datos
276
            $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->delete($agreement);
277
            try {
278
                $this->getDoctrine()->getManager()->flush();
279
                $this->addFlash('success', $this->get('translator')->trans('alert.agreement_deleted', [], 'group'));
280
            } catch (\Exception $e) {
281
                $this->addFlash('error', $this->get('translator')->trans('alert.agreement_not_deleted', [], 'group'));
282
            }
283
            return $this->redirectToRoute('admin_group_student_agreements', ['id' => $student->getId()]);
284
        }
285
286
        $title = (string) $agreement->getWorkcenter();
287
288
        return $this->render('group/delete_agreement.html.twig', [
289
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
290
            'breadcrumb' => [
291
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
292
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
293
                ['fixed' => $title]
294
            ],
295
            'title' => $title,
296
            'agreement' => $agreement
297
        ]);
298
    }
299
300
    /**
301
     * @Route("/seguimiento/acuerdo/estudiante/{id}", name="admin_group_student_agreement_student_info", methods={"GET"})
302
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
303
     */
304
    public function agreementStudentDetailAction(Agreement $agreement)
305
    {
306
        $student = $agreement->getStudent();
307
        $form = $this->createForm('AppBundle\Form\Type\StudentUserType', $student, [
308
            'admin' => false,
309
            'disabled' => true
310
        ]);
311
312
        return $this->render('student/student_detail.html.twig',
313
            [
314
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
315
                'breadcrumb' => [
316
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
317
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
318
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
319
                    ['fixed' => $this->get('translator')->trans('student.detail', [], 'group')]
320
                ],
321
                'title' => (string) $student,
322
                'user' => $student,
323
                'agreement' => $agreement,
324
                'form' => $form->createView(),
325
                'back' => 'admin_group_student_calendar'
326
            ]);
327
    }
328
329
330
    /**
331
     * @Route("/seguimiento/acuerdo/centro/{id}", name="admin_group_student_agreement_workcenter_info", methods={"GET"})
332
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
333
     */
334
    public function workCenterDetailAction(Agreement $agreement)
335
    {
336
        $workcenter = $agreement->getWorkcenter();
337
        $student = $agreement->getStudent();
338
339
        $form = $this->createForm('AppBundle\Form\Type\WorkcenterType', $workcenter, [
340
            'disabled' => true
341
        ]);
342
343
        return $this->render('student/workcenter_detail.html.twig',
344
            [
345
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
346
                'breadcrumb' => [
347
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
348
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
349
                    ['fixed' => (string) $agreement->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $agreement->getId()]],
350
                    ['fixed' => $this->get('translator')->trans('form.workcenter', [], 'company')]
351
                ],
352
                'title' => (string) $workcenter,
353
                'workcenter' => $workcenter,
354
                'agreement' => $agreement,
355
                'form' => $form->createView(),
356
                'back' => 'admin_group_student_calendar'
357
            ]);
358
    }
359
}
360