block_global_info.class.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /* See license terms in /license.txt */
  3. /**
  4. * This file is part of global info block plugin for dashboard,
  5. * it should be required inside the dashboard controller for
  6. * showing it into the dashboard interface.
  7. * @package chamilo.dashboard
  8. * @author Yannick Warnier
  9. */
  10. /**
  11. * This class is used like controller for this global info block plugin
  12. * the class name must be registered inside path.info file
  13. * (e.g: controller = "BlockGlobalInfo"), so dashboard controller can
  14. * instantiate it
  15. * @package chamilo.dashboard
  16. */
  17. class BlockGlobalInfo extends Block
  18. {
  19. private $user_id;
  20. private $courses;
  21. private $path;
  22. private $permission = array();
  23. /**
  24. * Constructor
  25. * @param int $user_id
  26. */
  27. public function __construct($user_id)
  28. {
  29. $this->user_id = $user_id;
  30. $this->path = 'block_global_info';
  31. if ($this->is_block_visible_for_user($user_id)) {
  32. //$this->courses = CourseManager::get_courses_followed_by_drh($user_id);
  33. }
  34. }
  35. /**
  36. * This method check if a user is allowed to see the block inside dashboard interface
  37. * @param int User id
  38. * @return bool Is block visible for user
  39. */
  40. public function is_block_visible_for_user($user_id)
  41. {
  42. $user_info = api_get_user_info($user_id);
  43. $user_status = $user_info['status'];
  44. $is_block_visible_for_user = false;
  45. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  46. $is_block_visible_for_user = true;
  47. }
  48. return $is_block_visible_for_user;
  49. }
  50. /**
  51. * This method return content html containing information
  52. * about courses and its position for showing it inside dashboard interface
  53. * it's important to use the name 'get_block' for beeing used from dashboard controller
  54. * @return array column and content html
  55. */
  56. public function get_block()
  57. {
  58. global $charset;
  59. $column = 2;
  60. $data = array();
  61. $content = $this->get_content_html();
  62. $html = '<div class="panel panel-default" id="intro">
  63. <div class="panel-heading">'.get_lang('GlobalPlatformInformation').'
  64. <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
  65. <em class="fa fa-times"></em>
  66. </a></div>
  67. </div>
  68. <div class="panel-body">
  69. '.$content.'
  70. </div>
  71. </div>
  72. ';
  73. $data['column'] = $column;
  74. $data['content_html'] = $html;
  75. return $data;
  76. }
  77. /**
  78. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  79. * @return string content html
  80. */
  81. public function get_content_html()
  82. {
  83. $global_data = $this->get_global_information_data();
  84. $content = '<h4>'.get_lang('GlobalPlatformInformation').'</h4>';
  85. $data_table = null;
  86. if (!empty($global_data)) {
  87. $data_table = '<table class="table table-bordered" width="95%">';
  88. $i = 1;
  89. foreach ($global_data as $data) {
  90. if ($i % 2 == 0) {
  91. $class_tr = 'row_odd';
  92. } else {
  93. $class_tr = 'row_even';
  94. }
  95. $data_table .= '<tr class="'.$class_tr.'">';
  96. foreach ($data as $cell) {
  97. $data_table .= '<td align="right">'.$cell.'</td>';
  98. }
  99. $data_table .= '</tr>';
  100. $i++;
  101. }
  102. $data_table .= '</table>';
  103. } else {
  104. $data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
  105. }
  106. $content .= $data_table;
  107. //$content .= '</div>';
  108. return $content;
  109. }
  110. /**
  111. * Get global information data
  112. * @return array
  113. */
  114. public function get_global_information_data()
  115. {
  116. // Two-dimensional array with data about the system
  117. $path = api_get_path(WEB_CODE_PATH);
  118. // Check total number of users
  119. $global_info = array(
  120. array(get_lang('CountUsers'), '<a href="'.$path.'admin/user_list.php">'.Statistics::countUsers().'</a>'),
  121. // Check only active users
  122. array(get_lang('NumberOfUsersActive'), '<a href="'.$path.'admin/user_list.php?keyword_firstname=&amp;keyword_lastname=&amp;keyword_username=&amp;keyword_email=&amp;keyword_officialcode=&amp;keyword_status=%25&amp;keyword_active=1&amp;submit=&amp;_qf__advanced_search=">'.Statistics::countUsers(null, null, null, true).'</a>'),
  123. // Check number of courses
  124. array(get_lang('NumberOfCoursesTotal'), '<a href="'.$path.'admin/course_list.php">'.Statistics::countCourses().'</a>'),
  125. array(get_lang('NumberOfCoursesPublic'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_WORLD.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_OPEN_WORLD).'</a>'),
  126. array(get_lang('NumberOfCoursesOpen'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_PLATFORM.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_OPEN_PLATFORM).'</a>'),
  127. array(get_lang('NumberOfCoursesPrivate'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_REGISTERED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_REGISTERED).'</a>'),
  128. array(get_lang('NumberOfCoursesClosed'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_CLOSED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_CLOSED).'</a>'),
  129. array(get_lang('NumberOfCoursesHidden'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_HIDDEN.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_HIDDEN).'</a>')
  130. );
  131. return $global_info;
  132. }
  133. }