Completed
Push — master ( 4d6a24...d6fdf9 )
by Antony
03:37
created

ContactController::getListRenderTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
/*************************************************************************************/
13
14
namespace Dealer\Controller;
15
16
use Dealer\Controller\Base\BaseController;
17
use Dealer\Dealer;
18
use Symfony\Component\HttpFoundation\RedirectResponse;
19
use Thelia\Core\Security\AccessManager;
20
use Thelia\Core\Security\Resource\AdminResources;
21
use Thelia\Tools\URL;
22
23
/**
24
 * Class ContactController
25
 * @package Dealer\Controller
26
 */
27
class ContactController extends BaseController
28
{
29
    const CONTROLLER_ENTITY_NAME = "dealer-contact";
30
31
    /**
32
     * Use to get render of list
33
     * @return mixed
34
     */
35
    protected function getListRenderTemplate()
36
    {
37
        $id = $this->getRequest()->query->get("dealer_id");
38
39
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer/edit",
40
            ["dealer_id" => $id,]));
41
    }
42
43
    /**
44
     * Must return a RedirectResponse instance
45
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
46
     */
47
    protected function redirectToListTemplate()
48
    {
49
        $id = $this->getRequest()->request->get("dealer_id");
50
51
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer/edit",
52
            ["dealer_id" => $id,]));
53
    }
54
55
    /**
56
     * Use to get Edit render
57
     * @return mixed
58
     */
59
    protected function getEditRenderTemplate()
60
    {
61
        return $this->render("dealer-edit");
62
    }
63
64
    /**
65
     * Use to get Create render
66
     * @return mixed
67
     */
68
    protected function getCreateRenderTemplate()
69
    {
70
        return $this->render("dealer-edit");
71
    }
72
73
    /**
74
     * @return mixed
75
     */
76
    protected function getObjectId($object)
77
    {
78
        $object->getId();
79
    }
80
81
    /**
82
     * Load an existing object from the database
83
     */
84
    protected function getExistingObject()
85
    {
86
        // TODO: Implement getExistingObject() method.
87
    }
88
89
    /**
90
     * Hydrate the update form for this object, before passing it to the update template
91
     *
92
     * @param mixed $object
93
     */
94
    protected function hydrateObjectForm($object)
95
    {
96
        // TODO: Implement hydrateObjectForm() method.
97
    }
98
99
    /**
100
     * Method to get current controller associated service
101
     * @return object
102
     */
103
    protected function getService()
104
    {
105
        if (!$this->service) {
106
            $this->service = $this->getContainer()->get("dealer_contact_service");
107
        }
108
109
        return $this->service;
110
    }
111
112
    public function toggleDefaultAction()
113
    {
114
        // Check current user authorization
115
        if (null !== $response = $this->checkAuth(AdminResources::MODULE, Dealer::getModuleCode(),
116
                AccessManager::UPDATE)
117
        ) {
118
            return $response;
119
        }
120
        try {
121
            $request = $this->getRequest()->request;
122
123
            $data = [
124
                'id' => $request->get("dealer_contact_id"),
125
                'is_default' => $request->get("is_default")
126
            ];
127
128
129
            $this->getService()->setDefault($data);
130
            if ($response == null) {
131
                return $this->redirectToListTemplate();
132
            } else {
133
                return $response;
134
            }
135
        } catch (\Exception $e) {
136
            return $this->renderAfterDeleteError($e);
137
        }
138
    }
139
140
141
}