1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Admingenerator\GeneratorBundle\Generator; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Util\Inflector; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This class describes an action |
9
|
|
|
* |
10
|
|
|
* @author cedric Lombardot |
11
|
|
|
* @author Piotr Gołębiewski <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Action |
14
|
|
|
{ |
15
|
|
|
protected $name; |
16
|
|
|
|
17
|
|
|
protected $type; |
18
|
|
|
|
19
|
|
|
protected $label; |
20
|
|
|
|
21
|
|
|
protected $icon; |
22
|
|
|
|
23
|
|
|
protected $class; |
24
|
|
|
|
25
|
|
|
protected $options = array(); |
26
|
|
|
|
27
|
|
|
protected $submit; |
28
|
|
|
|
29
|
|
|
protected $route; |
30
|
|
|
|
31
|
|
|
protected $params = array(); |
32
|
|
|
|
33
|
|
|
protected $confirmMessage; |
34
|
|
|
|
35
|
|
|
protected $confirmModal; |
36
|
|
|
|
37
|
|
|
protected $csrfProtected = false; |
38
|
|
|
|
39
|
|
|
protected $forceIntermediate = false; |
40
|
|
|
|
41
|
|
|
protected $credentials = 'AdmingenAllowed'; |
42
|
|
|
|
43
|
|
|
public function __construct($name, $type = 'custom') |
44
|
|
|
{ |
45
|
|
|
$this->name = $name; |
46
|
|
|
$this->type = $type; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setProperty($option, $value) |
50
|
|
|
{ |
51
|
|
|
$option = Inflector::classify($option); |
52
|
|
|
call_user_func_array(array($this, 'set'.$option), array($value)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getName() |
56
|
|
|
{ |
57
|
|
|
return $this->name; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getTwigName() |
61
|
|
|
{ |
62
|
|
|
return strtolower(str_replace('-', '_', $this->name)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getType() |
66
|
|
|
{ |
67
|
|
|
return $this->type; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $label |
72
|
|
|
*/ |
73
|
|
|
public function setLabel($label) |
74
|
|
|
{ |
75
|
|
|
$this->label = $label; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getLabel() |
79
|
|
|
{ |
80
|
|
|
if (isset($this->label)) { |
81
|
|
|
return $this->label; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $this->humanize($this->getName()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $icon |
89
|
|
|
*/ |
90
|
|
|
public function setIcon($icon) |
91
|
|
|
{ |
92
|
|
|
$this->icon = $icon; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getIcon() |
96
|
|
|
{ |
97
|
|
|
return $this->icon; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $class |
102
|
|
|
*/ |
103
|
|
|
public function setClass($class) |
104
|
|
|
{ |
105
|
|
|
$this->class = $class; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getClass() |
109
|
|
|
{ |
110
|
|
|
return $this->class; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $route |
115
|
|
|
*/ |
116
|
|
|
public function setRoute($route) |
117
|
|
|
{ |
118
|
|
|
$this->route = $route; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getRoute() |
122
|
|
|
{ |
123
|
|
|
return $this->route; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param boolean $submit |
128
|
|
|
*/ |
129
|
|
|
public function setSubmit($submit) |
130
|
|
|
{ |
131
|
|
|
$this->submit = (bool) $submit; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function getSubmit() |
135
|
|
|
{ |
136
|
|
|
return $this->submit; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
private function humanize($text) |
140
|
|
|
{ |
141
|
|
|
return ucfirst(str_replace('_', ' ', $text)); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param string $confirmMessage |
146
|
|
|
*/ |
147
|
|
|
public function setConfirm($confirmMessage) |
148
|
|
|
{ |
149
|
|
|
$this->confirmMessage = $confirmMessage; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function getConfirm() |
153
|
|
|
{ |
154
|
|
|
return $this->confirmMessage; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $confirmModal |
159
|
|
|
*/ |
160
|
|
|
public function setConfirmModal($confirmModal) |
161
|
|
|
{ |
162
|
|
|
$this->confirmModal = $confirmModal; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function getConfirmModal() |
166
|
|
|
{ |
167
|
|
|
return $this->confirmModal; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param boolean $csrfProtected |
172
|
|
|
*/ |
173
|
|
|
public function setCsrfProtected($csrfProtected) |
174
|
|
|
{ |
175
|
|
|
$this->csrfProtected = $csrfProtected; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function getCsrfProtected() |
179
|
|
|
{ |
180
|
|
|
return $this->csrfProtected; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function setCredentials($credentials) |
184
|
|
|
{ |
185
|
|
|
$this->credentials = $credentials; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function setForceIntermediate($forceIntermediate) |
189
|
|
|
{ |
190
|
|
|
$this->forceIntermediate = $forceIntermediate; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function getForceIntermediate() |
194
|
|
|
{ |
195
|
|
|
return $this->forceIntermediate; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function getCredentials() |
199
|
|
|
{ |
200
|
|
|
return $this->credentials; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function getParams() |
204
|
|
|
{ |
205
|
|
|
return $this->params; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function setParams(array $params) |
209
|
|
|
{ |
210
|
|
|
$this->params = $params; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function getOptions() |
214
|
|
|
{ |
215
|
|
|
return $this->options; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function setOptions(array $options) |
219
|
|
|
{ |
220
|
|
|
$this->options = $options; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|