yf_dashboards2 classdashboards2 for user.
| File | plugins/dashboards/classes/yf_dashboards2.class.php |
|---|---|
| Use | _class('dashboards2') |
A site sets them in its config with $PROJECT_CONF['dashboards2']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$_dashboard_data |
null |
|
$_name |
null |
public function display($params = [])
Designed to be used by other modules to show configured dashboard.
public function display($params = [])
{
$this->_time_start = microtime(true);
$name = null;
if (is_string($params)) {
$name = $params;
}
if ( ! is_array($params)) {
$params = [];
}
if ( ! $params['name'] && $name) {
$params['name'] = $name;
}
if ( ! $params['name']) {
return _e('Empty dashboard name');
}
$this->_name = $params['name'];
$dashboard_data = $this->view($params);
$this->_debug_info['total_time'] = round(microtime(true) - $this->_time_start, 5);
DEBUG_MODE && debug('dashboard', $this->_debug_info);
return $dashboard_data;
}
public function view($params = [])
Similar to 'display', but for usage inside this module (action links and more).
public function view($params = [])
{
if ( ! is_array($params)) {
$params = [];
}
$ds_name = isset($params['name']) ? $params['name'] : ($this->_name ? $this->_name : ($_GET['id'] ?? null));
$this->_debug_info['name'] = $ds_name;
$ds = $this->_get_dashboard_data($ds_name);
if ( ! $ds['id']) {
return _e('No such record');
}
$grid = '';
if (isset($ds['data']['rows']) && is_array($ds['data']['rows'])) {
$grid = $this->_get_grid($ds['data']['rows']);
}
return $grid;
}
_ hooks and helpers; not routable as page actionspublic function _get_dashboard_data($id = '')
public function _get_dashboard_data($id = '')
{
$params = null;
if ( ! $id) {
$id = $this->_name ? $this->_name : $_GET['id'];
}
if ( ! $id) {
return false;
}
if (isset($this->_dashboard_data[$id])) {
return $this->_dashboard_data[$id];
}
$ds = db()->get('SELECT * FROM ' . db('dashboards2') . ' WHERE name="' . db()->es($id) . '" OR id=' . (int) $id);
if ($ds) {
$ds['data'] = object_to_array(json_decode($ds['data']));
}
$this->_dashboard_data[$id] = $ds;
return $ds;
}
public function _get_grid($data = [])
public function _get_grid($data = [])
{
$rows = null;
foreach ((array) $data as $row_id => $row_items) {
$cols = '';
if (isset($row_items['cols']) && is_array($row_items['cols'])) {
foreach ((array) $row_items['cols'] as $col_id => $col_items) {
$content = '';
if (is_array($col_items['class'])) {
$col_class = $col_items['class'][0];
} else {
$col_class = $col_items['class'];
}
$row_class = $col_items['class'][0];
if (isset($col_items['content']) && is_array($col_items['content'])) {
foreach ((array) $col_items['content'] as $content_id => $content_items) {
if (isset($content_items['rows']) && is_array($content_items['rows'])) {
$content .= $this->_get_grid($content_items['rows']);
}
if (isset($content_items['widget']) && is_array($content_items['widget'])) {
$content .= $this->_view_widget_items($content_items['widget']);
}
}
}
$id = '';
if ( ! empty($col_items['id'])) {
$id = ' id="' . $col_items['id'] . '" ';
}
if (is_array($col_items['class'])) {
$cols .= '<div class="col-md-' . $col_class . '"' . $id . ' > ' . $content . ' </div>';
} else {
$cols .= '<div class="' . $col_class . '"' . $id . '> ' . $content . ' </div>';
}
}
}
$rows[] = [
'cols' => $cols,
'id' => $row_items['id'],
'class' => trim($row_items['class']),
];
}
$replace = [
'rows' => $rows,
];
return tpl()->parse(__CLASS__ . '/view_main', $replace);
}
public function _init()
public function _init()
{
conf('css_framework', 'bs3');
}
public function _view_widget_items($widgets = [])
public function _view_widget_items($widgets = [])
{
$info = $saved_config = null;
$_orig_object = ($_GET['object'] ?? null);
$_orig_action = ($_GET['action'] ?? null);
$is_cloneable_item = true;
$module_name = '';
$method_name = '';
$content = '';
if ($is_cloneable_item) {
if ($widgets['type'] == 'php') {
list($module_name, $method_name) = explode('.', $widgets['val']);
} elseif ($widgets['type'] == 'stpl') {
}
}
if ($module_name && $method_name) {
$_time_start = microtime(true);
$saved_config = null;
$module_obj = module_safe($module_name);
if (is_object($module_obj) && method_exists($module_obj, $method_name)) {
$content = $module_obj->$method_name($saved_config);
$this->_debug_info['widgets'][] = [
'class_name' => $module_name,
'action' => $method_name,
'time' => round(microtime(true) - $_time_start, 5),
];
} else {
trigger_error(__CLASS__ . ': called module.method from widget not exists: ' . $module_name . '.' . $method_name . '', E_USER_WARNING);
}
$_GET['object'] = $_orig_object;
$_GET['action'] = $_orig_action;
}
return $content;
}