|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\Agreement; |
|
6
|
|
|
use AppBundle\Entity\Workday; |
|
7
|
|
|
use AppBundle\Form\Model\Calendar; |
|
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
|
|
14
|
|
|
class AgreementController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @Route("/acuerdos/{id}/calendario", name="agreement_calendar", methods={"GET"}) |
|
18
|
|
|
* @Security("is_granted('AGREEMENT_MANAGE', agreement)") |
|
19
|
|
|
*/ |
|
20
|
|
|
public function agreementGraphicCalendarAction(Agreement $agreement) |
|
21
|
|
|
{ |
|
22
|
|
|
$totalHours = $agreement->getStudent()->getStudentGroup()->getTraining()->getProgramHours(); |
|
23
|
|
|
$agreementHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->countHours($agreement); |
|
24
|
|
|
$studentHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->countAgreementHours($agreement->getStudent()); |
|
25
|
|
|
$calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($agreement->getWorkdays()); |
|
26
|
|
|
return $this->render('calendar/agreement_calendar_graphic.html.twig', [ |
|
27
|
|
|
'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_agreement'), |
|
28
|
|
|
'breadcrumb' => [ |
|
29
|
|
|
['fixed' => (string) $agreement, 'path' => 'admin_agreement_form', 'options' => ['id' => $agreement->getId()]], |
|
30
|
|
|
['fixed' => $this->get('translator')->trans('browse.title', [], 'calendar')] |
|
31
|
|
|
], |
|
32
|
|
|
'calendar' => $calendar, |
|
33
|
|
|
'agreement' => $agreement, |
|
34
|
|
|
'total_hours' => $totalHours, |
|
35
|
|
|
'agreement_hours' => $agreementHours, |
|
36
|
|
|
'student_hours' => $studentHours |
|
37
|
|
|
]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @Route("/acuerdos/{id}/calendario/incorporar", name="agreement_calendar_add", methods={"GET", "POST"}) |
|
42
|
|
|
* @Security("is_granted('AGREEMENT_MANAGE', agreement)") |
|
43
|
|
|
*/ |
|
44
|
|
|
public function addAgreementCalendarAction(Agreement $agreement, Request $request) |
|
45
|
|
|
{ |
|
46
|
|
|
$totalHours = $agreement->getStudent()->getStudentGroup()->getTraining()->getProgramHours(); |
|
47
|
|
|
$agreementHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->countHours($agreement); |
|
48
|
|
|
$studentHours = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->countAgreementHours($agreement->getStudent()); |
|
49
|
|
|
|
|
50
|
|
|
$calendar = new Calendar(max(0, $totalHours - $studentHours)); |
|
51
|
|
|
|
|
52
|
|
|
$form = $this->createForm('AppBundle\Form\Type\CalendarType', $calendar, [ |
|
53
|
|
|
'program_hours' => $totalHours |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$form->handleRequest($request); |
|
57
|
|
|
|
|
58
|
|
|
$workdays = new ArrayCollection(); |
|
59
|
|
|
|
|
60
|
|
|
if ($form->isValid() && $form->isSubmitted()) { |
|
61
|
|
|
$workdays = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->createCalendar($calendar, $agreement); |
|
62
|
|
|
|
|
63
|
|
|
if ($request->request->has('submit')) { |
|
64
|
|
|
$this->getDoctrine()->getManager()->flush(); |
|
65
|
|
|
$agreement->setFromDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealFromDate($agreement)); |
|
66
|
|
|
$agreement->setToDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealToDate($agreement)); |
|
67
|
|
|
$this->getDoctrine()->getManager()->flush(); |
|
68
|
|
|
$this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar')); |
|
69
|
|
|
return $this->redirectToRoute('agreement_calendar', ['id' => $agreement->getId()]); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$calendar = $this->getDoctrine()->getManager()->getRepository('AppBundle:Workday')->getArrayCalendar($workdays); |
|
74
|
|
|
|
|
75
|
|
|
return $this->render('calendar/agreement_calendar_add.html.twig', [ |
|
76
|
|
|
'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_agreement'), |
|
77
|
|
|
'breadcrumb' => [ |
|
78
|
|
|
['fixed' => (string) $agreement, 'path' => 'admin_agreement_form', 'options' => ['id' => $agreement->getId()]], |
|
79
|
|
|
['fixed' => $this->get('translator')->trans('browse.title', [], 'calendar'), 'path' => 'agreement_calendar', 'options' => ['id' => $agreement->getId()]], |
|
80
|
|
|
['fixed' => $this->get('translator')->trans('form.add', [], 'calendar')] |
|
81
|
|
|
], |
|
82
|
|
|
'agreement' => $agreement, |
|
83
|
|
|
'total_hours' => $totalHours, |
|
84
|
|
|
'agreement_hours' => $agreementHours, |
|
85
|
|
|
'student_hours' => $studentHours, |
|
86
|
|
|
'form' => $form->createView(), |
|
87
|
|
|
'calendar' => $calendar |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function lockWorkdayAction(Agreement $agreement, Request $request, $status) |
|
92
|
|
|
{ |
|
93
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
94
|
|
|
|
|
95
|
|
|
if ($request->request->has('ids')) { |
|
96
|
|
|
try { |
|
97
|
|
|
$ids = $request->request->get('ids'); |
|
98
|
|
|
|
|
99
|
|
|
$em->createQuery('UPDATE AppBundle:Workday w SET w.locked = :locked WHERE w.id IN (:ids) AND w.agreement = :agreement') |
|
100
|
|
|
->setParameter('locked', $status) |
|
101
|
|
|
->setParameter('ids', $ids) |
|
102
|
|
|
->setParameter('agreement', $agreement) |
|
103
|
|
|
->execute(); |
|
104
|
|
|
|
|
105
|
|
|
$em->flush(); |
|
106
|
|
|
$this->addFlash('success', $this->get('translator')->trans('alert.locked', [], 'calendar')); |
|
107
|
|
|
} catch (\Exception $e) { |
|
108
|
|
|
$this->addFlash('error', $this->get('translator')->trans('alert.locked_error', [], 'calendar')); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
return $this->redirectToRoute('agreement_calendar', ['id' => $agreement->getId()]); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @Route("/acuerdos/{id}/calendario/operacion", name="agreement_calendar_operation", methods={"POST"}) |
|
116
|
|
|
* @Security("is_granted('AGREEMENT_MANAGE', agreement)") |
|
117
|
|
|
*/ |
|
118
|
|
|
public function deleteAgreementCalendarAction(Agreement $agreement, Request $request) |
|
119
|
|
|
{ |
|
120
|
|
|
if ($request->request->has('lock')) { |
|
121
|
|
|
return $this->lockWorkdayAction($agreement, $request, true); |
|
122
|
|
|
} |
|
123
|
|
|
if ($request->request->has('unlock')) { |
|
124
|
|
|
return $this->lockWorkdayAction($agreement, $request, false); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
128
|
|
|
|
|
129
|
|
|
if ($request->request->has('ids')) { |
|
130
|
|
|
try { |
|
131
|
|
|
$ids = $request->request->get('ids'); |
|
132
|
|
|
|
|
133
|
|
|
$dates = $em->getRepository('AppBundle:Workday')->createQueryBuilder('w') |
|
134
|
|
|
->where('w.id IN (:ids)') |
|
135
|
|
|
->andWhere('w.agreement = :agreement') |
|
136
|
|
|
->setParameter('ids', $ids) |
|
137
|
|
|
->setParameter('agreement', $agreement) |
|
138
|
|
|
->getQuery() |
|
139
|
|
|
->getResult(); |
|
140
|
|
|
|
|
141
|
|
|
/** @var Workday $date */ |
|
142
|
|
|
foreach ($dates as $date) { |
|
143
|
|
|
if ($date->getTrackedHours() === 0) { |
|
144
|
|
|
$em->remove($date); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
$em->flush(); |
|
148
|
|
|
|
|
149
|
|
|
$agreement->setFromDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealFromDate($agreement)); |
|
150
|
|
|
$agreement->setToDate($this->getDoctrine()->getManager()->getRepository('AppBundle:Agreement')->getRealToDate($agreement)); |
|
151
|
|
|
|
|
152
|
|
|
$em->flush(); |
|
153
|
|
|
$this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], 'calendar')); |
|
154
|
|
|
} catch (\Exception $e) { |
|
155
|
|
|
$this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], 'calendar')); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
return $this->redirectToRoute('agreement_calendar', ['id' => $agreement->getId()]); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @Route("/jornada/{id}", name="agreement_calendar_form", methods={"GET", "POST"}) |
|
163
|
|
|
* @Security("is_granted('AGREEMENT_MANAGE', workday.getAgreement())") |
|
164
|
|
|
*/ |
|
165
|
|
|
public function agreementCalendarFormAction(Workday $workday, Request $request) |
|
166
|
|
|
{ |
|
167
|
|
|
$form = $this->createForm('AppBundle\Form\Type\WorkdayType', $workday); |
|
168
|
|
|
$form->handleRequest($request); |
|
169
|
|
|
|
|
170
|
|
|
if ($form->isValid() && $form->isSubmitted()) { |
|
171
|
|
|
$this->getDoctrine()->getManager()->flush(); |
|
172
|
|
|
$this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'calendar')); |
|
173
|
|
|
return $this->redirectToRoute('agreement_calendar', ['id' => $workday->getAgreement()->getId()]); |
|
174
|
|
|
} |
|
175
|
|
|
return $this->render('calendar/agreement_calendar_form.html.twig', [ |
|
176
|
|
|
'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_agreement'), |
|
177
|
|
|
'breadcrumb' => [ |
|
178
|
|
|
['fixed' => (string) $workday->getAgreement(), 'path' => 'admin_agreement_form', 'options' => ['id' => $workday->getAgreement()->getId()]], |
|
179
|
|
|
['fixed' => $this->get('translator')->trans('browse.title', [], 'calendar'), 'path' => 'agreement_calendar', 'options' => ['id' => $workday->getAgreement()->getId()]], |
|
180
|
|
|
['fixed' => $this->get('translator')->trans('form.add', [], 'calendar')] |
|
181
|
|
|
], |
|
182
|
|
|
'form' => $form->createView(), |
|
183
|
|
|
'workday' => $workday |
|
184
|
|
|
]); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|