block_global_info.class.php 6.9 KB

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