Completed
Push — Recipes ( 931021...804a32 )
by Laurent
03:33
created

MaterialController::newAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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
use AppBundle\Entity\Article;
26
27
/**
28
 * Config\Material controller.
29
 *
30
 * @Route("/material")
31
 */
32
class MaterialController extends AbstractController
33
{
34
    /**
35
     * Lists all Material entities.
36
     *
37
     * @Route("/", name="material")
38
     * @Method("GET")
39
     * @Template()
40
     */
41
    public function indexAction(Request $request)
42
    {
43
        $return = $this->abstractIndexAction('Config\Material', 'material', $request);
44
45
        return $return;
46
    }
47
48
    /**
49
     * Finds and displays a Material entity.
50
     *
51
     * @Route("/{slug}/show", name="material_show")
52
     * @Method("GET")
53
     * @Template()
54
     */
55
    public function showAction(Material $material)
56
    {
57
        $return = $this->abstractShowAction($material, 'material');
58
59
        return $return;
60
    }
61
62
    /**
63
     * Displays a form to create a new Material entity.
64
     *
65
     * @Route("/new", name="material_new")
66
     * @Method("GET")
67
     * @Template()
68
     */
69 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...
70
    {
71
        $return = $this->abstractNewAction(
72
            'Config\Material',
73
            'AppBundle:Config\Material',
74
            MaterialType::class,
75
            'material'
76
        );
77
        $articles = $this->getDoctrine()->getManager()->getRepository('AppBundle:Article')->findAll();
78
        $return['articles'] = $articles;
79
80
        return $return;
81
    }
82
83
    /**
84
     * Creates a new Material entity.
85
     *
86
     * @Route("/admin/create", name="material_create")
87
     * @Method("POST")
88
     * @Template("AppBundle:Config\Material:new.html.twig")
89
     */
90
    public function createAction(Request $request)
91
    {
92
        $return = $this->abstractCreateAction(
93
            $request,
94
            'Config\Material',
95
            'AppBundle:Config\Material',
96
            MaterialType::class,
97
            'material'
98
        );
99
100
        return $return;
101
    }
102
103
    /**
104
     * Displays a form to edit an existing Material entity.
105
     *
106
     * @Route("/admin/{slug}/edit", name="material_edit")
107
     * @Method("GET")
108
     * @Template()
109
     */
110 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...
111
    {
112
        $return = $this->abstractEditAction($material, 'material', MaterialType::class);
113
        $articles = $this->getDoctrine()->getManager()->getRepository('AppBundle:Article')->findAll();
114
        $return['articles'] = $articles;
115
116
        return $return;
117
    }
118
119
    /**
120
     * Edits an existing Material entity.
121
     *
122
     * @Route("/admin/{slug}/update", name="material_update")
123
     * @Method("PUT")
124
     * @Template("AppBundle:Config\Material:edit.html.twig")
125
     */
126
    public function updateAction(Material $material, Request $request)
127
    {
128
        $return = $this->abstractUpdateAction($material, $request, 'material', MaterialType::class);
129
130
        return $return;
131
    }
132
133
    /**
134
     * Save order.
135
     *
136
     * @Route("/order/{entity}/{field}/{type}", name="material_sort")
137
     *
138
     * @param string $entity Entity of the field to sort
139
     * @param string $field  Field to sort
140
     * @param string $type   type of sort
141
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
142
     */
143
    public function sortAction($entity, $field, $type)
144
    {
145
        $this->get('app.helper.controller')->setOrder('material', $entity, $field, $type);
146
147
        return $this->redirect($this->generateUrl('material'));
148
    }
149
150
    /**
151
     * Deletes a Material entity.
152
     *
153
     * @Route("/{id}/delete", name="material_delete", requirements={"id"="\d+"})
154
     * @Method("DELETE")
155
     */
156
    public function deleteAction(Material $material, Request $request)
157
    {
158
        $this->abstractDeleteAction($material, $request, 'material');
159
160
        return $this->redirectToRoute('material');
161
    }
162
}
163