DealerController::getEditRenderTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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 as DealerModule;
18
use Dealer\Model\Dealer;
19
use Dealer\Model\DealerQuery;
20
use Propel\Runtime\Propel;
21
use Symfony\Component\HttpFoundation\RedirectResponse;
22
use Thelia\Core\HttpFoundation\JsonResponse;
23
use Thelia\Core\Security\AccessManager;
24
use Thelia\Core\Security\Resource\AdminResources;
25
use Thelia\Tools\URL;
26
27
/**
28
 * Class DealerController
29
 * @package Dealer\Controller
30
 */
31
class DealerController extends BaseController
32
{
33
    /**
34
     * Load an existing object from the database
35
     */
36
    protected function getExistingObject()
37
    {
38
        return DealerQuery::create()->findPk($this->getRequest()->query->get("dealer_id"));
39
    }
40
41
    /**
42
     * Hydrate the update form for this object, before passing it to the update template
43
     *
44
     * @param mixed $object
45
     */
46
    protected function hydrateObjectForm($object)
47
    {
48
        $data = array(
49
            "id" => $object->getId(),
50
            "title" => $object->getTitle(),
51
            "address1" => $object->getAddress1(),
52
            "address2" => $object->getAddress2(),
53
            "address3" => $object->getAddress3(),
54
            "zipcode" => $object->getZipcode(),
55
            "city" => $object->getCity(),
56
            "country_id" => $object->getCountryId(),
57
            "description" => $object->getDescription(),
58
            "big_description" => $object->getBigDescription(),
59
            "hard_open_hour" => $object->getHardOpenHour(),
60
            "latitude" => $object->getLatitude(),
61
            "longitude" => $object->getLongitude(),
62
        );
63
64
        return $this->getUpdateForm($data);
65
    }
66
67
    const CONTROLLER_ENTITY_NAME = "dealer";
68
69
    /**
70
     * Use to get render of list
71
     * @return mixed
72
     */
73
    protected function getListRenderTemplate()
74
    {
75
        return $this->render("dealers");
76
    }
77
78
    /**
79
     * Use to get Edit render
80
     * @return mixed
81
     */
82
    protected function getEditRenderTemplate()
83
    {
84
        return $this->render("dealer-edit");
85
    }
86
87
    /**
88
     * Use to get Create render
89
     * @return mixed
90
     */
91
    protected function getCreateRenderTemplate()
92
    {
93
        // TODO: Implement getCreateRenderTemplate() method.
94
    }
95
96
    /**
97
     * @return mixed
98
     */
99
    protected function getObjectId($object)
100
    {
101
        /** @var Dealer $object */
102
        return $object->getId();
103
    }
104
105
    protected function redirectToListTemplate()
106
    {
107
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer"));
108
    }
109
110
    protected function redirectToEditionTemplate()
111
    {
112
        $id = $this->getRequest()->query->get("dealer_id");
113
114
        return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/module/Dealer/dealer/edit",
115
            ["dealer_id" => $id, ]));
116
    }
117
118
    public function toggleVisibleAction($id)
119
    {
120
        // Check current user authorization
121
        if (null !== $response = $this->checkAuth(AdminResources::MODULE, DealerModule::getModuleCode(),
122
                AccessManager::UPDATE)
123
        ) {
124
            return $response;
125
        }
126
127
        // Error (Default: false)
128
        $error_msg = false;
0 ignored issues
show
Unused Code introduced by
$error_msg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
129
130
        $retour = [];
131
        $code = 200;
132
133
134
        $con = Propel::getConnection();
135
        $con->beginTransaction();
136
137
        try {
138
            $updatedObject = $this->getService()->toggleVisibilityFromId($id);
139
140
            // Check if object exist
141
            if (!$updatedObject) {
142
                throw new \LogicException(
143
                    $this->getTranslator()->trans("No %obj was updated.", ['%obj' => static::CONTROLLER_ENTITY_NAME])
144
                );
145
            }
146
147
            $con->commit();
148
149
            $retour["message"] = "Visibility was updated";
150
        } catch (\Exception $ex) {
151
            $con->rollBack();
152
            // Any other error
153
            $retour["message"] = "Visibility can be updated";
154
            $code = 500;
155
            $retour["error"] = $ex->getMessage();
156
        }
157
158
        return JsonResponse::create($retour, $code);
159
    }
160
}
161