1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Models\SmartProperties\Properties\AbstractProperty; |
4
|
|
|
|
5
|
|
|
use Nip\Records\Record as Record; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Generic |
9
|
|
|
* @package ByTIC\Models\SmartProperties\Properties\AbstractProperty |
10
|
|
|
*/ |
11
|
|
|
abstract class Generic |
12
|
|
|
{ |
13
|
|
|
use Traits\HasItemTrait; |
14
|
|
|
use Traits\HasManagerTrait; |
15
|
|
|
use Traits\HasNameTrait; |
16
|
|
|
|
17
|
|
|
protected $label = null; |
18
|
|
|
|
19
|
|
|
protected $label_short = null; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var null|string |
24
|
|
|
*/ |
25
|
|
|
protected $field; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param $name |
29
|
|
|
* @return null |
30
|
|
|
*/ |
31
|
|
|
public function __get($name) |
32
|
|
|
{ |
33
|
|
|
$method = 'get' . ucfirst($name); |
34
|
|
|
if (method_exists($this, $method)) { |
35
|
|
|
return $this->$method(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return null; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param bool $short |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
public function getLabelHTML($short = false) |
46
|
|
|
{ |
47
|
|
|
return '<span class="' . $this->getLabelClasses() . '" rel="tooltip" title="' . $this->getLabel() . '" |
|
|
|
|
48
|
|
|
style="' . $this->getColorCSS() . '"> |
49
|
|
|
' . $this->getIconHTML() . ' |
50
|
|
|
' . $this->getLabel($short) . ' |
|
|
|
|
51
|
|
|
</span>'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* get the label class name |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function getLabelClasses() |
60
|
|
|
{ |
61
|
|
|
return 'label label-' . $this->getColorClass(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the color class |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getColorClass() |
70
|
|
|
{ |
71
|
|
|
return 'default'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get Property label |
76
|
|
|
* |
77
|
|
|
* @param bool $short short flag |
78
|
|
|
* |
79
|
|
|
* @return null |
80
|
|
|
*/ |
81
|
|
|
public function getLabel($short = false) |
82
|
|
|
{ |
83
|
|
|
if (!$this->label) { |
84
|
|
|
$this->label = $this->generateLabel(); |
85
|
|
|
if ($this->hasShortLabel()) { |
86
|
|
|
$this->label_short = $this->generateLabelShort(); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $short ? $this->label_short : $this->label; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
protected function generateLabel() |
97
|
|
|
{ |
98
|
|
|
return $this->getManager()->translate($this->getLabelSlug() . '.' . $this->getName()); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
abstract protected function getLabelSlug(); |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return boolean |
108
|
|
|
*/ |
109
|
|
|
protected function hasShortLabel() |
110
|
|
|
{ |
111
|
|
|
return true; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
protected function generateLabelShort() |
118
|
|
|
{ |
119
|
|
|
return $this->getManager()->translate($this->getLabelSlug() . '.' . $this->getName() . '.short'); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getColorCSS() |
126
|
|
|
{ |
127
|
|
|
$css = []; |
128
|
|
|
if ($this->getBGColor()) { |
129
|
|
|
$css[] = 'background-color: ' . $this->getBGColor(); |
130
|
|
|
} |
131
|
|
|
if ($this->getFGColor()) { |
132
|
|
|
$css[] = 'color: ' . $this->getFGColor(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
return implode(';', $css); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return bool|string |
140
|
|
|
*/ |
141
|
|
|
public function getBGColor() |
142
|
|
|
{ |
143
|
|
|
return false; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool|string |
148
|
|
|
*/ |
149
|
|
|
public function getFGColor() |
150
|
|
|
{ |
151
|
|
|
return false; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function getIconHTML() |
158
|
|
|
{ |
159
|
|
|
$icon = $this->getIcon(); |
160
|
|
|
$return = ''; |
161
|
|
|
if ($icon) { |
|
|
|
|
162
|
|
|
$return .= '<span class="glyphicon glyphicon-white ' . $icon . '"></span> '; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $return; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return bool|string |
170
|
|
|
*/ |
171
|
|
|
public function getIcon() |
172
|
|
|
{ |
173
|
|
|
return false; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return bool|mixed |
178
|
|
|
*/ |
179
|
|
|
public function update() |
180
|
|
|
{ |
181
|
|
|
$item = $this->getItem(); |
182
|
|
|
if ($item) { |
183
|
|
|
$this->preValueChange(); |
184
|
|
|
/** @noinspection PhpUndefinedFieldInspection */ |
185
|
1 |
|
$item->{$this->getField()} = $this->getName(); |
186
|
|
|
$this->preUpdate(); |
187
|
1 |
|
$return = $item->saveRecord(); |
|
|
|
|
188
|
1 |
|
$this->postUpdate(); |
189
|
1 |
|
|
190
|
|
|
return $return; |
191
|
1 |
|
} |
192
|
1 |
|
|
193
|
1 |
|
return false; |
194
|
1 |
|
} |
195
|
|
|
|
196
|
1 |
|
public function preValueChange() |
197
|
|
|
{ |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return null|string |
202
|
|
|
*/ |
203
|
|
|
public function getField() |
204
|
|
|
{ |
205
|
1 |
|
return $this->field; |
206
|
|
|
} |
207
|
1 |
|
|
208
|
|
|
/** |
209
|
|
|
* @param null|string $field |
210
|
|
|
*/ |
211
|
|
|
public function setField($field) |
212
|
|
|
{ |
213
|
|
|
$this->field = $field; |
214
|
8 |
|
} |
215
|
|
|
|
216
|
8 |
|
public function preUpdate() |
217
|
|
|
{ |
218
|
8 |
|
} |
219
|
|
|
|
220
|
|
|
public function postUpdate() |
221
|
1 |
|
{ |
222
|
|
|
} |
223
|
1 |
|
|
224
|
|
|
/** |
225
|
|
|
* @return string |
226
|
|
|
*/ |
227
|
|
|
public function getMessageType() |
228
|
1 |
|
{ |
229
|
|
|
return 'info'; |
230
|
1 |
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return string |
234
|
|
|
*/ |
235
|
|
|
public function __toString(): string |
236
|
14 |
|
{ |
237
|
|
|
return $this->getName(); |
238
|
14 |
|
} |
239
|
|
|
} |
240
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.