block_session.class.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * This file is part of session block plugin for dashboard,
  4. * it should be required inside dashboard controller for showing it into dashboard interface from plattform
  5. * @package chamilo.dashboard
  6. * @author Christian Fasanando
  7. */
  8. /**
  9. * required files for getting data
  10. */
  11. require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  13. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'course_description.lib.php';
  15. /**
  16. * This class is used like controller for this session block plugin,
  17. * the class name must be registered inside path.info file (e.g: controller = "BlockSession"), so dashboard controller will be instantiate it
  18. * @package chamilo.dashboard
  19. */
  20. class BlockSession extends Block {
  21. private $user_id;
  22. private $sessions;
  23. private $path;
  24. /**
  25. * Constructor
  26. */
  27. public function __construct ($user_id) {
  28. $this->user_id = $user_id;
  29. $this->sessions = SessionManager::get_assigned_sessions_to_hr_manager($user_id);
  30. $this->path = 'block_session';
  31. }
  32. /**
  33. * This method return content html containing information about sessions and its position for showing it inside dashboard interface
  34. * it's important to use the name 'get_block' for beeing used from dashboard controller
  35. * @return array column and content html
  36. */
  37. public function get_block() {
  38. global $charset;
  39. $column = 2;
  40. $data = array();
  41. $content = $this->get_content_html();
  42. $content_html = '
  43. <li class="widget color-red" id="intro">
  44. <div class="widget-head">
  45. <h3>'.get_lang('SessionsInformation').'</h3>
  46. <div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.Display::return_icon('close.gif',get_lang('Close')).'</a></div>
  47. </div>
  48. <div class="widget-content">
  49. '.$content.'
  50. </div>
  51. </li>
  52. ';
  53. $data['column'] = $column;
  54. $data['content_html'] = $content_html;
  55. return $data;
  56. }
  57. /**
  58. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  59. * @return string content html
  60. */
  61. public function get_content_html() {
  62. $content = '';
  63. $sessions = $this->sessions;
  64. $content = '<div style="margin:10px;">';
  65. $content .= '<h3><font color="#000">'.get_lang('YourTrainingsSessionList').'</font></h3>';
  66. if (count($sessions) > 0) {
  67. foreach ($sessions as $session) {
  68. $session_id = intval($session['id']);
  69. $content .= '<div style="margin-top:10px;"><strong>'.$session['name'].'</strong> - '.get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'].'</div>';
  70. $courses = Tracking ::get_courses_list_from_session($session_id);
  71. $courses_table = '';
  72. if (count($courses)) {
  73. $courses_table = '<div style="margin:10px;margin-bottom:20px;"><table class="data_table" width:"95%">';
  74. $courses_table .= '<tr>
  75. <th>'.get_lang('Course').'</th>
  76. <th width="10%">'.get_lang('Time').'</th>
  77. <th width="10%">'.get_lang('Progress').'</th>
  78. <th width="10%">'.get_lang('Score').'</th>
  79. <th width="10%">'.get_lang('TematicAdvance').'</th>
  80. </tr>';
  81. $i = 1;
  82. foreach ($courses as $course) {
  83. $course_code = Database::escape_string($course['course_code']);
  84. $course_info = CourseManager :: get_course_information($course_code);
  85. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  86. // students directly subscribed to the course
  87. $sql = "SELECT id_user FROM $tbl_session_course_user srcu WHERE srcu. course_code='$course_code'";
  88. $rs = Database::query($sql);
  89. $users = array();
  90. while ($row = Database::fetch_array($rs)) {
  91. $users[] = $row['id_user'];
  92. }
  93. $time_spent_on_course = api_time_to_hms(Tracking :: get_time_spent_on_the_course($users, $course_code));
  94. $progress = Tracking :: get_avg_student_progress($users, $course_code);
  95. $score = Tracking :: get_avg_student_score($users, $course_code);
  96. $progress = empty($progress) ? '0%' : $progress.'%';
  97. $score = empty($score) ? '0%' : $score.'%';
  98. $tematic_advance_progress = 0;
  99. $course_description = new CourseDescription();
  100. $course_description->set_session_id($session_id);
  101. $tematic_advance = $course_description->get_data_by_description_type(8, $course_code);
  102. if (!empty($tematic_advance)) {
  103. $tematic_advance_progress = $tematic_advance['progress'];
  104. }
  105. if ($i%2 == 0) $class_tr = 'row_odd';
  106. else $class_tr = 'row_even';
  107. $courses_table .= '<tr class="'.$class_tr.'">
  108. <td align="right">'.$course_info['title'].'</td>
  109. <td align="right">'.$time_spent_on_course.'</td>
  110. <td align="right">'.$progress.'</td>
  111. <td align="right">'.$score.'</td>
  112. <td align="right">'.$tematic_advance_progress.'%</td>
  113. </tr>';
  114. $i++;
  115. }
  116. $courses_table .= '</table></div>';
  117. } else {
  118. $courses_table .= '<div style="margin:10px;">'.get_lang('ThereAreNoCoursesInformationsInsideThisSession').'</div>';
  119. }
  120. $content .= $courses_table;
  121. }
  122. } else {
  123. $content .= '<div style="margin:20px;">'.get_lang('ThereAreNoInformationsAboutYoursSessions').'</div>';
  124. }
  125. if (count($sessions) > 0) {
  126. $content .= '<div style="text-align:right;margin-top:10px;"><a href="#">'.get_lang('SeeMore').'</a></div>';
  127. }
  128. $content .= '</div>';
  129. return $content;
  130. }
  131. /**
  132. * Get number of sessions
  133. * @return int
  134. */
  135. function get_number_of_sessions() {
  136. return count($this->sessions);
  137. }
  138. }
  139. ?>