block_global_info.class.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. *
  8. * @package chamilo.dashboard
  9. *
  10. * @author Yannick Warnier
  11. */
  12. /**
  13. * This class is used like controller for this global info block plugin
  14. * the class name must be registered inside path.info file
  15. * (e.g: controller = "BlockGlobalInfo"), so dashboard controller can
  16. * instantiate it.
  17. *
  18. * @package chamilo.dashboard
  19. */
  20. class BlockGlobalInfo extends Block
  21. {
  22. private $user_id;
  23. private $courses;
  24. private $permission = [];
  25. /**
  26. * Constructor.
  27. *
  28. * @param int $user_id
  29. */
  30. public function __construct($user_id)
  31. {
  32. $this->user_id = $user_id;
  33. $this->path = 'block_global_info';
  34. }
  35. /**
  36. * This method check if a user is allowed to see the block inside dashboard interface.
  37. *
  38. * @param int User id
  39. *
  40. * @return bool Is block visible for user
  41. */
  42. public function is_block_visible_for_user($user_id)
  43. {
  44. $user_info = api_get_user_info($user_id);
  45. $user_status = $user_info['status'];
  46. $is_block_visible_for_user = false;
  47. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  48. $is_block_visible_for_user = true;
  49. }
  50. return $is_block_visible_for_user;
  51. }
  52. /**
  53. * This method return content html containing information
  54. * about courses and its position for showing it inside dashboard interface
  55. * it's important to use the name 'get_block' for beeing used from dashboard controller.
  56. *
  57. * @return array column and content html
  58. */
  59. public function get_block()
  60. {
  61. $column = 2;
  62. $data = [];
  63. $html = $this->getBlockCard(
  64. get_lang('Global platform information'),
  65. $this->getContent()
  66. );
  67. $data['column'] = $column;
  68. $data['content_html'] = $html;
  69. return $data;
  70. }
  71. /**
  72. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface.
  73. *
  74. * @return string content html
  75. */
  76. public function getContent()
  77. {
  78. $global_data = $this->get_global_information_data();
  79. $data_table = null;
  80. if (!empty($global_data)) {
  81. $data_table = '<table class="table table-bordered">';
  82. $i = 1;
  83. foreach ($global_data as $data) {
  84. if ($i % 2 == 0) {
  85. $class_tr = 'row_odd';
  86. } else {
  87. $class_tr = 'row_even';
  88. }
  89. $data_table .= '<tr class="'.$class_tr.'">';
  90. foreach ($data as $cell) {
  91. $data_table .= '<td align="right">'.$cell.'</td>';
  92. }
  93. $data_table .= '</tr>';
  94. $i++;
  95. }
  96. $data_table .= '</table>';
  97. } else {
  98. $data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
  99. }
  100. return $data_table;
  101. }
  102. /**
  103. * Get global information data.
  104. *
  105. * @return array
  106. */
  107. public function get_global_information_data()
  108. {
  109. // Two-dimensional array with data about the system
  110. $path = api_get_path(WEB_CODE_PATH);
  111. // Check total number of users
  112. $global_info = [
  113. [get_lang('Number of users'), '<a href="'.$path.'admin/user_list.php">'.Statistics::countUsers().'</a>'],
  114. // Check only active users
  115. [get_lang('Number of active users'), '<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>'],
  116. // Check number of courses
  117. [get_lang('Total number of courses'), '<a href="'.$path.'admin/course_list.php">'.Statistics::countCourses().'</a>'],
  118. [get_lang('Number of public courses'), '<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>'],
  119. [get_lang('Number of open courses'), '<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>'],
  120. [get_lang('Number of private courses'), '<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>'],
  121. [get_lang('Number of closed courses'), '<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>'],
  122. [get_lang('Number of hidden courses'), '<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>'],
  123. ];
  124. return $global_info;
  125. }
  126. }