block_daily.class.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 $path;
  26. private $permission = [DRH];
  27. /**
  28. * Constructor.
  29. */
  30. public function __construct($user_id)
  31. {
  32. $this->user_id = $user_id;
  33. $this->path = 'block_daily';
  34. if ($this->is_block_visible_for_user($user_id)) {
  35. $this->courses = CourseManager::get_courses_followed_by_drh(
  36. $user_id
  37. );
  38. }
  39. }
  40. /**
  41. * This method check if a user is allowed to see the block inside dashboard interface.
  42. *
  43. * @param int User id
  44. *
  45. * @return bool Is block visible for user
  46. */
  47. public function is_block_visible_for_user($user_id)
  48. {
  49. $user_info = api_get_user_info($user_id);
  50. $user_status = $user_info['status'];
  51. $is_block_visible_for_user = false;
  52. if (UserManager::is_admin($user_id) || in_array(
  53. $user_status,
  54. $this->permission
  55. )
  56. ) {
  57. $is_block_visible_for_user = true;
  58. }
  59. return $is_block_visible_for_user;
  60. }
  61. /**
  62. * This method return content html containing information about courses and its position for showing it inside dashboard interface
  63. * it's important to use the name 'get_block' for beeing used from dashboard controller.
  64. *
  65. * @return array column and content html
  66. */
  67. public function get_block()
  68. {
  69. global $charset;
  70. $column = 2;
  71. $data = [];
  72. $content = $this->get_content_html();
  73. $html = '<div class="panel panel-default" id="intro">
  74. <div class="panel-heading">'.get_lang('GradebookAndAttendances').'
  75. <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\''.addslashes(
  76. api_htmlentities(
  77. get_lang('ConfirmYourChoice'),
  78. ENT_QUOTES,
  79. $charset
  80. )
  81. ).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">
  82. <em class="fa fa-times"></em>
  83. </a></div>
  84. </div>
  85. <div class="panel-body">
  86. '.$content.'
  87. </div>
  88. </div>
  89. ';
  90. $data['column'] = $column;
  91. $data['content_html'] = $html;
  92. return $data;
  93. }
  94. /**
  95. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface.
  96. *
  97. * @return string content html
  98. */
  99. public function get_content_html()
  100. {
  101. $course_data = $this->get_course_information_data();
  102. $content = '<h4>'.get_lang('YourCourseList').'</h4>';
  103. $data_table = null;
  104. if (!empty($course_data)) {
  105. $data_table .= '<table class="data_table" width:"95%">';
  106. $data_table .= '<tr>
  107. <th>'.get_lang('CourseTitle').'</th>
  108. <th width="20%">'.get_lang('NbStudents').'</th>
  109. <th width="20%">'.get_lang('Evaluation').'</th>
  110. <th width="20%">'.get_lang('ToolAttendance').'</th>
  111. </tr>';
  112. $i = 1;
  113. foreach ($course_data as $course) {
  114. if ($i % 2 == 0) {
  115. $class_tr = 'row_odd';
  116. } else {
  117. $class_tr = 'row_even';
  118. }
  119. $data_table .= '<tr class="'.$class_tr.'">';
  120. if (!isset($course[3])) {
  121. $course[3] = get_lang('NotAvailable');
  122. }
  123. foreach ($course as $cell) {
  124. $data_table .= '<td align="right">'.$cell.'</td>';
  125. }
  126. $data_table .= '</tr>';
  127. $i++;
  128. }
  129. $data_table .= '</table>';
  130. } else {
  131. $data_table .= get_lang('ThereIsNoInformationAboutYourCourses');
  132. }
  133. $content .= $data_table;
  134. if (!empty($course_data)) {
  135. $content .= '<div style="text-align:right;margin-top:10px;">
  136. <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('SeeMore').'</a></div>';
  137. }
  138. //$content .= '</div>';
  139. return $content;
  140. }
  141. /**
  142. * Get number of courses.
  143. *
  144. * @return int
  145. */
  146. public function get_number_of_courses()
  147. {
  148. return count($this->courses);
  149. }
  150. /**
  151. * Get course information data.
  152. *
  153. * @return array
  154. */
  155. public function get_course_information_data()
  156. {
  157. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  158. $course_data = [];
  159. $courses = $this->courses;
  160. foreach ($courses as $row_course) {
  161. $score = null;
  162. $courseId = $row_course['c_id'];
  163. $course_info = api_get_course_info_by_id($courseId);
  164. $course_code = $course_info['code'];
  165. if (empty($course_info)) {
  166. continue;
  167. }
  168. // Attendance table
  169. $table_course = Database::get_course_table(TABLE_ATTENDANCE);
  170. $sql = "SELECT id, name, attendance_qualify_max FROM $table_course
  171. WHERE c_id = ".$course_info['real_id']." AND active = 1 AND session_id = 0";
  172. $rs = Database::query($sql);
  173. $attendance = [];
  174. $attendances = [];
  175. while ($row = Database::fetch_array($rs, 'ASSOC')) {
  176. $attendance['done'] = $row['attendance_qualify_max'];
  177. $attendance['id'] = $row['id'];
  178. //$attendance['name'] = $row['name'];
  179. $attendance['course_code'] = $course_info['code'];
  180. if ($attendance['done'] != '0') {
  181. $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>';
  182. } else {
  183. $attendances[] = get_lang("NotAvailable");
  184. }
  185. }
  186. if (count($attendances) == 0) {
  187. $attendances[] = get_lang("NotAvailable");
  188. }
  189. // Number of students
  190. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user
  191. WHERE course_rel_user.status=".STUDENT." AND course_rel_user.c_id=$courseId";
  192. $rs = Database::query($sql);
  193. $users = [];
  194. while ($row = Database::fetch_array($rs)) {
  195. $users[] = $row['user_id'];
  196. }
  197. if (count($users) > 0) {
  198. $nb_students_in_course = count($users);
  199. }
  200. if (!empty($tematic_advance)) {
  201. $tematic_advance_progress = '<a title="'.get_lang(
  202. 'GoToThematicAdvance'
  203. ).'" href="'.api_get_path(
  204. WEB_CODE_PATH
  205. ).'attendance/index.php?cidReq='.$course_code.'&action=attendance_sheet_print&attendance_id=">'.$tematic_advance.'%</a>';
  206. } else {
  207. $tematic_advance_progress = '0%';
  208. }
  209. // Score
  210. $tbl_grade_categories = Database::get_main_table(
  211. TABLE_MAIN_GRADEBOOK_CATEGORY
  212. );
  213. $sql = "SELECT id from ".$tbl_grade_categories."
  214. WHERE course_code ='".$course_code."'";
  215. $rs = Database::query($sql);
  216. $category = null;
  217. while ($row = Database::fetch_array($rs)) {
  218. $category = $row['id'];
  219. }
  220. if (!empty($category)) {
  221. $cat = Category::load($category);
  222. $eval = $cat[0]->get_evaluations();
  223. if (count($eval) > 0) {
  224. $i = 0;
  225. foreach ($eval as $item) {
  226. $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>';
  227. if (count($eval) - 1 != $i) {
  228. $score .= ', ';
  229. }
  230. $i++;
  231. }
  232. } else {
  233. $score = get_lang("NotAvailable");
  234. }
  235. } else {
  236. $score = get_lang("NotAvailable");
  237. }
  238. $table_row = [];
  239. $table_row[] = $row_course['title'];
  240. $table_row[] = $nb_students_in_course;
  241. $table_row[] = $score;
  242. $table_row[] = $attendances[0];
  243. $course_data[] = $table_row;
  244. }
  245. return $course_data;
  246. }
  247. }