123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- class DashboardController {
-
- private $toolname;
- private $view;
- private $user_id;
-
-
- public function __construct() {
- $this->user_id = api_get_user_id();
- $this->toolname = 'dashboard';
- $this->view = new View($this->toolname);
- }
-
-
- public function display($msg = false) {
- $data = array();
- $user_id = $this->user_id;
-
- $block_data_without_plugin = DashboardManager::get_block_data_without_plugin();
- $dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks();
- $user_block_data = DashboardManager::get_user_block_data($user_id);
- $user_blocks_id = array_keys($user_block_data);
- if (!empty($dashboard_blocks)) {
- foreach ($dashboard_blocks as $block) {
-
-
- if (!in_array($block['id'], $user_blocks_id)) continue;
-
- $path = $block['path'];
- $controller_class = $block['controller'];
- $filename_controller = $path.'.class.php';
- $dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
- require_once $dashboard_plugin_path.$filename_controller;
- if (class_exists($controller_class)) {
- $obj = new $controller_class($user_id);
-
-
- if (method_exists($obj, 'is_block_visible_for_user')) {
- $is_block_visible_for_user = $obj->is_block_visible_for_user($user_id);
- if (!$is_block_visible_for_user) continue;
- }
-
- $data_block[$path] = $obj->get_block();
-
- $data_block[$path]['column'] = $user_block_data[$block['id']]['column'];
- }
- }
-
- $data['blocks'] = $data_block;
- $data['dashboard_view'] = 'blocks';
- }
-
- if ($msg) {
- $data['msg'] = $msg;
- }
-
-
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('dashboard');
- $this->view->render();
- }
-
-
- public function store_user_block() {
-
- $data = array();
- $user_id = $this->user_id;
- if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
- $enabled_blocks = $_POST['enabled_blocks'];
- $columns = $_POST['columns'];
- $affected_rows = DashboardManager::store_user_blocks($user_id, $enabled_blocks, $columns);
- if ($affected_rows) {
- $data['success'] = true;
- }
- }
- $data['dashboard_view'] = 'list';
-
-
- $this->view->set_data($data);
- $this->view->set_layout('layout');
- $this->view->set_template('dashboard');
- $this->view->render();
- }
-
-
- public function close_user_block($path) {
- $user_id = $this->user_id;
- $result = DashboardManager::close_user_block($user_id, $path);
- $this->display($result);
- }
-
- }
- ?>
|