Completed
Push — master ( 5e4f38...1af8b6 )
by Laurent
08:07 queued 04:24
created

MaterialController::createAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
/**
3
 * MterialController controller des matières.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version GIT: <git_id>
12
 *
13
 * @link      https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\Controller\Config;
16
17
use Symfony\Component\HttpFoundation\Request;
18
use AppBundle\Controller\AbstractController;
19
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
20
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
21
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
22
23
use AppBundle\Entity\Config\Material;
24
use AppBundle\Form\Type\Config\MaterialType;
25
26
/**
27
 * Config\Material controller.
28
 *
29
 * @Route("/material")
30
 */
31
class MaterialController extends AbstractController
32
{
33
    /**
34
     * Lists all Material entities.
35
     *
36
     * @Route("/", name="material")
37
     * @Method("GET")
38
     * @Template()
39
     */
40
    public function indexAction(Request $request)
41
    {
42
        $return = $this->abstractIndexAction('Config\Material', 'material', $request);
43
44
        return $return;
45
    }
46
47
    /**
48
     * Finds and displays a Material entity.
49
     *
50
     * @Route("/{slug}/show", name="material_show")
51
     * @Method("GET")
52
     * @Template()
53
     */
54
    public function showAction(Material $material)
55
    {
56
        $return = $this->abstractShowAction($material, 'material');
57
58
        return $return;
59
    }
60
61
    /**
62
     * Displays a form to create a new Material entity.
63
     *
64
     * @Route("/new", name="material_new")
65
     * @Method("GET")
66
     * @Template()
67
     */
68 View Code Duplication
    public function newAction()
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $return = $this->abstractNewAction(
71
            'Config\Material',
72
            'AppBundle:Config\Material',
73
            MaterialType::class,
74
            'material'
75
        );
76
        $articles = $this->getDoctrine()->getManager()->getRepository('AppBundle:Article')->findAll();
77
        $return['articles'] = $articles;
78
79
        return $return;
80
    }
81
82
    /**
83
     * Creates a new Material entity.
84
     *
85
     * @Route("/admin/create", name="material_create")
86
     * @Method("POST")
87
     * @Template("AppBundle:Config\Material:new.html.twig")
88
     */
89
    public function createAction(Request $request)
90
    {
91
        $return = $this->abstractCreateAction(
92
            $request,
93
            'Config\Material',
94
            'AppBundle:Config\Material',
95
            MaterialType::class,
96
            'material'
97
        );
98
99
        return $return;
100
    }
101
102
    /**
103
     * Displays a form to edit an existing Material entity.
104
     *
105
     * @Route("/admin/{slug}/edit", name="material_edit")
106
     * @Method("GET")
107
     * @Template()
108
     */
109 View Code Duplication
    public function editAction(Material $material)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $return = $this->abstractEditAction($material, 'material', MaterialType::class);
112
        $articles = $this->getDoctrine()->getManager()->getRepository('AppBundle:Article')->findAll();
113
        $return['articles'] = $articles;
114
115
        return $return;
116
    }
117
118
    /**
119
     * Edits an existing Material entity.
120
     *
121
     * @Route("/admin/{slug}/update", name="material_update")
122
     * @Method("PUT")
123
     * @Template("AppBundle:Config\Material:edit.html.twig")
124
     */
125
    public function updateAction(Material $material, Request $request)
126
    {
127
        $return = $this->abstractUpdateAction($material, $request, 'material', MaterialType::class);
128
129
        return $return;
130
    }
131
132
    /**
133
     * Save order.
134
     *
135
     * @Route("/order/{entity}/{field}/{type}", name="material_sort")
136
     *
137
     * @param string $entity Entity of the field to sort
138
     * @param string $field  Field to sort
139
     * @param string $type   type of sort
140
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
141
     */
142
    public function sortAction($entity, $field, $type)
143
    {
144
        $this->get('app.helper.controller')->setOrder('material', $entity, $field, $type);
145
146
        return $this->redirect($this->generateUrl('material'));
147
    }
148
149
    /**
150
     * Deletes a Material entity.
151
     *
152
     * @Route("/{id}/delete", name="material_delete", requirements={"id"="\d+"})
153
     * @Method("DELETE")
154
     */
155
    public function deleteAction(Material $material, Request $request)
156
    {
157
        $this->abstractDeleteAction($material, $request, 'material');
158
159
        return $this->redirectToRoute('material');
160
    }
161
}
162