block_global_info.class.php 7.0 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 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 = '
  63. <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. <i class="fa fa-times"></i>
  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 = '<div style="margin:10px;">';
  86. $content = '<h4>'.get_lang('GlobalPlatformInformation').'</h4>';
  87. $data_table = null;
  88. if (!empty($global_data)) {
  89. $data_table = '<table class="table table-bordered" width:"95%">';
  90. $i = 1;
  91. foreach ($global_data as $data) {
  92. if ($i%2 == 0) {
  93. $class_tr = 'row_odd';
  94. } else {
  95. $class_tr = 'row_even';
  96. }
  97. $data_table .= '<tr class="'.$class_tr.'">';
  98. foreach ($data as $cell) {
  99. $data_table .= '<td align="right">'.$cell.'</td>';
  100. }
  101. $data_table .= '</tr>';
  102. $i++;
  103. }
  104. $data_table .= '</table>';
  105. } else {
  106. $data_table .= get_lang('ThereIsNoInformationAboutThePlatform');
  107. }
  108. $content .= $data_table;
  109. //$content .= '</div>';
  110. return $content;
  111. }
  112. /**
  113. * Get global information data
  114. * @return array
  115. */
  116. function get_global_information_data()
  117. {
  118. // Two-dimensional array with data about the system
  119. $path = api_get_path(WEB_CODE_PATH);
  120. // Check total number of users
  121. $global_info = array(
  122. array(get_lang('CountUsers'), '<a href="'.$path.'admin/user_list.php">'.Statistics::countUsers().'</a>'),
  123. // Check only active users
  124. 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>'),
  125. // Check number of courses
  126. array(get_lang('NumberOfCoursesTotal'), '<a href="'.$path.'admin/course_list.php">'.Statistics::countCourses().'</a>'),
  127. 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>'),
  128. 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>'),
  129. 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>'),
  130. 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>'),
  131. 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>')
  132. );
  133. return $global_info;
  134. }
  135. }