|
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 Dealer\Model\DealerAdmin; |
|
19
|
|
|
use Propel\Runtime\Propel; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
21
|
|
|
use Thelia\Core\Security\AccessManager; |
|
22
|
|
|
use Thelia\Core\Security\Resource\AdminResources; |
|
23
|
|
|
use Thelia\Tools\URL; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class AdminLinkController |
|
27
|
|
|
* @package Dealer\Controller |
|
28
|
|
|
*/ |
|
29
|
|
|
class AdminLinkController extends BaseController |
|
30
|
|
|
{ |
|
31
|
|
|
const CONTROLLER_ENTITY_NAME = "dealer_admin_link"; |
|
32
|
|
|
const CONTROLLER_CHECK_RESOURCE = Dealer::RESOURCES_USERS; |
|
33
|
|
|
/** |
|
34
|
|
|
* @inheritDoc |
|
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#users", |
|
41
|
|
|
["dealer_id" => $id, ])); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @inheritDoc |
|
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#users", |
|
52
|
|
|
["dealer_id" => $id, ])); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritDoc |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function getEditRenderTemplate() |
|
59
|
|
|
{ |
|
60
|
|
|
// TODO: Implement getEditRenderTemplate() method. |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @inheritDoc |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getCreateRenderTemplate() |
|
67
|
|
|
{ |
|
68
|
|
|
// TODO: Implement getCreateRenderTemplate() method. |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @inheritDoc |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getObjectId($object) |
|
75
|
|
|
{ |
|
76
|
|
|
/** @var DealerAdmin $object */ |
|
77
|
|
|
return $object->getId(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @inheritDoc |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function getExistingObject() |
|
84
|
|
|
{ |
|
85
|
|
|
// TODO: Implement getExistingObject() method. |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @inheritDoc |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function hydrateObjectForm($object) |
|
92
|
|
|
{ |
|
93
|
|
|
// TODO: Implement hydrateObjectForm() method. |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Method to get current controller users service |
|
98
|
|
|
* @return object |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getService() |
|
101
|
|
|
{ |
|
102
|
|
|
if (!$this->service) { |
|
103
|
|
|
$this->service = $this->getContainer()->get("dealer_admin_link_service"); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $this->service; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Method to get Base Creation Form |
|
111
|
|
|
* @return \Thelia\Form\BaseForm |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function getCreationForm() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->createForm(static::CONTROLLER_ENTITY_NAME . "_create"); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Delete an object |
|
120
|
|
|
* |
|
121
|
|
|
* @return \Thelia\Core\HttpFoundation\Response the response |
|
122
|
|
|
*/ |
|
123
|
|
|
public function deleteAction() |
|
124
|
|
|
{ |
|
125
|
|
|
// Check current user authorization |
|
126
|
|
|
if (null !== $response = $this->checkAuth(AdminResources::MODULE, Dealer::getModuleCode(), |
|
127
|
|
|
AccessManager::DELETE) |
|
128
|
|
|
) { |
|
129
|
|
|
return $response; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$con = Propel::getConnection(); |
|
133
|
|
|
$con->beginTransaction(); |
|
134
|
|
|
try { |
|
135
|
|
|
// Check token |
|
136
|
|
|
$this->getTokenProvider()->checkToken( |
|
137
|
|
|
$this->getRequest()->query->get("_token") |
|
138
|
|
|
); |
|
139
|
|
|
$data = [ |
|
140
|
|
|
"admin_id" => $this->getRequest()->request->get(static::CONTROLLER_ENTITY_NAME . "_id"), |
|
141
|
|
|
"dealer_id" => $this->getRequest()->request->get("dealer_id"), |
|
142
|
|
|
]; |
|
143
|
|
|
$this->getService()->deleteFromArray($data); |
|
144
|
|
|
$con->commit(); |
|
145
|
|
|
|
|
146
|
|
|
if ($this->getRequest()->request->get("success_url") == null) { |
|
147
|
|
|
return $this->redirectToListTemplate(); |
|
|
|
|
|
|
148
|
|
|
} else { |
|
149
|
|
|
return new RedirectResponse(URL::getInstance()->absoluteUrl($this->getRequest()->request->get("success_url"))); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
} catch (\Exception $e) { |
|
152
|
|
|
$con->rollBack(); |
|
153
|
|
|
|
|
154
|
|
|
return $this->renderAfterDeleteError($e); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.