1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\Holiday; |
6
|
|
|
use AppBundle\Form\Type\HolidayType; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
|
12
|
|
|
class AdminHolidayController extends Controller |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @Route(path="/admin/holiday", name="admin_holiday_index") |
16
|
|
|
*/ |
17
|
|
|
public function homepageAction() |
18
|
|
|
{ |
19
|
|
|
$holidays = $this->getDoctrine()->getRepository(Holiday::class)->findAll(); |
20
|
|
|
|
21
|
|
|
return $this->render('admin_holiday/index.html.twig', array( |
22
|
|
|
'holidays' => $holidays, |
23
|
|
|
'available_times' => $this->get('planning')->getAvailableTimes(), |
24
|
|
|
'form_holiday' => $this->createForm(HolidayType::class)->createView() |
25
|
|
|
)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @Route(path="/admin/holiday/create", name="admin_holiday_create") |
30
|
|
|
*/ |
31
|
|
|
public function createAction(Request $request) |
32
|
|
|
{ |
33
|
|
|
$form = $this->createForm(HolidayType::class); |
34
|
|
|
|
35
|
|
|
if ($form->handleRequest($request)->isValid()) { |
36
|
|
|
$em = $this->getDoctrine()->getManager(); |
37
|
|
|
$em->persist($form->getData()); |
38
|
|
|
$em->flush(); |
39
|
|
|
|
40
|
|
|
return $this->redirectToRoute('admin_holiday_index'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$holidays = $this->getDoctrine()->getRepository(Holiday::class)->findAll(); |
44
|
|
|
|
45
|
|
|
return $this->render('admin_holiday/index.html.twig', array( |
46
|
|
|
'holidays' => $holidays, |
47
|
|
|
'available_times' => $this->get('planning')->getAvailableTimes(), |
48
|
|
|
'form_holiday' => $form->createView() |
49
|
|
|
)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Route(path="/admin/holiday/delete/{id}", name="admin_holiday_delete") |
54
|
|
|
* @ParamConverter |
55
|
|
|
*/ |
56
|
|
|
public function deleteAction(Holiday $holiday) |
57
|
|
|
{ |
58
|
|
|
$em = $this->getDoctrine()->getManager(); |
59
|
|
|
$em->remove($holiday); |
60
|
|
|
$em->flush(); |
61
|
|
|
|
62
|
|
|
return $this->redirectToRoute('admin_holiday_index'); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|