OwnerController.php 2.99 KB
Newer Older
Mat's avatar
Mat committed
1
2
3
4
5
6
7
<?php

namespace TechnoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use TechnoBundle\Entity\Owner;
8
use TechnoBundle\Form\Owner\OwnerType;
9
use APIBundle\Form\Owner\OwnerAPIType;
Mat's avatar
Mat committed
10
11


12
class OwnerController extends MasterController
Mat's avatar
Mat committed
13
14
15
{

    /**
Mat's avatar
Mat committed
16
17
    *   @param Request
    *   @return \Symfony\Component\HttpFoundation\Response
Mat's avatar
Mat committed
18
19
20
21
22
23
24
25
26
27
28
29
30
    */
    public function createAction(Request $request)
    {
        $auteur = new Owner();

        $form = $this->createForm(OwnerType::class, $auteur);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid())
        {
            $em = $this->getDoctrine()->getManager();
            $em->persist($auteur);
            $em->flush();
31
32

            return $this->redirectToRoute('techno_owner_read');
Mat's avatar
Mat committed
33
34
35
        }

        return $this->render('@Techno/Owner/create.html.twig', array(
Mat's avatar
Mat committed
36
            'formOwner' => $form->createView()
Mat's avatar
Mat committed
37
38
39
40
41
42
43
44
        ));
    }

    /**
    *   @return \Symfony\Component\HttpFoundation\Response
    */
    public function readAction()
    {
45
46
        $em = $this->getDoctrine()->getManager();
        $auteurs = $em->getRepository('TechnoBundle:Owner')->findAllForIndex();
47

Mat's avatar
Mat committed
48
49
50
51
        return $this->render('@Techno/Owner/read.html.twig', array(
            'auteurs' => $auteurs
        ));
    }
52

Mat's avatar
Mat committed
53
54

    /**
Mat's avatar
Mat committed
55
56
57
    *   @param Request
    *   @param $id
    *   @return \Symfony\Component\HttpFoundation\Response
Mat's avatar
Mat committed
58
    */
Mat's avatar
Mat committed
59
    public function updateAction(Request $request, $id)
Mat's avatar
Mat committed
60
    {
Mat's avatar
Mat committed
61
62
63
64
65
66
67
68
69
70
71
72
73
        $em = $this->getDoctrine()->getManager();
        $auteur = $em->getRepository('TechnoBundle:Owner')->findOneByUpdate($id);

        if ($auteur === null) {
            throw $this->createNotFoundException();
        }

        $form = $this->createForm(OwnerType::class, $auteur);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid())
        {
            $em->flush();
Mat's avatar
Mat committed
74
75

            return $this->redirectToRoute('techno_owner_read');
Mat's avatar
Mat committed
76
77
78
79
80
81
82
        }

        return $this->render('@Techno/Owner/update.html.twig', array(
            'id' => $id,
            'formOwner' => $form->createView()
        ));

Mat's avatar
Mat committed
83
84
    }

85

Mat's avatar
Mat committed
86
    /**
Mat's avatar
Mat committed
87
88
    *   @param $id
    *   @return \Symfony\Component\HttpFoundation\Response
Mat's avatar
Mat committed
89
    */
Mat's avatar
Mat committed
90
    public function deleteAction($id)
Mat's avatar
Mat committed
91
    {
Mat's avatar
Mat committed
92
93
94
95
96
97
98
99
100
101
        $em = $this->getDoctrine()->getManager();
        $auteur = $em->getRepository('TechnoBundle:Owner')->findOneByDelete($id);

        if ($auteur !== null)
        {
            $em->remove($auteur);
            $em->flush();
        }

        return $this->redirectToRoute('techno_owner_read');
Mat's avatar
Mat committed
102
103
    }

104
105
106
107
108
109

    /**
    *
    */
    public function mainDisplayAction()
    {
110
        $form = $this->createForm(OwnerAPIType::class);
Mat's avatar
Mat committed
111

112
113
        // charge un service session
        $session = $this->get('session');
114
        $session->set('test', 'oups');
115
116
        dump($session);

Mat's avatar
Mat committed
117
118
119
        return $this->render('@Techno/Ajax/Owner/mainDisplay.html.twig', array(
            'formOwner' => $form->createView()
        ));
120
121
122
    }


Mat's avatar
Mat committed
123
}