block_daily.class.php 9.8 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. * @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. require_once api_get_path(LIBRARY_PATH) . 'thematic.lib.php';
  13. require_once api_get_path(LIBRARY_PATH) . 'attendance.lib.php';
  14. require_once api_get_path(SYS_CODE_PATH) . 'gradebook/lib/be.inc.php';
  15. /**
  16. * This class is used like controller for this course block plugin,
  17. * the class name must be registered inside path.info file (e.g: controller = "BlockDiario"), so dashboard controller will be instantiate it
  18. * @package chamilo.dashboard
  19. */
  20. class BlockDaily extends Block
  21. {
  22. private $user_id;
  23. private $courses;
  24. private $path;
  25. private $permission = array(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. * @param int User id
  42. * @return bool Is block visible for user
  43. */
  44. public function is_block_visible_for_user($user_id)
  45. {
  46. $user_info = api_get_user_info($user_id);
  47. $user_status = $user_info['status'];
  48. $is_block_visible_for_user = false;
  49. if (UserManager::is_admin($user_id) || in_array(
  50. $user_status,
  51. $this->permission
  52. )
  53. ) {
  54. $is_block_visible_for_user = true;
  55. }
  56. return $is_block_visible_for_user;
  57. }
  58. /**
  59. * This method return content html containing information about courses and its position for showing it inside dashboard interface
  60. * it's important to use the name 'get_block' for beeing used from dashboard controller
  61. * @return array column and content html
  62. */
  63. public function get_block()
  64. {
  65. global $charset;
  66. $column = 2;
  67. $data = array();
  68. $content = $this->get_content_html();
  69. $html = '<li class="widget color-green" id="intro">
  70. <div class="widget-head">
  71. <h3>' . get_lang('GradebookAndAttendances') . '</h3>
  72. <div class="widget-actions"><a onclick="javascript:if(!confirm(\'' . addslashes(
  73. api_htmlentities(
  74. get_lang('ConfirmYourChoice'),
  75. ENT_QUOTES,
  76. $charset
  77. )
  78. ) . '\')) return false;" href="index.php?action=disable_block&path=' . $this->path . '">' . Display::return_icon(
  79. 'close.gif',
  80. get_lang('Close')
  81. ) . '</a></div>
  82. </div>
  83. <div class="widget-content">
  84. ' . $content . '
  85. </div>
  86. </li>
  87. ';
  88. $data['column'] = $column;
  89. $data['content_html'] = $html;
  90. return $data;
  91. }
  92. /**
  93. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  94. * @return string content html
  95. */
  96. public function get_content_html()
  97. {
  98. $course_data = $this->get_course_information_data();
  99. $content = '<div style="margin:10px;">';
  100. $content .= '<h3><font color="#000">' . get_lang(
  101. 'YourCourseList'
  102. ) . '</font></h3>';
  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. * @return int
  144. */
  145. function get_number_of_courses()
  146. {
  147. return count($this->courses);
  148. }
  149. /**
  150. * Get course information data
  151. * @return array
  152. */
  153. function get_course_information_data()
  154. {
  155. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  156. $course_data = array();
  157. $courses = $this->courses;
  158. foreach ($courses as $row_course) {
  159. $score = null;
  160. $course_code = $row_course['code'];
  161. $course_info = api_get_course_info($course_code);
  162. if (empty($course_info)) {
  163. continue;
  164. }
  165. // Attendance table
  166. $table_course = Database::get_course_table(TABLE_ATTENDANCE);
  167. $sql = "SELECT id, name, attendance_qualify_max FROM $table_course
  168. WHERE c_id = " . $course_info['real_id'] . " AND active = 1 AND session_id = 0";
  169. $rs = Database::query($sql);
  170. $attendance = array();
  171. $attendances = array();
  172. $param_gradebook = '';
  173. if (isset($_SESSION['gradebook'])) {
  174. $param_gradebook = '&gradebook=' . $_SESSION['gradebook'];
  175. }
  176. while ($row = Database::fetch_array($rs, 'ASSOC')) {
  177. $attendance['done'] = $row['attendance_qualify_max'];
  178. $attendance['id'] = $row['id'];
  179. //$attendance['name'] = $row['name'];
  180. $attendance['course_code'] = $course_code;
  181. if ($attendance['done'] != '0') {
  182. $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>';
  183. } else {
  184. $attendances[] = get_lang("NotAvailable");
  185. }
  186. }
  187. // quantidade de alunos
  188. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user
  189. WHERE course_rel_user.status=" . STUDENT . " AND course_rel_user.course_code='$course_code'";
  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. }