ContactController::toggleDefaultAction()   A
last analyzed

Complexity

Conditions 4
Paths 7

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 4
nc 7
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
    const CONTROLLER_CHECK_RESOURCE = Dealer::RESOURCES_CONTACT;
31
32
    /**
33
     * Use to get render of list
34
     * @return mixed
35
     */
36
    protected function getListRenderTemplate()
37
    {
38
        $id = $this->getRequest()->query->get("dealer_id");
39
40
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer/edit",
41
            ["dealer_id" => $id, ]));
42
    }
43
44
    /**
45
     * Must return a RedirectResponse instance
46
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
47
     */
48
    protected function redirectToListTemplate()
49
    {
50
        $id = $this->getRequest()->request->get("dealer_id");
51
52
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer/edit",
53
            ["dealer_id" => $id, ]));
54
    }
55
56
    /**
57
     * Use to get Edit render
58
     * @return mixed
59
     */
60
    protected function getEditRenderTemplate()
61
    {
62
        return $this->render("dealer-edit");
63
    }
64
65
    /**
66
     * Use to get Create render
67
     * @return mixed
68
     */
69
    protected function getCreateRenderTemplate()
70
    {
71
        return $this->render("dealer-edit");
72
    }
73
74
    /**
75
     * @return mixed
76
     */
77
    protected function getObjectId($object)
78
    {
79
        $object->getId();
80
    }
81
82
    /**
83
     * Load an existing object from the database
84
     */
85
    protected function getExistingObject()
86
    {
87
        // TODO: Implement getExistingObject() method.
88
    }
89
90
    /**
91
     * Hydrate the update form for this object, before passing it to the update template
92
     *
93
     * @param mixed $object
94
     */
95
    protected function hydrateObjectForm($object)
96
    {
97
        // TODO: Implement hydrateObjectForm() method.
98
    }
99
100
    /**
101
     * Method to get current controller associated service
102
     * @return object
103
     */
104
    protected function getService()
105
    {
106
        if (!$this->service) {
107
            $this->service = $this->getContainer()->get("dealer_contact_service");
108
        }
109
110
        return $this->service;
111
    }
112
113
    public function toggleDefaultAction()
114
    {
115
        // Check current user authorization
116
        if (null !== $response = $this->checkAuth(AdminResources::MODULE, Dealer::getModuleCode(),
117
                AccessManager::UPDATE)
118
        ) {
119
            return $response;
120
        }
121
        try {
122
            $request = $this->getRequest()->request;
123
124
            $data = [
125
                'id' => $request->get("dealer_contact_id"),
126
                'is_default' => $request->get("is_default")
127
            ];
128
129
130
            $this->getService()->setDefault($data);
131
            if ($response == null) {
132
                return $this->redirectToListTemplate();
133
            } else {
134
                return $response;
135
            }
136
        } catch (\Exception $e) {
137
            return $this->renderAfterDeleteError($e);
138
        }
139
    }
140
}
141