Размер файла: 1.78Kb
<?php
/**
* An extending of standart WebModule class.
* Allows to use settings
*/
class WebModule extends CWebModule {
/**
* Meta information about module
*/
private $_meta = array();
/**
* Initializes module
*/
protected function init() {
// get meta information from cache or parse meta.xml
if (($data = Yii::app()->cache->get($this->name.'.meta')) !== false) {
$this->_meta = $data;
} else if (file_exists(Yii::getPathOfAlias($this->name).'/meta.xml')) {
$meta = json_decode(json_encode((array)simplexml_load_file(Yii::getPathOfAlias($this->name).'/meta.xml')), 1);
$this->flatArray($this->_meta, $meta);
Yii::app()->cache->set($this->name.'.meta', $this->_meta, 0, new CFileCacheDependency(Yii::getPathOfAlias($this->name).'/meta.xml'));
}
}
/**
* Returns meta value
* @param string $property Property
* @return null|string Null, if property is undefined
*/
public function getMeta($property) {
if (isset($this->_meta[$property]))
return $this->_meta[$property];
return null;
}
/**
* Renders an admin widget
*/
public function renderAdminWidget() {
Yii::app()->controller->renderPartial($this->id.'.views.admin.widget', array(
'module' => $this,
'context' => Yii::app()->controller,
));
}
/**
* Recursively converts nested array into a flat one with preserved keys connected with connector.
* @param array $result Resulting array
* @param array $array Source array
* @param string $prefix Key's prefix
* @param string $connector Levels connector
*/
private function flatArray(array &$result, array $array, $prefix = null, $connector = '.') {
foreach ($array as $key => $value) {
if (is_array($value))
$this->flatArray($result, $value, $prefix.$key.$connector, $connector);
else
$result[$prefix.$key] = $value;
}
}
}