| @@ 67-84 (lines=18) @@ | ||
| 64 | * |
|
| 65 | * @return array |
|
| 66 | */ |
|
| 67 | public function getUserAcceptedLegal($userId, $courseId, $sessionId) |
|
| 68 | { |
|
| 69 | $userId = intval($userId); |
|
| 70 | $courseId = intval($courseId); |
|
| 71 | $sessionId = intval($sessionId); |
|
| 72 | ||
| 73 | $table = Database::get_main_table('session_rel_course_rel_user_legal'); |
|
| 74 | $sql = "SELECT * |
|
| 75 | FROM $table |
|
| 76 | WHERE user_id = $userId AND c_id = $courseId AND session_id = $sessionId"; |
|
| 77 | $result = Database::query($sql); |
|
| 78 | $data = array(); |
|
| 79 | if (Database::num_rows($result) > 0) { |
|
| 80 | $data = Database::fetch_array($result, 'ASSOC'); |
|
| 81 | } |
|
| 82 | ||
| 83 | return $data; |
|
| 84 | } |
|
| 85 | ||
| 86 | /** |
|
| 87 | * @param int $userId |
|
| @@ 1202-1222 (lines=21) @@ | ||
| 1199 | * @param int attendance id |
|
| 1200 | * @return int attendance calendar id |
|
| 1201 | */ |
|
| 1202 | public function get_next_attendance_calendar_id($attendance_id) |
|
| 1203 | { |
|
| 1204 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1205 | $attendance_id = intval($attendance_id); |
|
| 1206 | $course_id = api_get_course_int_id(); |
|
| 1207 | ||
| 1208 | $sql = "SELECT id FROM $tbl_attendance_calendar |
|
| 1209 | WHERE |
|
| 1210 | c_id = $course_id AND |
|
| 1211 | attendance_id = '$attendance_id' AND |
|
| 1212 | done_attendance = 0 |
|
| 1213 | ORDER BY date_time |
|
| 1214 | LIMIT 1"; |
|
| 1215 | $rs = Database::query($sql); |
|
| 1216 | $next_calendar_id = 0; |
|
| 1217 | if (Database::num_rows($rs) > 0) { |
|
| 1218 | $row = Database::fetch_array($rs); |
|
| 1219 | $next_calendar_id = $row['id']; |
|
| 1220 | } |
|
| 1221 | ||
| 1222 | return $next_calendar_id; |
|
| 1223 | } |
|
| 1224 | ||
| 1225 | /** |
|
| @@ 1230-1250 (lines=21) @@ | ||
| 1227 | * @param int attendance id |
|
| 1228 | * @return int UNIX time format datetime |
|
| 1229 | */ |
|
| 1230 | public function get_next_attendance_calendar_datetime($attendance_id) |
|
| 1231 | { |
|
| 1232 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1233 | $course_id = api_get_course_int_id(); |
|
| 1234 | $attendance_id = intval($attendance_id); |
|
| 1235 | $sql = "SELECT id, date_time FROM $tbl_attendance_calendar |
|
| 1236 | WHERE |
|
| 1237 | c_id = $course_id AND |
|
| 1238 | attendance_id = '$attendance_id' AND |
|
| 1239 | done_attendance = 0 |
|
| 1240 | ORDER BY date_time |
|
| 1241 | LIMIT 1"; |
|
| 1242 | $rs = Database::query($sql); |
|
| 1243 | $next_calendar_datetime = 0; |
|
| 1244 | if (Database::num_rows($rs) > 0) { |
|
| 1245 | $row = Database::fetch_array($rs); |
|
| 1246 | $next_calendar_datetime = api_get_local_time($row['date_time']); |
|
| 1247 | } |
|
| 1248 | ||
| 1249 | return $next_calendar_datetime; |
|
| 1250 | } |
|
| 1251 | ||
| 1252 | /** |
|
| 1253 | * Get user' score from current attendance |
|
| @@ 1305-1322 (lines=18) @@ | ||
| 1302 | * @param int attendance calendar id |
|
| 1303 | * @return array attendance calendar data |
|
| 1304 | */ |
|
| 1305 | public function get_attendance_calendar_by_id($calendar_id) |
|
| 1306 | { |
|
| 1307 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1308 | $calendar_id = intval($calendar_id); |
|
| 1309 | $course_id = api_get_course_int_id(); |
|
| 1310 | $sql = "SELECT * FROM $tbl_attendance_calendar |
|
| 1311 | WHERE c_id = $course_id AND id = '$calendar_id' "; |
|
| 1312 | $rs = Database::query($sql); |
|
| 1313 | $data = array(); |
|
| 1314 | if (Database::num_rows($rs) > 0) { |
|
| 1315 | while ($row = Database::fetch_array($rs)) { |
|
| 1316 | $row['date_time'] = api_get_local_time($row['date_time']); |
|
| 1317 | $data = $row; |
|
| 1318 | } |
|
| 1319 | } |
|
| 1320 | ||
| 1321 | return $data; |
|
| 1322 | } |
|
| 1323 | ||
| 1324 | /** |
|
| 1325 | * Get all attendance calendar data inside current attendance |
|
| @@ 1516-1532 (lines=17) @@ | ||
| 1513 | * @param int $attendance_id |
|
| 1514 | * @return int count of dates |
|
| 1515 | */ |
|
| 1516 | public static function get_count_dates_inside_attendance_calendar($attendance_id) |
|
| 1517 | { |
|
| 1518 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1519 | $attendance_id = intval($attendance_id); |
|
| 1520 | $course_id = api_get_course_int_id(); |
|
| 1521 | $sql = "SELECT count(id) FROM $tbl_attendance_calendar |
|
| 1522 | WHERE |
|
| 1523 | c_id = $course_id AND |
|
| 1524 | attendance_id = '$attendance_id'"; |
|
| 1525 | $rs = Database::query($sql); |
|
| 1526 | $count = 0; |
|
| 1527 | if (Database::num_rows($rs) > 0) { |
|
| 1528 | $row = Database::fetch_row($rs); |
|
| 1529 | $count = $row[0]; |
|
| 1530 | } |
|
| 1531 | return $count; |
|
| 1532 | } |
|
| 1533 | ||
| 1534 | /** |
|
| 1535 | * check if all calendar of an attendance is done |
|
| @@ 328-342 (lines=15) @@ | ||
| 325 | * |
|
| 326 | * @return array |
|
| 327 | */ |
|
| 328 | public static function getChildren($categoryCode) |
|
| 329 | { |
|
| 330 | $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY); |
|
| 331 | $categoryCode = Database::escape_string($categoryCode); |
|
| 332 | $sql = "SELECT code, id FROM $tbl_category |
|
| 333 | WHERE parent_id = '$categoryCode'"; |
|
| 334 | $result = Database::query($sql); |
|
| 335 | $children = []; |
|
| 336 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
| 337 | $children[] = $row; |
|
| 338 | $subChildren = self::getChildren($row['code']); |
|
| 339 | $children = array_merge($children, $subChildren); |
|
| 340 | } |
|
| 341 | ||
| 342 | return $children; |
|
| 343 | } |
|
| 344 | ||
| 345 | /** |
|
| @@ 2643-2664 (lines=22) @@ | ||
| 2640 | * @param array $courseInfo |
|
| 2641 | * @return array with the post info |
|
| 2642 | */ |
|
| 2643 | public function getAttachment($attachmentId, $eventId, $courseInfo) |
|
| 2644 | { |
|
| 2645 | $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 2646 | $courseId = intval($courseInfo['real_id']); |
|
| 2647 | $eventId = intval($eventId); |
|
| 2648 | $attachmentId = intval($attachmentId); |
|
| 2649 | ||
| 2650 | $row = array(); |
|
| 2651 | $sql = "SELECT id, path, filename, comment |
|
| 2652 | FROM $tableAttachment |
|
| 2653 | WHERE |
|
| 2654 | c_id = $courseId AND |
|
| 2655 | agenda_id = $eventId AND |
|
| 2656 | id = $attachmentId |
|
| 2657 | "; |
|
| 2658 | $result = Database::query($sql); |
|
| 2659 | if (Database::num_rows($result) != 0) { |
|
| 2660 | $row = Database::fetch_array($result, 'ASSOC'); |
|
| 2661 | } |
|
| 2662 | ||
| 2663 | return $row; |
|
| 2664 | } |
|
| 2665 | ||
| 2666 | /** |
|
| 2667 | * Add an attachment file into agenda |
|
| @@ 2616-2634 (lines=19) @@ | ||
| 2613 | * @param array $courseInfo |
|
| 2614 | * @return array with the post info |
|
| 2615 | */ |
|
| 2616 | public function getAttachmentList($eventId, $courseInfo) |
|
| 2617 | { |
|
| 2618 | $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 2619 | $courseId = intval($courseInfo['real_id']); |
|
| 2620 | $eventId = intval($eventId); |
|
| 2621 | ||
| 2622 | $sql = "SELECT id, path, filename, comment |
|
| 2623 | FROM $tableAttachment |
|
| 2624 | WHERE |
|
| 2625 | c_id = $courseId AND |
|
| 2626 | agenda_id = $eventId"; |
|
| 2627 | $result = Database::query($sql); |
|
| 2628 | $list = array(); |
|
| 2629 | if (Database::num_rows($result) != 0) { |
|
| 2630 | $list = Database::store_result($result, 'ASSOC'); |
|
| 2631 | } |
|
| 2632 | ||
| 2633 | return $list; |
|
| 2634 | } |
|
| 2635 | ||
| 2636 | /** |
|
| 2637 | * Show a list with all the attachments according to the post's id |
|
| @@ 5194-5215 (lines=22) @@ | ||
| 5191 | * @param int $courseId |
|
| 5192 | * @return array |
|
| 5193 | */ |
|
| 5194 | public static function getCoachesByCourseSession($sessionId, $courseId) |
|
| 5195 | { |
|
| 5196 | $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
|
| 5197 | $sessionId = intval($sessionId); |
|
| 5198 | $courseId = intval($courseId); |
|
| 5199 | ||
| 5200 | $sql = "SELECT user_id FROM $table |
|
| 5201 | WHERE |
|
| 5202 | session_id = '$sessionId' AND |
|
| 5203 | c_id = '$courseId' AND |
|
| 5204 | status = 2"; |
|
| 5205 | $result = Database::query($sql); |
|
| 5206 | ||
| 5207 | $coaches = array(); |
|
| 5208 | if (Database::num_rows($result) > 0) { |
|
| 5209 | while ($row = Database::fetch_array($result)) { |
|
| 5210 | $coaches[] = $row['user_id']; |
|
| 5211 | } |
|
| 5212 | } |
|
| 5213 | ||
| 5214 | return $coaches; |
|
| 5215 | } |
|
| 5216 | ||
| 5217 | /** |
|
| 5218 | * @param int $sessionId |
|
| @@ 2837-2852 (lines=16) @@ | ||
| 2834 | * @param integer course id |
|
| 2835 | * @return integer Number of interactions |
|
| 2836 | */ |
|
| 2837 | public static function get_interactions_count_from_db($lp_iv_id, $course_id) |
|
| 2838 | { |
|
| 2839 | $table = Database::get_course_table(TABLE_LP_IV_INTERACTION); |
|
| 2840 | $lp_iv_id = intval($lp_iv_id); |
|
| 2841 | $course_id = intval($course_id); |
|
| 2842 | ||
| 2843 | $sql = "SELECT count(*) FROM $table |
|
| 2844 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
|
| 2845 | $res = Database::query($sql); |
|
| 2846 | $num = 0; |
|
| 2847 | if (Database::num_rows($res)) { |
|
| 2848 | $row = Database::fetch_array($res); |
|
| 2849 | $num = $row[0]; |
|
| 2850 | } |
|
| 2851 | return $num; |
|
| 2852 | } |
|
| 2853 | ||
| 2854 | /** |
|
| 2855 | * Return the interactions as an array for the given lp_iv_id. |
|
| @@ 2911-2927 (lines=17) @@ | ||
| 2908 | * @param integer Item View ID |
|
| 2909 | * @return integer Number of objectives |
|
| 2910 | */ |
|
| 2911 | public static function get_objectives_count_from_db($lp_iv_id, $course_id) |
|
| 2912 | { |
|
| 2913 | $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE); |
|
| 2914 | $course_id = intval($course_id); |
|
| 2915 | $lp_iv_id = intval($lp_iv_id); |
|
| 2916 | $sql = "SELECT count(*) FROM $table |
|
| 2917 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
|
| 2918 | //@todo seems that this always returns 0 |
|
| 2919 | $res = Database::query($sql); |
|
| 2920 | $num = 0; |
|
| 2921 | if (Database::num_rows($res)) { |
|
| 2922 | $row = Database::fetch_array($res); |
|
| 2923 | $num = $row[0]; |
|
| 2924 | } |
|
| 2925 | ||
| 2926 | return $num; |
|
| 2927 | } |
|
| 2928 | ||
| 2929 | /** |
|
| 2930 | * Return the objectives as an array for the given lp_iv_id. |
|