block_daily.class.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 = '<h4>'.get_lang('YourCourseList').'</h4>';
  96. $data_table = null;
  97. if (!empty($course_data)) {
  98. $data_table .= '<table class="data_table" width:"95%">';
  99. $data_table .= '<tr>
  100. <th>' . get_lang('CourseTitle').'</th>
  101. <th width="20%">' . get_lang('NbStudents').'</th>
  102. <th width="20%">' . get_lang('Evaluation').'</th>
  103. <th width="20%">' . get_lang('ToolAttendance').'</th>
  104. </tr>';
  105. $i = 1;
  106. foreach ($course_data as $course) {
  107. if ($i % 2 == 0) {
  108. $class_tr = 'row_odd';
  109. } else {
  110. $class_tr = 'row_even';
  111. }
  112. $data_table .= '<tr class="'.$class_tr.'">';
  113. if (!isset($course[3])) {
  114. $course[3] = get_lang('NotAvailable');
  115. }
  116. foreach ($course as $cell) {
  117. $data_table .= '<td align="right">'.$cell.'</td>';
  118. }
  119. $data_table .= '</tr>';
  120. $i++;
  121. }
  122. $data_table .= '</table>';
  123. } else {
  124. $data_table .= get_lang('ThereIsNoInformationAboutYourCourses');
  125. }
  126. $content .= $data_table;
  127. if (!empty($course_data)) {
  128. $content .= '<div style="text-align:right;margin-top:10px;">
  129. <a href="' . api_get_path(WEB_CODE_PATH).'mySpace/course.php">'.get_lang('SeeMore').'</a></div>';
  130. }
  131. //$content .= '</div>';
  132. return $content;
  133. }
  134. /**
  135. * Get number of courses
  136. * @return int
  137. */
  138. function get_number_of_courses()
  139. {
  140. return count($this->courses);
  141. }
  142. /**
  143. * Get course information data
  144. * @return array
  145. */
  146. function get_course_information_data()
  147. {
  148. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  149. $course_data = array();
  150. $courses = $this->courses;
  151. foreach ($courses as $row_course) {
  152. $score = null;
  153. $courseId = $row_course['c_id'];
  154. $course_info = api_get_course_info_by_id($courseId);
  155. $course_code = $course_info['code'];
  156. if (empty($course_info)) {
  157. continue;
  158. }
  159. // Attendance table
  160. $table_course = Database::get_course_table(TABLE_ATTENDANCE);
  161. $sql = "SELECT id, name, attendance_qualify_max FROM $table_course
  162. WHERE c_id = ".$course_info['real_id']." AND active = 1 AND session_id = 0";
  163. $rs = Database::query($sql);
  164. $attendance = array();
  165. $attendances = array();
  166. while ($row = Database::fetch_array($rs, 'ASSOC')) {
  167. $attendance['done'] = $row['attendance_qualify_max'];
  168. $attendance['id'] = $row['id'];
  169. //$attendance['name'] = $row['name'];
  170. $attendance['course_code'] = $course_info['code'];
  171. if ($attendance['done'] != '0') {
  172. $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>';
  173. } else {
  174. $attendances[] = get_lang("NotAvailable");
  175. }
  176. }
  177. if (count($attendances) == 0) {
  178. $attendances[] = get_lang("NotAvailable");
  179. }
  180. // Number of students
  181. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user
  182. WHERE course_rel_user.status=".STUDENT." AND course_rel_user.c_id=$courseId";
  183. $rs = Database::query($sql);
  184. $users = array();
  185. while ($row = Database::fetch_array($rs)) {
  186. $users[] = $row['user_id'];
  187. }
  188. if (count($users) > 0) {
  189. $nb_students_in_course = count($users);
  190. }
  191. if (!empty($tematic_advance)) {
  192. $tematic_advance_progress = '<a title="'.get_lang(
  193. 'GoToThematicAdvance'
  194. ).'" href="'.api_get_path(
  195. WEB_CODE_PATH
  196. ).'attendance/index.php?cidReq='.$course_code.'&action=attendance_sheet_print&attendance_id=">'.$tematic_advance.'%</a>';
  197. } else {
  198. $tematic_advance_progress = '0%';
  199. }
  200. // Score
  201. $tbl_grade_categories = Database::get_main_table(
  202. TABLE_MAIN_GRADEBOOK_CATEGORY
  203. );
  204. $sql = "SELECT id from ".$tbl_grade_categories."
  205. WHERE course_code ='" . $course_code."'";
  206. $rs = Database::query($sql);
  207. $category = null;
  208. while ($row = Database::fetch_array($rs)) {
  209. $category = $row['id'];
  210. }
  211. if (!empty($category)) {
  212. $cat = Category::load($category);
  213. $eval = $cat[0]->get_evaluations();
  214. if (count($eval) > 0) {
  215. $i = 0;
  216. foreach ($eval as $item) {
  217. $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>';
  218. if (count($eval) - 1 != $i) {
  219. $score .= ', ';
  220. }
  221. $i++;
  222. }
  223. } else {
  224. $score = get_lang("NotAvailable");
  225. }
  226. } else {
  227. $score = get_lang("NotAvailable");
  228. }
  229. $table_row = array();
  230. $table_row[] = $row_course['title'];
  231. $table_row[] = $nb_students_in_course;
  232. $table_row[] = $score;
  233. $table_row[] = $attendances[0];
  234. $course_data[] = $table_row;
  235. }
  236. return $course_data;
  237. }
  238. }