block_global_info.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 $path;
  25. private $permission = [];
  26. /**
  27. * Constructor.
  28. *
  29. * @param int $user_id
  30. */
  31. public function __construct($user_id)
  32. {
  33. $this->user_id = $user_id;
  34. $this->path = 'block_global_info';
  35. if ($this->is_block_visible_for_user($user_id)) {
  36. //$this->courses = CourseManager::get_courses_followed_by_drh($user_id);
  37. }
  38. }
  39. /**
  40. * This method check if a user is allowed to see the block inside dashboard interface.
  41. *
  42. * @param int User id
  43. *
  44. * @return bool Is block visible for user
  45. */
  46. public function is_block_visible_for_user($user_id)
  47. {
  48. $user_info = api_get_user_info($user_id);
  49. $user_status = $user_info['status'];
  50. $is_block_visible_for_user = false;
  51. if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) {
  52. $is_block_visible_for_user = true;
  53. }
  54. return $is_block_visible_for_user;
  55. }
  56. /**
  57. * This method return content html containing information
  58. * about courses and its position for showing it inside dashboard interface
  59. * it's important to use the name 'get_block' for beeing used from dashboard controller.
  60. *
  61. * @return array column and content html
  62. */
  63. public function get_block()
  64. {
  65. global $charset;
  66. $column = 2;
  67. $data = [];
  68. $content = $this->get_content_html();
  69. $html = '<div class="panel panel-default" id="intro">
  70. <div class="panel-heading">'.get_lang('GlobalPlatformInformation').'
  71. <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.'">
  72. <em class="fa fa-times"></em>
  73. </a></div>
  74. </div>
  75. <div class="panel-body">
  76. '.$content.'
  77. </div>
  78. </div>
  79. ';
  80. $data['column'] = $column;
  81. $data['content_html'] = $html;
  82. return $data;
  83. }
  84. /**
  85. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface.
  86. *
  87. * @return string content html
  88. */
  89. public function get_content_html()
  90. {
  91. $global_data = $this->get_global_information_data();
  92. $content = '<h4>'.get_lang('GlobalPlatformInformation').'</h4>';
  93. $data_table = null;
  94. if (!empty($global_data)) {
  95. $data_table = '<table class="table table-bordered">';
  96. $i = 1;
  97. foreach ($global_data as $data) {
  98. if ($i % 2 == 0) {
  99. $class_tr = 'row_odd';
  100. } else {
  101. $class_tr = 'row_even';
  102. }
  103. $data_table .= '<tr class="'.$class_tr.'">';
  104. foreach ($data as $cell) {
  105. $data_table .= '<td align="right">'.$cell.'</td>';
  106. }
  107. $data_table .= '</tr>';
  108. $i++;
  109. }
  110. $data_table .= '</table>';
  111. } else {
  112. $data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
  113. }
  114. $content .= $data_table;
  115. return $content;
  116. }
  117. /**
  118. * Get global information data.
  119. *
  120. * @return array
  121. */
  122. public function get_global_information_data()
  123. {
  124. // Two-dimensional array with data about the system
  125. $path = api_get_path(WEB_CODE_PATH);
  126. // Check total number of users
  127. $global_info = [
  128. [get_lang('CountUsers'), '<a href="'.$path.'admin/user_list.php">'.Statistics::countUsers().'</a>'],
  129. // Check only active users
  130. [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>'],
  131. // Check number of courses
  132. [get_lang('NumberOfCoursesTotal'), '<a href="'.$path.'admin/course_list.php">'.Statistics::countCourses().'</a>'],
  133. [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>'],
  134. [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>'],
  135. [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>'],
  136. [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>'],
  137. [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>'],
  138. ];
  139. return $global_info;
  140. }
  141. }