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 — user-entity ( 8f70fe...83f5aa )
by Luis Ramón
03:38
created

BaseController::baseWorkdayAction()   C

Complexity

Conditions 7
Paths 2

Size

Total Lines 48
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 48
rs 6.7272
cc 7
eloc 33
nc 2
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\Tracking;
25
use AppBundle\Entity\Workday;
26
use Doctrine\ORM\Query;
27
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
28
use Symfony\Component\HttpFoundation\Request;
29
30
class BaseController extends Controller
31
{
32
    public function baseWorkdayAction(Workday $workday, Request $request, $options)
33
    {
34
        $agreement = $workday->getAgreement();
35
        $agreementHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->countHours($agreement);
36
37
        $dow = ((6 + (int) $workday->getDate()->format('w')) % 7);
38
        
39
        $title = $this->get('translator')->trans('dow' . $dow, [], 'calendar') . ', ' . $workday->getDate()->format('d/m/Y');
40
        $em = $this->getDoctrine()->getManager();
41
        $em->getRepository('AppBundle:Tracking')->updateTrackingByWorkday($workday);
42
43
        $form = $this->createForm('AppBundle\Form\Type\WorkdayTrackingType', $workday, [
44
            'disabled' => ($this->isGranted('AGREEMENT_FILL', $agreement) || $workday->isLocked()) && (!$this->isGranted('AGREEMENT_UNLOCK', $agreement))
45
        ]);
46
        $form->handleRequest($request);
47
48
        if ($form->isSubmitted() && $form->isValid()) {
49
            /** @var Tracking $tracking */
50
            foreach ($workday->getTrackingActivities() as $tracking) {
51
                if ($tracking->getHours() == 0) {
52
                    $workday->removeTrackingActivity($tracking);
53
                    $em->remove($tracking);
54
                } else {
55
                    $em->persist($tracking);
56
                }
57
            }
58
            $em->flush();
59
        }
60
61
        $activitiesStats = $em->getRepository('AppBundle:Agreement')->getActivitiesStats($agreement);
62
        $next = $em->getRepository('AppBundle:Workday')->getNext($workday);
63
        $previous = $em->getRepository('AppBundle:Workday')->getPrevious($workday);
64
        
65
        return $this->render('student/tracking_form.html.twig',
66
            [
67
                'menu_item' => $options['menu_item'],
68
                'breadcrumb' => $options['breadcrumb'],
69
                'title' => $title,
70
                'user' => $this->getUser(),
71
                'workday' => $workday,
72
                'form' => $form->createView(),
73
                'agreement_hours' => $agreementHours,
74
                'activities_stats' => $activitiesStats,
75
                'next' => $next,
76
                'previous' => $previous,
77
                'back_route_name' => $options['back_route_name']
78
            ]);
79
    }
80
81
82
    public function lockWorkdayAction(Agreement $agreement, Request $request, $status, $routeName)
83
    {
84
        $this->denyAccessUnlessGranted($status ? 'AGREEMENT_LOCK' : 'AGREEMENT_UNLOCK', $agreement);
85
86
        $em = $this->getDoctrine()->getManager();
87
88
        if ($request->request->has('ids')) {
89
            try {
90
                $ids = $request->request->get('ids');
91
92
                $em->createQuery('UPDATE AppBundle:Workday w SET w.locked = :locked WHERE w.id IN (:ids) AND w.agreement = :agreement')
93
                    ->setParameter('locked', $status)
94
                    ->setParameter('ids', $ids)
95
                    ->setParameter('agreement', $agreement)
96
                    ->execute();
97
98
                $em->flush();
99
                $this->addFlash('success', $this->get('translator')->trans('alert.locked', [], 'calendar'));
100
            } catch (\Exception $e) {
101
                $this->addFlash('error', $this->get('translator')->trans('alert.locked_error', [], 'calendar'));
102
            }
103
        }
104
        return $this->redirectToRoute($routeName, ['id' => $agreement->getId()]);
105
    }
106
107
    public function lockWeekAction(Agreement $agreement, Request $request, $status, $routeName)
108
    {
109
        $this->denyAccessUnlessGranted($status ? 'AGREEMENT_LOCK' : 'AGREEMENT_UNLOCK', $agreement);
110
111
        $data = $request->get($status ? 'week_lock' : 'week_unlock');
112
        $week = $data % 100;
113
        $year = intdiv($data, 100);
114
115
        $em = $this->getDoctrine()->getManager();
116
117
        $workdays = $em->getRepository('AppBundle:Workday')->getWorkdaysInWeek($agreement, $week, $year);
118
119
        try {
120
            /** @var Workday $workday */
121
            foreach ($workdays as $workday) {
122
                $workday->setLocked($status);
123
            }
124
125
            $em->flush();
126
            $this->addFlash('success', $this->get('translator')->trans('alert.locked', [], 'calendar'));
127
        } catch (\Exception $e) {
128
            $this->addFlash('error', $this->get('translator')->trans('alert.locked_error', [], 'calendar'));
129
        }
130
131
        return $this->redirectToRoute($routeName, ['id' => $agreement->getId()]);
132
    }
133
}
134