block_daily.class.php 8.6 KB

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