Newer
Older
*/
public function __construct($params=array())
{
// default
$default = array(
'type' => 'content',
'content' => '',
'title' => '',
'description' => '',
'project' => '',
'areas' => ''
);
$this->setAttributes( $default );
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
foreach ( $default as $key => $value )
{
if ( isset( $params[ $key ] ) ) {
$this->setAttribute( $key, $params[ $key ] );
}
}
// default settings from control
$Control = $this->_getControl();
$Manager = new Manager();
$availableSettings = $Manager->getAvailableBrickSettingsByBrickType(
$this->getAttribute( 'type' )
);
foreach ( $availableSettings as $entry ) {
$this->_settings[ $entry['name'] ] = false;
}
// control default settings
if ( $Control )
{
$controlSettings = $Control->getAttributes();
foreach ( $this->_settings as $key => $value )
{
if ( isset( $controlSettings[ $key ] ) ) {
$this->_settings[ $key ] = $controlSettings[ $key ];
}
}
}
// settings from database
if ( isset( $params['settings'] ) )
{
$settings = $params['settings'];
if ( is_string( $settings ) ) {
$settings = json_decode( $settings, true );
}
foreach ( $this->_settings as $key => $value )
{
if ( isset( $settings[ $key ] ) ) {
$this->_settings[ $key ] = $settings[ $key ];
}
/**
* Check, if control canbe created
*
* @throws QUI\Exception
* @return QUI\Bricks\Brick
*/
public function check()
{
$Control = $this->_getControl();
if ( !$Control ) {
throw new QUI\Exception( 'Control not found. Brick could not be created' );
}
return $Control;
}
if ( $this->getAttribute( 'type' ) == 'content' ) {
return $this->getAttribute( 'content' );
}
$Control = $this->_getControl();
if ( !$Control ) {
throw new QUI\Exception( 'Control not found. Brick could not be created' );
}
$Control->setAttributes( $this->getSettings() );
return $Control->create();
}
/**
* Return the internal control
* @return QUI\Control|Bool
*/
protected function _getControl()
{
if ( !is_callable( $Ctrl ) && !class_exists( $Ctrl ) ) {
$Control = new $Ctrl( $this->getSettings() );
if ( !($Control instanceof QUI\Control) || !$Control ) {
*/
public function getSettings()
{
return $this->_settings;
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* Set brick settings
*
* @param Array $settings
*/
public function setSettings($settings)
{
foreach ( $settings as $key => $value ) {
$this->setSetting( $key, $value );
}
}
/**
* Return the setting of the brick
*
* @param String $name - Name of the setting
* @return Bool|String
*/
public function getSetting($name)
{
if ( isset( $this->_settings[ $name ] ) ) {
return $this->_settings[ $name ];
}
return false;
}
/**
* Set a brick setting
*
* @param String $name - name of the setting
* @param String $value - value of the setting
*/
public function setSetting($name, $value)
{
if ( isset( $this->_settings[ $name ] ) ) {
$this->_settings[ $name ] = $value;
}
}
}