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 — develop ( 3c014b...f94ec5 )
by Luis Ramón
05:10 queued 30s
created

TrackingController::studentWorkdayAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
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->getWorkcenter();
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' => $title],
77
                ],
78
                'title' => $title,
79
                'user' => $this->getUser(),
80
                'calendar' => $calendar,
81
                'agreement' => $agreement,
82
                'route_name' => 'admin_group_student_tracking'
83
            ]);
84
    }
85
86
    public function deleteWorkdayAction(Agreement $agreement, Request $request)
87
    {
88
        $this->denyAccessUnlessGranted('AGREEMENT_MANAGE', $agreement);
89
90
        $em = $this->getDoctrine()->getManager();
91
92
        if ($request->request->has('ids')) {
93
            try {
94
                $ids = $request->request->get('ids');
95
96
                $dates = $em->getRepository('AppBundle:Workday')->createQueryBuilder('w')
97
                    ->where('w.id IN (:ids)')
98
                    ->andWhere('w.agreement = :agreement')
99
                    ->setParameter('ids', $ids)
100
                    ->setParameter('agreement', $agreement)
101
                    ->getQuery()
102
                    ->getResult();
103
104
                /** @var Workday $date */
105
                foreach ($dates as $date) {
106
                    if ($date->getTrackedHours() === 0.0) {
107
                        $em->remove($date);
108
                    }
109
                }
110
                $em->flush();
111
112
                $agreement->setFromDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealFromDate($agreement));
113
                $agreement->setToDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealToDate($agreement));
114
115
                $em->flush();
116
                $this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], 'calendar'));
117
            } catch (\Exception $e) {
118
                $this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], 'calendar'));
119
            }
120
        }
121
        return $this->redirectToRoute('admin_group_student_calendar', ['id' => $agreement->getId()]);
122
    }
123
124
    /**
125
     * @Route("/seguimiento/acuerdo/{id}/operacion", name="admin_group_student_workday_operation", methods={"POST"})
126
     * @Security("is_granted('AGREEMENT_ACCESS', agreement)")
127
     */
128
    public function operationWorkdayAction(Agreement $agreement, Request $request)
129
    {
130
        if ($request->request->has('delete')) {
131
            return $this->deleteWorkdayAction($agreement, $request);
132
        } elseif ($request->request->has('week_lock') || ($request->request->has('week_unlock'))) {
133
            return $this->lockWeekAction($agreement, $request, $request->request->has('week_lock'), 'admin_group_student_calendar');
134
        } else {
135
            return $this->lockWorkdayAction($agreement, $request, $request->request->has('lock'), 'admin_group_student_calendar');
136
        }
137
    }
138
139
    /**
140
     * @Route("/seguimiento/acuerdo/{id}/incorporar", name="admin_group_student_workday_add", methods={"GET", "POST"})
141
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
142
     */
143
    public function addAgreementCalendarAction(Agreement $agreement, Request $request)
144
    {
145
        $totalHours = $agreement->getStudent()->getStudentGroup()->getTraining()->getProgramHours();
146
        $agreementHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->countHours($agreement);
147
        $studentHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->countAgreementHours($agreement->getStudent());
148
149
        $calendar = new Calendar(max(0, $totalHours - $studentHours));
150
151
        $form = $this->createForm('AppBundle\Form\Type\CalendarType', $calendar, [
152
            'program_hours' => $totalHours
153
        ]);
154
155
        $form->handleRequest($request);
156
157
        $workdays = new ArrayCollection();
158
159
        if ($form->isValid() && $form->isSubmitted()) {
160
            $workdays = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->createCalendar($calendar, $agreement);
161
162
            if ($request->request->has('submit')) {
163
                $this->getDoctrine()->getManager()->flush();
164
                $agreement->setFromDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealFromDate($agreement));
165
                $agreement->setToDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealToDate($agreement));
166
                $this->getDoctrine()->getManager()->flush();
167
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar'));
168
                return $this->redirectToRoute('admin_group_student_calendar', ['id' => $agreement->getId()]);
169
            }
170
        }
171
172
        $student = $agreement->getStudent();
173
174
        $calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($workdays);
175
176
        return $this->render('group/calendar_agreement_workday_add.html.twig', [
177
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
178
            'breadcrumb' => [
179
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
180
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
181
                ['fixed' => (string) $agreement->getWorkcenter()],
182
                ['fixed' => $this->get('translator')->trans('form.add', [], 'calendar')]
183
            ],
184
            'agreement' => $agreement,
185
            'total_hours' => $totalHours,
186
            'agreement_hours' => $agreementHours,
187
            'student_hours' => $studentHours,
188
            'form' => $form->createView(),
189
            'calendar' => $calendar
190
        ]);
191
    }
192
193
    /**
194
     * @Route("/seguimiento/acuerdo/jornada/{id}", name="admin_group_student_tracking", methods={"GET", "POST"})
195
     * @Security("is_granted('AGREEMENT_ACCESS', workday.getAgreement())")
196
     */
197
    public function studentWorkdayAction(Workday $workday, Request $request)
