|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* @package sitemaker |
|
6
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
|
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace blitze\sitemaker\model\entity; |
|
12
|
|
|
|
|
13
|
|
|
use blitze\sitemaker\model\base_entity; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @method int get_bid() |
|
17
|
|
|
* @method object set_icon($icon) |
|
18
|
|
|
* @method string get_icon() |
|
19
|
|
|
* @method object set_name($name) |
|
20
|
|
|
* @method string get_name() |
|
21
|
|
|
* @method string get_title() |
|
22
|
|
|
* @method object set_route_id(integer $route_id) |
|
23
|
|
|
* @method integer get_route_id() |
|
24
|
|
|
* @method object set_position($position) |
|
25
|
|
|
* @method string get_position() |
|
26
|
|
|
* @method object set_weight(integer $weight) |
|
27
|
|
|
* @method integer get_weight() |
|
28
|
|
|
* @method object set_style(integer $style) |
|
29
|
|
|
* @method integer get_style() |
|
30
|
|
|
* @method object set_status(boolean $status) |
|
31
|
|
|
* @method boolean get_status() |
|
32
|
|
|
* @method object set_type(integer $type) |
|
33
|
|
|
* @method integer get_type() |
|
34
|
|
|
* @method object set_hide_title(boolean $hide_title) |
|
35
|
|
|
* @method boolean get_hide_title() |
|
36
|
|
|
* @method object set_hash($hash) |
|
37
|
|
|
* @method string get_hash() |
|
38
|
|
|
* @method object set_view($view) |
|
39
|
|
|
* @method boolean get_view() |
|
40
|
|
|
*/ |
|
41
|
|
|
final class block extends base_entity |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var integer */ |
|
44
|
|
|
protected $bid; |
|
45
|
|
|
|
|
46
|
|
|
/** @var string */ |
|
47
|
|
|
protected $icon = ''; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string */ |
|
50
|
|
|
protected $name = ''; |
|
51
|
|
|
|
|
52
|
|
|
/** @var string */ |
|
53
|
|
|
protected $title = ''; |
|
54
|
|
|
|
|
55
|
|
|
/** @var integer */ |
|
56
|
|
|
protected $route_id = 0; |
|
57
|
|
|
|
|
58
|
|
|
/** @var string */ |
|
59
|
|
|
protected $position = ''; |
|
60
|
|
|
|
|
61
|
|
|
/** @var integer */ |
|
62
|
|
|
protected $weight = 0; |
|
63
|
|
|
|
|
64
|
|
|
/** @var integer */ |
|
65
|
|
|
protected $style = 0; |
|
66
|
|
|
|
|
67
|
|
|
/** @var string */ |
|
68
|
|
|
protected $permission = ''; |
|
69
|
|
|
|
|
70
|
|
|
/** @var string */ |
|
71
|
|
|
protected $class = ''; |
|
72
|
|
|
|
|
73
|
|
|
/** @var boolean */ |
|
74
|
|
|
protected $status = true; |
|
75
|
|
|
|
|
76
|
|
|
/** @var integer */ |
|
77
|
|
|
protected $type = 0; |
|
78
|
|
|
|
|
79
|
|
|
/** @var boolean */ |
|
80
|
|
|
protected $hide_title = false; |
|
81
|
|
|
|
|
82
|
|
|
/** @var string */ |
|
83
|
|
|
protected $hash = ''; |
|
84
|
|
|
|
|
85
|
|
|
/** @var string */ |
|
86
|
|
|
protected $settings = ''; |
|
87
|
|
|
|
|
88
|
|
|
/** @var string */ |
|
89
|
|
|
protected $view = ''; |
|
90
|
|
|
|
|
91
|
|
|
/** @var array */ |
|
92
|
|
|
protected $required_fields = array('name', 'route_id', 'position', 'style'); |
|
93
|
|
|
|
|
94
|
|
|
/** @var array */ |
|
95
|
|
|
protected $db_fields = array( |
|
96
|
|
|
'icon', |
|
97
|
|
|
'name', |
|
98
|
|
|
'title', |
|
99
|
|
|
'route_id', |
|
100
|
|
|
'position', |
|
101
|
|
|
'weight', |
|
102
|
|
|
'style', |
|
103
|
|
|
'permission', |
|
104
|
|
|
'class', |
|
105
|
|
|
'status', |
|
106
|
|
|
'type', |
|
107
|
|
|
'hide_title', |
|
108
|
|
|
'hash', |
|
109
|
|
|
'settings', |
|
110
|
|
|
'view', |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Set block ID |
|
115
|
|
|
* @param int $bid |
|
116
|
|
|
* @return $this |
|
117
|
|
|
*/ |
|
118
|
|
|
public function set_bid($bid) |
|
119
|
|
|
{ |
|
120
|
|
|
if (!$this->bid) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->bid = (int) $bid; |
|
123
|
|
|
} |
|
124
|
|
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Set title |
|
129
|
|
|
* @param string $title |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
|
|
public function set_title($title) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->title = utf8_ucfirst(trim($title)); |
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Set css class |
|
140
|
|
|
* @param string $class |
|
141
|
|
|
* @return $this |
|
142
|
|
|
*/ |
|
143
|
|
|
public function set_class($class) |
|
144
|
|
|
{ |
|
145
|
|
|
$this->class = ($class) ? ' ' . trim($class) : ''; |
|
146
|
|
|
return $this; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Set permissions |
|
151
|
|
|
* Going from ['type' => 1, 'groups' => [1,2,3]] to 1,2,3:1 |
|
152
|
|
|
* @param array|string $permission |
|
153
|
|
|
* @return $this |
|
154
|
|
|
*/ |
|
155
|
|
|
public function set_permission($permission) |
|
156
|
|
|
{ |
|
157
|
|
|
$this->permission = $permission; |
|
|
|
|
|
|
158
|
|
|
if (is_array($permission)) |
|
159
|
|
|
{ |
|
160
|
|
|
$permission = array_merge(['groups' => [], 'type' => 1], $permission); |
|
161
|
|
|
$permission['groups'] = join(',', array_filter($permission['groups'])); |
|
162
|
|
|
$this->permission = join(':', $permission); |
|
163
|
|
|
} |
|
164
|
|
|
return $this; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Get permissions |
|
169
|
|
|
* Going from 1,2,3:0 to ['type' => 0, 'groups' => [1,2,3]] or 1,2,3 to ['type' => 1, 'groups' => [1,2,3]] |
|
170
|
|
|
* @return array |
|
171
|
|
|
*/ |
|
172
|
|
|
public function get_permission() |
|
173
|
|
|
{ |
|
174
|
|
|
[$groups, $type] = array_pad(explode(':', $this->permission), 2, 0); |
|
175
|
|
|
return [ |
|
176
|
|
|
'type' => (int) $type, |
|
177
|
|
|
'groups' => array_map('intval', array_filter(explode(',', $groups))), |
|
178
|
|
|
]; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Set settings |
|
183
|
|
|
* @param array|string $settings |
|
184
|
|
|
* @return $this |
|
185
|
|
|
*/ |
|
186
|
|
|
public function set_settings($settings) |
|
187
|
|
|
{ |
|
188
|
|
|
if ($this->set_array_field('settings', $settings)) |
|
189
|
|
|
{ |
|
190
|
|
|
$this->hash = md5($this->settings); |
|
191
|
|
|
} |
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get settings |
|
197
|
|
|
* @return array |
|
198
|
|
|
*/ |
|
199
|
|
|
public function get_settings() |
|
200
|
|
|
{ |
|
201
|
|
|
return ($this->settings) ? json_decode($this->settings, true) : array(); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* |
|
206
|
|
|
*/ |
|
207
|
|
|
public function __clone() |
|
208
|
|
|
{ |
|
209
|
|
|
$this->bid = null; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.