Completed
Push — develop ( 8387b5...1b51bd )
by Daniel
11:34
created

block::set_title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\model\entity;
11
12
use blitze\sitemaker\model\base_entity;
13
14
/**
15
 * @method int get_bid()
16
 * @method object set_icon($icon)
17
 * @method string get_icon()
18
 * @method object set_name($name)
19
 * @method string get_name()
20
 * @method string get_title()
21
 * @method object set_route_id(integer $route_id)
22
 * @method integer get_route_id()
23
 * @method object set_position($position)
24
 * @method string get_position()
25
 * @method object set_weight(integer $weight)
26
 * @method integer get_weight()
27
 * @method object set_style(integer $style)
28
 * @method integer get_style()
29
 * @method object set_status(boolean $status)
30
 * @method boolean get_status()
31
 * @method object set_type(integer $type)
32
 * @method integer get_type()
33
 * @method object set_hide_title(boolean $hide_title)
34
 * @method boolean get_hide_title()
35
 * @method object set_hash($hash)
36
 * @method string get_hash()
37
 * @method object set_view($view)
38
 * @method boolean get_view()
39
 */
40
final class block extends base_entity
41
{
42
	/** @var integer */
43
	protected $bid;
44
45
	/** @var string */
46
	protected $icon = '';
47
48
	/** @var string */
49
	protected $name = '';
50
51
	/** @var string */
52
	protected $title = '';
53
54
	/** @var integer */
55
	protected $route_id = 0;
56
57
	/** @var string */
58
	protected $position = '';
59
60
	/** @var integer */
61
	protected $weight = 0;
62
63
	/** @var integer */
64
	protected $style = 0;
65
66
	/** @var string */
67
	protected $permission = '';
68
69
	/** @var string */
70
	protected $class = '';
71
72
	/** @var boolean */
73
	protected $status = true;
74
75
	/** @var integer */
76
	protected $type = 0;
77
78
	/** @var boolean */
79
	protected $hide_title = false;
80
81
	/** @var string */
82
	protected $hash = '';
83
84
	/** @var string */
85
	protected $settings = '';
86
87
	/** @var string */
88
	protected $view = '';
89
90
	/** @var array */
91
	protected $required_fields = array('name', 'route_id', 'position', 'style');
92
93
	/** @var array */
94
	protected $db_fields = array(
95
		'icon',
96
		'name',
97
		'title',
98
		'route_id',
99
		'position',
100
		'weight',
101
		'style',
102
		'permission',
103
		'class',
104
		'status',
105
		'type',
106
		'hide_title',
107
		'hash',
108
		'settings',
109
		'view',
110
	);
111
112
	/**
113
	 * Set block ID
114
	 * @param int $bid
115
	 * @return $this
116
	 */
117 57
	public function set_bid($bid)
118
	{
119 57
		if (!$this->bid)
120 57
		{
121 57
			$this->bid = (int) $bid;
122 57
		}
123 57
		return $this;
124
	}
125
126
	/**
127
	 * Set title
128
	 * @param string $title
129
	 * @return $this
130
	 */
131 53
	public function set_title($title)
132
	{
133 53
		$this->title = utf8_ucfirst(trim($title));
134 53
		return $this;
135
	}
136
137
	/**
138
	 * Set css class
139
	 * @param string $class
140
	 * @return $this
141
	 */
142 52
	public function set_class($class)
143
	{
144 52
		$this->class = ($class) ? ' ' . trim($class) : '';
145 52
		return $this;
146
	}
147
148
	/**
149
	 * Set permissions
150
	 * @param array|string $permission
151
	 * @return $this
152
	 */
153 53
	public function set_permission($permission)
154
	{
155 53
		$this->permission = is_array($permission) ? join(',', array_filter($permission)) : $permission;
156 53
		return $this;
157
	}
158
159
	/**
160
	 * Get permissions
161
	 * @return array
162
	 */
163 34
	public function get_permission()
164
	{
165 34
		return array_map('intval', array_filter(explode(',', $this->permission)));
166
	}
167
168
	/**
169
	 * Set settings
170
	 * @param array|string $settings
171
	 * @return $this
172
	 */
173 54
	public function set_settings($settings)
174
	{
175 54
		if (!is_array($settings))
176 54
		{
177 51
			$this->settings = $settings;
178 51
		}
179 37
		else if (sizeof($settings))
180 37
		{
181 34
			$this->settings = json_encode($settings);
182 34
			$this->hash = md5($this->settings);
183 34
		}
184 54
		return $this;
185
	}
186
187
	/**
188
	 * Get settings
189
	 * @return array
190
	 */
191 39
	public function get_settings()
192
	{
193 39
		return ($this->settings) ? json_decode($this->settings, true) : array();
194
	}
195
196
	/**
197
	 *
198
	 */
199 6
	public function __clone()
200
	{
201 6
		$this->bid = null;
202 6
	}
203
}
204