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