block_daily.class.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * This file is part of course block plugin for dashboard,
  4. * it should be required inside dashboard controller for showing it into dashboard interface from plattform.
  5. *
  6. * @package chamilo.dashboard
  7. *
  8. * @author Marco Sousa original code
  9. * @author Julio Montoya class named was changed of name, and some minor changes
  10. */
  11. /**
  12. * required files for getting data.
  13. */
  14. /**
  15. * This class is used like controller for this course block plugin,
  16. * the class name must be registered inside path.info file
  17. * (e.g: controller = "BlockDiario"), so dashboard controller will be instantiate it.
  18. *
  19. * @package chamilo.dashboard
  20. */
  21. class BlockDaily extends Block
  22. {
  23. private $user_id;
  24. private $courses;
  25. private $permission = [DRH];
  26. /**
  27. * Constructor.
  28. */
  29. public function __construct($user_id)
  30. {
  31. $this->user_id = $user_id;
  32. $this->path = 'block_daily';
  33. if ($this->is_block_visible_for_user($user_id)) {
  34. $this->courses = CourseManager::get_courses_followed_by_drh(
  35. $user_id
  36. );
  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(
  52. $user_status,
  53. $this->permission
  54. )
  55. ) {
  56. $is_block_visible_for_user = true;
  57. }
  58. return $is_block_visible_for_user;
  59. }
  60. /**
  61. * This method return content html containing information about courses and its position for showing it inside dashboard interface
  62. * it's important to use the name 'get_block' for beeing used from dashboard controller.
  63. *
  64. * @return array column and content html
  65. */
  66. public function get_block()
  67. {
  68. $column = 2;
  69. $data = [];
  70. $html = $this->getBlockCard(
  71. get_lang('Assessments and attendances'),
  72. $this->getContent()
  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. *
  81. * @return string content html
  82. */
  83. public function getContent()
  84. {
  85. $course_data = $this->get_course_information_data();
  86. $content = '<h4>'.get_lang('Your courses').'</h4>';
  87. $data_table = null;
  88. if (!empty($course_data)) {
  89. $data_table .= '<table class="data_table" width:"95%">';
  90. $data_table .= '<tr>
  91. <th>'.get_lang('Course title').'</th>
  92. <th width="20%">'.get_lang('Learners').'</th>
  93. <th width="20%">'.get_lang('Score').'</th>
  94. <th width="20%">'.get_lang('Attendances').'</th>
  95. </tr>';
  96. $i = 1;
  97. foreach ($course_data as $course) {
  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. if (!isset($course[3])) {
  105. $course[3] = get_lang('Not available');
  106. }
  107. foreach ($course as $cell) {
  108. $data_table .= '<td align="right">'.$cell.'</td>';
  109. }
  110. $data_table .= '</tr>';
  111. $i++;
  112. }
  113. $data_table .= '</table>';
  114. } else {
  115. $data_table .= get_lang('There is no available information about your courses');
  116. }
  117. $content .= $data_table;
  118. if (!empty($course_data)) {
  119. $content .= '<div style="text-align:right;margin-top:10px;">
  120. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('See more').'</a></div>';
  121. }
  122. //$content .= '</div>';
  123. return $content;
  124. }
  125. /**
  126. * Get number of courses.
  127. *
  128. * @return int
  129. */
  130. public function get_number_of_courses()
  131. {
  132. return count($this->courses);
  133. }
  134. /**
  135. * Get course information data.
  136. *
  137. * @return array
  138. */
  139. public function get_course_information_data()
  140. {
  141. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  142. $course_data = [];
  143. $courses = $this->courses;
  144. foreach ($courses as $row_course) {
  145. $score = null;
  146. $courseId = $row_course['c_id'];
  147. $course_info = api_get_course_info_by_id($courseId);
  148. $course_code = $course_info['code'];
  149. if (empty($course_info)) {
  150. continue;
  151. }
  152. // Attendance table
  153. $table_course = Database::get_course_table(TABLE_ATTENDANCE);
  154. $sql = "SELECT id, name, attendance_qualify_max FROM $table_course
  155. WHERE c_id = ".$course_info['real_id']." AND active = 1 AND session_id = 0";
  156. $rs = Database::query($sql);
  157. $attendance = [];
  158. $attendances = [];
  159. while ($row = Database::fetch_array($rs, 'ASSOC')) {
  160. $attendance['done'] = $row['attendance_qualify_max'];
  161. $attendance['id'] = $row['id'];
  162. //$attendance['name'] = $row['name'];
  163. $attendance['course_code'] = $course_info['code'];
  164. if ($attendance['done'] != '0') {
  165. $attendances[] = '<a href="'.api_get_path(WEB_PATH).'main/attendance/index.php?cidReq='.$attendance['course_code'].'&action=attendance_sheet_print&attendance_id='.$attendance['id'].'">'.Display::return_icon('printmgr.gif', get_lang('Print')).'</a>';
  166. } else {
  167. $attendances[] = get_lang("Not available");
  168. }
  169. }
  170. if (count($attendances) == 0) {
  171. $attendances[] = get_lang("Not available");
  172. }
  173. // Number of students
  174. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user
  175. WHERE course_rel_user.status=".STUDENT." AND course_rel_user.c_id=$courseId";
  176. $rs = Database::query($sql);
  177. $users = [];
  178. while ($row = Database::fetch_array($rs)) {
  179. $users[] = $row['user_id'];
  180. }
  181. if (count($users) > 0) {
  182. $nb_students_in_course = count($users);
  183. }
  184. if (!empty($tematic_advance)) {
  185. $tematic_advance_progress = '<a title="'.get_lang(
  186. 'GoToThematicAdvance'
  187. ).'" href="'.api_get_path(
  188. WEB_CODE_PATH
  189. ).'attendance/index.php?cidReq='.$course_code.'&action=attendance_sheet_print&attendance_id=">'.$tematic_advance.'%</a>';
  190. } else {
  191. $tematic_advance_progress = '0%';
  192. }
  193. // Score
  194. $tbl_grade_categories = Database::get_main_table(
  195. TABLE_MAIN_GRADEBOOK_CATEGORY
  196. );
  197. $sql = "SELECT id from ".$tbl_grade_categories."
  198. WHERE course_code ='".$course_code."'";
  199. $rs = Database::query($sql);
  200. $category = null;
  201. while ($row = Database::fetch_array($rs)) {
  202. $category = $row['id'];
  203. }
  204. if (!empty($category)) {
  205. $cat = Category::load($category);
  206. $eval = $cat[0]->get_evaluations();
  207. if (count($eval) > 0) {
  208. $i = 0;
  209. foreach ($eval as $item) {
  210. $score .= '<a href="'.api_get_path(WEB_PATH).'main/gradebook/gradebook_view_result.php?export=pdf&cat_code='.$cat[0]->get_id().'&official_code='.$cat[0]->get_course_code().'&selecteval='.$item->get_id().'">'.$item->get_name().'</a>';
  211. if (count($eval) - 1 != $i) {
  212. $score .= ', ';
  213. }
  214. $i++;
  215. }
  216. } else {
  217. $score = get_lang("Not available");
  218. }
  219. } else {
  220. $score = get_lang("Not available");
  221. }
  222. $table_row = [];
  223. $table_row[] = $row_course['title'];
  224. $table_row[] = $nb_students_in_course;
  225. $table_row[] = $score;
  226. $table_row[] = $attendances[0];
  227. $course_data[] = $table_row;
  228. }
  229. return $course_data;
  230. }
  231. }