dashboard_controller.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file contains class used like controller, it should be included inside a dispatcher file (e.g: index.php)
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @package chamilo.dashboard
  7. */
  8. /**
  9. * Controller script. Prepares the common background variables to give to the scripts corresponding to
  10. * the requested action
  11. * @package chamilo.dashboard
  12. */
  13. class DashboardController { // extends Controller {
  14. private $toolname;
  15. private $view;
  16. private $user_id;
  17. /**
  18. * Constructor
  19. */
  20. public function __construct() {
  21. $this->user_id = api_get_user_id();
  22. $this->toolname = 'dashboard';
  23. $this->view = new View($this->toolname);
  24. }
  25. /**
  26. * Display blocks from dashboard plugin paths
  27. * @param string message (optional)
  28. * render to dashboard.php view
  29. */
  30. public function display($msg = false) {
  31. $data = array();
  32. $user_id = $this->user_id;
  33. $block_data_without_plugin = DashboardManager::get_block_data_without_plugin();
  34. $dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks();
  35. $user_block_data = DashboardManager::get_user_block_data($user_id);
  36. $user_blocks_id = array_keys($user_block_data);
  37. if (!empty($dashboard_blocks)) {
  38. foreach ($dashboard_blocks as $block) {
  39. // display only user blocks
  40. if (!in_array($block['id'], $user_blocks_id)) continue;
  41. $path = $block['path'];
  42. $controller_class = $block['controller'];
  43. $filename_controller = $path.'.class.php';
  44. $dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
  45. require_once $dashboard_plugin_path.$filename_controller;
  46. $obj = new $controller_class($user_id);
  47. // check if user is allowed to see the block
  48. if (method_exists($obj, 'is_block_visible_for_user')) {
  49. $is_block_visible_for_user = $obj->is_block_visible_for_user($user_id);
  50. if (!$is_block_visible_for_user) continue;
  51. }
  52. $data_block[$path] = $obj->get_block();
  53. // set user block column
  54. $data_block[$path]['column'] = $user_block_data[$block['id']]['column'];
  55. }
  56. $data['blocks'] = $data_block;
  57. $data['dashboard_view'] = 'blocks';
  58. }
  59. if ($msg) {
  60. $data['msg'] = $msg;
  61. }
  62. // render to the view
  63. $this->view->set_data($data);
  64. $this->view->set_layout('layout');
  65. $this->view->set_template('dashboard');
  66. $this->view->render();
  67. }
  68. /**
  69. * This method allow store user blocks from dashboard manager
  70. * render to dashboard.php view
  71. */
  72. public function store_user_block() {
  73. $data = array();
  74. $user_id = $this->user_id;
  75. if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
  76. $enabled_blocks = $_POST['enabled_blocks'];
  77. $columns = $_POST['columns'];
  78. $affected_rows = DashboardManager::store_user_blocks($user_id, $enabled_blocks, $columns);
  79. if ($affected_rows) {
  80. $data['success'] = true;
  81. }
  82. }
  83. $data['dashboard_view'] = 'list';
  84. // render to the view
  85. $this->view->set_data($data);
  86. $this->view->set_layout('layout');
  87. $this->view->set_template('dashboard');
  88. $this->view->render();
  89. }
  90. /**
  91. * This method is used when you close a block from dashboard block interface
  92. * render to dashboard.php view
  93. */
  94. public function close_user_block($path) {
  95. $user_id = $this->user_id;
  96. $result = DashboardManager::close_user_block($user_id, $path);
  97. $this->display($result);
  98. }
  99. }
  100. ?>