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