block_daily.class.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. <em class="fa fa-times"></em>
  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. while ($row = Database::fetch_array($rs, 'ASSOC')) {
  170. $attendance['done'] = $row['attendance_qualify_max'];
  171. $attendance['id'] = $row['id'];
  172. //$attendance['name'] = $row['name'];
  173. $attendance['course_code'] = $course_info['code'];
  174. if ($attendance['done'] != '0') {
  175. $attendances[] = '<a href="' . api_get_path(WEB_PATH).'main/attendance/index.php?' . api_get_cidreq(). '&action=attendance_sheet_print&attendance_id=' . $attendance['id'].'">' .
  176. Display::return_icon('printmgr.gif', get_lang('Print')).'</a>';
  177. } else {
  178. $attendances[] = get_lang("NotAvailable");
  179. }
  180. }
  181. if (count($attendances) == 0) {
  182. $attendances[] = get_lang("NotAvailable");
  183. }
  184. // Number of students
  185. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user
  186. WHERE course_rel_user.status=" . STUDENT . " AND course_rel_user.c_id=$courseId";
  187. $rs = Database::query($sql);
  188. $users = array();
  189. while ($row = Database::fetch_array($rs)) {
  190. $users[] = $row['user_id'];
  191. }
  192. if (count($users) > 0) {
  193. $nb_students_in_course = count($users);
  194. }
  195. if (!empty($tematic_advance)) {
  196. $tematic_advance_progress = '<a title="' . get_lang(
  197. 'GoToThematicAdvance'
  198. ) . '" href="' . api_get_path(
  199. WEB_CODE_PATH
  200. ) . 'attendance/index.php?cidReq=' . $course_code . '&action=attendance_sheet_print&attendance_id=">' . $tematic_advance . '%</a>';
  201. } else {
  202. $tematic_advance_progress = '0%';
  203. }
  204. // Score
  205. $tbl_grade_categories = Database :: get_main_table(
  206. TABLE_MAIN_GRADEBOOK_CATEGORY
  207. );
  208. $sql = "SELECT id from " . $tbl_grade_categories . "
  209. WHERE course_code ='" . $course_code . "'";
  210. $rs = Database::query($sql);
  211. $category = null;
  212. while ($row = Database::fetch_array($rs)) {
  213. $category = $row['id'];
  214. }
  215. if (!empty($category)) {
  216. $cat = Category::load($category);
  217. $eval = $cat[0]->get_evaluations();
  218. if (count($eval) > 0) {
  219. $i = 0;
  220. foreach ($eval as $item) {
  221. $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(). '&'.api_get_cidreq().'">' .
  222. $item->get_name() . '</a>';
  223. if (count($eval) - 1 != $i) {
  224. $score .= ', ';
  225. }
  226. $i++;
  227. }
  228. } else {
  229. $score = get_lang("NotAvailable");
  230. }
  231. } else {
  232. $score = get_lang("NotAvailable");
  233. }
  234. $table_row = array();
  235. $table_row[] = $row_course['title'];
  236. $table_row[] = $nb_students_in_course;
  237. $table_row[] = $score;
  238. $table_row[] = $attendances[0];
  239. $course_data[] = $table_row;
  240. }
  241. return $course_data;
  242. }
  243. }