block_daily.class.php 8.9 KB

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