block_daily.class.php 8.5 KB

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