198
    {
199
        $student = $workday->getAgreement()->getStudent();
200
201
        return $this->baseWorkdayAction($workday, $request, [
202
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
203
            'breadcrumb' => [
204
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
205
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
206
                ['fixed' => (string) $workday->getAgreement()->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
207
                ['fixed' => $workday->getDate()->format('d/m/Y')]
208
            ],
209
            'back_route_name' => 'admin_group_student_calendar'
210
        ]);
211
    }
212
213
    /**
214
     * @Route("/seguimiento/acuerdo/jornada/modificar/{id}", name="admin_group_student_workday_form", methods={"GET", "POST"})
215
     * @Security("is_granted('AGREEMENT_MANAGE', workday.getAgreement())")
216
     */
217
    public function agreementCalendarFormAction(Workday $workday, Request $request)
218
    {
219
        $form = $this->createForm('AppBundle\Form\Type\WorkdayType', $workday);
220
        $form->handleRequest($request);
221
222
        if ($form->isValid() && $form->isSubmitted()) {
223
            $this->getDoctrine()->getManager()->flush();
224
            $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar'));
225
            return $this->redirectToRoute('admin_group_student_calendar', ['id' => $workday->getAgreement()->getId()]);
226
        }
227
        $student = $workday->getAgreement()->getStudent();
228
229
        $dow = ((6 + (int) $workday->getDate()->format('w')) % 7);
230
        $title = $this->get('translator')->trans('dow' . $dow, [], 'calendar') . ', ' . $workday->getDate()->format('d/m/Y');
231
232
        return $this->render('group/calendar_agreement_workday_form.html.twig', [
233
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
234
            'breadcrumb' => [
235
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
236
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
237
                ['fixed' => (string) $workday->getAgreement()->getWorkcenter(), 'path' => 'admin_group_student_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]],
238
                ['fixed' => $title],
239
            ],
240
            'form' => $form->createView(),
241
            'workday' => $workday
242
        ]);
243
    }
244
245
    /**
246
     * @Route("/seguimiento/acuerdo/nuevo/{id}", name="admin_group_student_agreement_new", methods={"GET", "POST"})
247
     * @Security("is_granted('GROUP_CREATE_AGREEMENT', student.getStudentGroup())")
248
     */
249
    public function agreementNewFormAction(User $student, Request $request)
250
    {
251
        $agreement = new Agreement();
252
        $agreement->setStudent($student);
253
        $this->getDoctrine()->getManager()->persist($agreement);
254
255
        return $this->agreementFormAction($agreement, $request);
256
    }
257
258
    /**
259
     * @Route("/seguimiento/acuerdo/modificar/{id}", name="admin_group_student_agreement_form", methods={"GET", "POST"})
260
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
261
     */
262
    public function agreementFormAction(Agreement $agreement, Request $request)
263
    {
264
        $form = $this->createForm('AppBundle\Form\Type\AgreementType', $agreement);
265
266
        $form->handleRequest($request);
267
268
        $student = $agreement->getStudent();
269
270 View Code Duplication
        if ($form->isValid() && $form->isSubmitted()) {
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...
271
            // Probar a guardar los cambios
272
            try {
273
                $this->getDoctrine()->getManager()->flush();
274
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'group'));
275
                return $this->redirectToRoute('admin_group_student_agreements', ['id' => $student->getId()]);
276
            } catch (\Exception $e) {
277
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'group'));
278
            }
279
        }
280
281
        $title = (null === $agreement->getId())
282
            ? $this->get('translator')->trans('form.new_agreement', [], 'group')
283
            : (string) $agreement->getWorkcenter();
284
285
        return $this->render('group/form_agreement.html.twig',
286
            [
287
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
288
                'breadcrumb' => [
289
                    ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
290
                    ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
291
                    ['fixed' => $title]
292
                ],
293
                'form' => $form->createView(),
294
                'agreement' => $agreement
295
            ]);
296
    }
297
298
    /**
299
     * @Route("/seguimiento/acuerdo/eliminar/{id}", name="admin_group_student_agreement_delete", methods={"GET", "POST"})
300
     * @Security("is_granted('AGREEMENT_MANAGE', agreement)")
301
     */
302 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...
303
    {
304
        $student = $agreement->getStudent();
305
306
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
307
308
            // Eliminar el acuerdo de la base de datos
309
            $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->delete($agreement);
310
            try {
311
                $this->getDoctrine()->getManager()->flush();
312
                $this->addFlash('success', $this->get('translator')->trans('alert.agreement_deleted', [], 'group'));
313
            } catch (\Exception $e) {
314
                $this->addFlash('error', $this->get('translator')->trans('alert.agreement_not_deleted', [], 'group'));
315
            }
316
            return $this->redirectToRoute('admin_group_student_agreements', ['id' => $student->getId()]);
317
        }
318
319
        $title = (string) $agreement->getWorkcenter();
320
321
        return $this->render('group/delete_agreement.html.twig', [
322
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_tutor_group'),
323
            'breadcrumb' => [
324
                ['fixed' => $student->getStudentGroup()->getName(), 'path' => 'admin_group_students', 'options' => ['id' => $student->getStudentGroup()->getId()]],
325
                ['fixed' => (string) $student, 'path' => 'admin_group_student_agreements', 'options' => ['id' => $student->getId()]],
326
                ['fixed' => $title]
327
            ],
328
            'title' => $title,
329
            'agreement' => $agreement
330
        ]);
331
    }
332
}
333