block_daily.class.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 = '
  69. <li class="widget color-green" id="intro">
  70. <div class="widget-head">
  71. <h3>'.get_lang('DailyElectronic').'</h3>
  72. <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>
  73. </div>
  74. <div class="widget-content">
  75. '.$content.'
  76. </div>
  77. </li>
  78. ';
  79. $data['column'] = $column;
  80. $data['content_html'] = $html;
  81. return $data;
  82. }
  83. /**
  84. * This method return a content html, it's used inside get_block method for showing it inside dashboard interface
  85. * @return string content html
  86. */
  87. public function get_content_html() {
  88. $course_data = $this->get_course_information_data();
  89. $content = '<div style="margin:10px;">';
  90. $content .= '<h3><font color="#000">'.get_lang('YourCourseList').'</font></h3>';
  91. if (!empty($course_data)) {
  92. $data_table = '<table class="data_table" width:"95%">';
  93. $data_table .= '<tr>
  94. <th>'.get_lang('CourseTitle').'</th>
  95. <th width="20%">'.get_lang('NbStudents').'</th>
  96. <th width="20%">'.get_lang('Evaluation').'</th>
  97. <th width="20%">'.get_lang('ToolAttendance').'</th>
  98. </tr>';
  99. $i = 1;
  100. foreach ($course_data as $course) {
  101. if ($i%2 == 0) {
  102. $class_tr = 'row_odd';
  103. } else {
  104. $class_tr = 'row_even';
  105. }
  106. $data_table .= '<tr class="'.$class_tr.'">';
  107. if (!isset($course[3])) {
  108. $course[3] = get_lang('NotAvailable');
  109. }
  110. foreach ($course as $cell) {
  111. $data_table .= '<td align="right">'.$cell.'</td>';
  112. }
  113. $data_table .= '</tr>';
  114. $i++;
  115. }
  116. $data_table .= '</table>';
  117. } else {
  118. $data_table .= get_lang('ThereIsNoInformationAboutYourCourses');
  119. }
  120. $content .= $data_table;
  121. if (!empty($course_data)) {
  122. $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>';
  123. }
  124. $content .= '</div>';
  125. return $content;
  126. }
  127. /**
  128. * Get number of courses
  129. * @return int
  130. */
  131. function get_number_of_courses() {
  132. return count($this->courses);
  133. }
  134. /**
  135. * Get course information data
  136. * @return array
  137. */
  138. function get_course_information_data() {
  139. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  140. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  141. $a_course_students = array();
  142. $course_data = array();
  143. $courses = $this->courses;
  144. foreach ($courses as $row_course) {
  145. $score = null;
  146. $course_code = $row_course['code'];
  147. $course_info = api_get_course_info($course_code);
  148. if (empty($course_info)) {
  149. continue;
  150. }
  151. // Attendance table
  152. $table_course = Database::get_course_table(TABLE_ATTENDANCE, $course_info['db_name']);
  153. $sql = "SELECT id, name, attendance_qualify_max FROM $table_course WHERE active = 1 AND session_id = 0";
  154. $rs = Database::query($sql);
  155. $attendance = array();
  156. $attendances = array();
  157. $param_gradebook = '';
  158. if (isset($_SESSION['gradebook'])) {
  159. $param_gradebook = '&gradebook='.$_SESSION['gradebook'];
  160. }
  161. while ($row = Database::fetch_array($rs,'ASSOC')) {
  162. $attendance['done'] = $row['attendance_qualify_max'];
  163. $attendance['id'] = $row['id'];
  164. //$attendance['name'] = $row['name'];
  165. $attendance['course_code'] = $course_code;
  166. if ($attendance['done'] != '0')
  167. $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>';
  168. else
  169. $attendances[] = get_lang("NotAvailable");
  170. }
  171. // quantidade de alunos
  172. $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'";
  173. $rs = Database::query($sql);
  174. $users = array();
  175. while ($row = Database::fetch_array($rs)) {
  176. $users[] = $row['user_id'];
  177. }
  178. if (count($users) > 0) {
  179. $nb_students_in_course = count($users);
  180. }
  181. if (!empty($tematic_advance)) {
  182. $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>';
  183. } else {
  184. $tematic_advance_progress = '0%';
  185. }
  186. // Score
  187. $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
  188. $sql = "SELECT id from " . $tbl_grade_categories ." WHERE course_code ='".$course_code."'";
  189. $rs = Database::query($sql);
  190. $category = null;
  191. while ($row = Database::fetch_array($rs)) {
  192. $category = $row['id'];
  193. }
  194. if (!empty($category)) {
  195. $cat = Category::load($category);
  196. $eval = $cat[0]->get_evaluations();
  197. if (count($eval) > 0){
  198. $i = 0;
  199. foreach ($eval as $item) {
  200. $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>';
  201. if (count($eval)-1 != $i) {
  202. $score .= ', ';
  203. }
  204. $i++;
  205. }
  206. } else {
  207. $score = get_lang("NotAvailable");
  208. }
  209. } else {
  210. $score = get_lang("NotAvailable");
  211. }
  212. $table_row = array();
  213. $table_row[] = $row_course['title'];
  214. $table_row[] = $nb_students_in_course;
  215. $table_row[] = $score;
  216. $table_row[] = $attendances[0];
  217. $course_data[] = $table_row;
  218. }
  219. return $course_data;
  220. }
  221. }