block_daily.class.php 9.7 KB

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