AdminHolidayController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A homepageAction() 0 10 1
A createAction() 0 21 3
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
        $form->handleRequest($request);
35
36
        if ($form->isSubmitted() && $form->isValid()) {
37
            $em = $this->getDoctrine()->getManager();
38
            $em->persist($form->getData());
39
            $em->flush();
40
41
            return $this->redirectToRoute('admin_holiday_index');
42
        }
43
44
        $holidays = $this->getDoctrine()->getRepository(Holiday::class)->findAll();
45
46
        return $this->render('admin_holiday/index.html.twig', array(
47
            'holidays' => $holidays,
48
            'available_times' => $this->get('planning')->getAvailableTimes(),
49
            'form_holiday' => $form->createView()
50
        ));
51
    }
52
53
    /**
54
     * @Route(path="/admin/holiday/delete/{id}", name="admin_holiday_delete")
55
     * @ParamConverter
56
     */
57
    public function deleteAction(Holiday $holiday)
58
    {
59
        $em = $this->getDoctrine()->getManager();
60
        $em->remove($holiday);
61
        $em->flush();
62
63
        return $this->redirectToRoute('admin_holiday_index');
64
    }
65
}
66