Completed
Push — master ( b79250...5c4b09 )
by Alexandre
04:43
created

AdminHolidayController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 6
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A homepageAction() 0 10 1
A createAction() 0 20 2
A deleteAction() 0 8 1
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