| @@ 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 |
|
| @@ 1501-1528 (lines=28) @@ | ||
| 1498 | * |
|
| 1499 | * @return array |
|
| 1500 | */ |
|
| 1501 | public static function getLatestHotPotatoResult( |
|
| 1502 | $exercisePath, |
|
| 1503 | $userId, |
|
| 1504 | $courseId, |
|
| 1505 | $sessionId |
|
| 1506 | ) |
|
| 1507 | { |
|
| 1508 | $table = Database:: get_main_table( |
|
| 1509 | TABLE_STATISTIC_TRACK_E_HOTPOTATOES |
|
| 1510 | ); |
|
| 1511 | ||
| 1512 | $courseInfo = api_get_course_info_by_id($courseId); |
|
| 1513 | $exercisePath = Database::escape_string($exercisePath); |
|
| 1514 | $userId = intval($userId); |
|
| 1515 | ||
| 1516 | $sql = "SELECT * FROM $table |
|
| 1517 | WHERE |
|
| 1518 | c_id = $courseId AND |
|
| 1519 | exe_name LIKE '$exercisePath%' AND |
|
| 1520 | exe_user_id = $userId |
|
| 1521 | ORDER BY id |
|
| 1522 | LIMIT 1"; |
|
| 1523 | $result = Database::query($sql); |
|
| 1524 | $attempt = array(); |
|
| 1525 | if (Database::num_rows($result)) { |
|
| 1526 | $attempt = Database::fetch_array($result, 'ASSOC'); |
|
| 1527 | } |
|
| 1528 | return $attempt; |
|
| 1529 | } |
|
| 1530 | ||
| 1531 | /** |
|
| @@ 236-254 (lines=19) @@ | ||
| 233 | * |
|
| 234 | * @return int |
|
| 235 | */ |
|
| 236 | public static function getCategoryForQuestion($questionId, $courseId = 0) |
|
| 237 | { |
|
| 238 | if (empty($courseId)) { |
|
| 239 | $courseId = api_get_course_int_id(); |
|
| 240 | } |
|
| 241 | $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
| 242 | $questionId = intval($questionId); |
|
| 243 | $sql = "SELECT category_id |
|
| 244 | FROM $table |
|
| 245 | WHERE question_id = $questionId AND c_id = $courseId"; |
|
| 246 | $res = Database::query($sql); |
|
| 247 | $result = 0; |
|
| 248 | if (Database::num_rows($res) > 0) { |
|
| 249 | $data = Database::fetch_array($res); |
|
| 250 | $result = $data['category_id']; |
|
| 251 | } |
|
| 252 | ||
| 253 | return $result; |
|
| 254 | } |
|
| 255 | ||
| 256 | /** |
|
| 257 | * true if question id has a category |
|
| @@ 1203-1223 (lines=21) @@ | ||
| 1200 | * @param int attendance id |
|
| 1201 | * @return int attendance calendar id |
|
| 1202 | */ |
|
| 1203 | public function get_next_attendance_calendar_id($attendance_id) |
|
| 1204 | { |
|
| 1205 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1206 | $attendance_id = intval($attendance_id); |
|
| 1207 | $course_id = api_get_course_int_id(); |
|
| 1208 | ||
| 1209 | $sql = "SELECT id FROM $tbl_attendance_calendar |
|
| 1210 | WHERE |
|
| 1211 | c_id = $course_id AND |
|
| 1212 | attendance_id = '$attendance_id' AND |
|
| 1213 | done_attendance = 0 |
|
| 1214 | ORDER BY date_time |
|
| 1215 | LIMIT 1"; |
|
| 1216 | $rs = Database::query($sql); |
|
| 1217 | $next_calendar_id = 0; |
|
| 1218 | if (Database::num_rows($rs) > 0) { |
|
| 1219 | $row = Database::fetch_array($rs); |
|
| 1220 | $next_calendar_id = $row['id']; |
|
| 1221 | } |
|
| 1222 | ||
| 1223 | return $next_calendar_id; |
|
| 1224 | } |
|
| 1225 | ||
| 1226 | /** |
|
| @@ 1231-1251 (lines=21) @@ | ||
| 1228 | * @param int attendance id |
|
| 1229 | * @return int UNIX time format datetime |
|
| 1230 | */ |
|
| 1231 | public function get_next_attendance_calendar_datetime($attendance_id) |
|
| 1232 | { |
|
| 1233 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1234 | $course_id = api_get_course_int_id(); |
|
| 1235 | $attendance_id = intval($attendance_id); |
|
| 1236 | $sql = "SELECT id, date_time FROM $tbl_attendance_calendar |
|
| 1237 | WHERE |
|
| 1238 | c_id = $course_id AND |
|
| 1239 | attendance_id = '$attendance_id' AND |
|
| 1240 | done_attendance = 0 |
|
| 1241 | ORDER BY date_time |
|
| 1242 | LIMIT 1"; |
|
| 1243 | $rs = Database::query($sql); |
|
| 1244 | $next_calendar_datetime = 0; |
|
| 1245 | if (Database::num_rows($rs) > 0) { |
|
| 1246 | $row = Database::fetch_array($rs); |
|
| 1247 | $next_calendar_datetime = api_get_local_time($row['date_time']); |
|
| 1248 | } |
|
| 1249 | ||
| 1250 | return $next_calendar_datetime; |
|
| 1251 | } |
|
| 1252 | ||
| 1253 | /** |
|
| 1254 | * Get user' score from current attendance |
|
| @@ 1306-1323 (lines=18) @@ | ||
| 1303 | * @param int attendance calendar id |
|
| 1304 | * @return array attendance calendar data |
|
| 1305 | */ |
|
| 1306 | public function get_attendance_calendar_by_id($calendar_id) |
|
| 1307 | { |
|
| 1308 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1309 | $calendar_id = intval($calendar_id); |
|
| 1310 | $course_id = api_get_course_int_id(); |
|
| 1311 | $sql = "SELECT * FROM $tbl_attendance_calendar |
|
| 1312 | WHERE c_id = $course_id AND id = '$calendar_id' "; |
|
| 1313 | $rs = Database::query($sql); |
|
| 1314 | $data = array(); |
|
| 1315 | if (Database::num_rows($rs) > 0) { |
|
| 1316 | while ($row = Database::fetch_array($rs)) { |
|
| 1317 | $row['date_time'] = api_get_local_time($row['date_time']); |
|
| 1318 | $data = $row; |
|
| 1319 | } |
|
| 1320 | } |
|
| 1321 | ||
| 1322 | return $data; |
|
| 1323 | } |
|
| 1324 | ||
| 1325 | /** |
|
| 1326 | * Get all attendance calendar data inside current attendance |
|
| @@ 1517-1533 (lines=17) @@ | ||
| 1514 | * @param int $attendance_id |
|
| 1515 | * @return int count of dates |
|
| 1516 | */ |
|
| 1517 | public static function get_count_dates_inside_attendance_calendar($attendance_id) |
|
| 1518 | { |
|
| 1519 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1520 | $attendance_id = intval($attendance_id); |
|
| 1521 | $course_id = api_get_course_int_id(); |
|
| 1522 | $sql = "SELECT count(id) FROM $tbl_attendance_calendar |
|
| 1523 | WHERE |
|
| 1524 | c_id = $course_id AND |
|
| 1525 | attendance_id = '$attendance_id'"; |
|
| 1526 | $rs = Database::query($sql); |
|
| 1527 | $count = 0; |
|
| 1528 | if (Database::num_rows($rs) > 0) { |
|
| 1529 | $row = Database::fetch_row($rs); |
|
| 1530 | $count = $row[0]; |
|
| 1531 | } |
|
| 1532 | return $count; |
|
| 1533 | } |
|
| 1534 | ||
| 1535 | /** |
|
| 1536 | * check if all calendar of an attendance is done |
|
| @@ 331-345 (lines=15) @@ | ||
| 328 | * |
|
| 329 | * @return array |
|
| 330 | */ |
|
| 331 | public static function getChildren($categoryCode) |
|
| 332 | { |
|
| 333 | $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY); |
|
| 334 | $categoryCode = Database::escape_string($categoryCode); |
|
| 335 | $sql = "SELECT code, id FROM $tbl_category |
|
| 336 | WHERE parent_id = '$categoryCode'"; |
|
| 337 | $result = Database::query($sql); |
|
| 338 | $children = array(); |
|
| 339 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
| 340 | $children[] = $row; |
|
| 341 | $subChildren = self::getChildren($row['code']); |
|
| 342 | $children = array_merge($children, $subChildren); |
|
| 343 | } |
|
| 344 | ||
| 345 | return $children; |
|
| 346 | } |
|
| 347 | ||
| 348 | /** |
|
| @@ 2838-2853 (lines=16) @@ | ||
| 2835 | * @param integer course id |
|
| 2836 | * @return integer Number of interactions |
|
| 2837 | */ |
|
| 2838 | public static function get_interactions_count_from_db($lp_iv_id, $course_id) |
|
| 2839 | { |
|
| 2840 | $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION); |
|
| 2841 | $lp_iv_id = intval($lp_iv_id); |
|
| 2842 | $course_id = intval($course_id); |
|
| 2843 | ||
| 2844 | $sql = "SELECT count(*) FROM $table |
|
| 2845 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
|
| 2846 | $res = Database::query($sql); |
|
| 2847 | $num = 0; |
|
| 2848 | if (Database::num_rows($res)) { |
|
| 2849 | $row = Database::fetch_array($res); |
|
| 2850 | $num = $row[0]; |
|
| 2851 | } |
|
| 2852 | return $num; |
|
| 2853 | } |
|
| 2854 | ||
| 2855 | /** |
|
| 2856 | * Return the interactions as an array for the given lp_iv_id. |
|
| @@ 2912-2928 (lines=17) @@ | ||
| 2909 | * @param integer Item View ID |
|
| 2910 | * @return integer Number of objectives |
|
| 2911 | */ |
|
| 2912 | public static function get_objectives_count_from_db($lp_iv_id, $course_id) |
|
| 2913 | { |
|
| 2914 | $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE); |
|
| 2915 | $course_id = intval($course_id); |
|
| 2916 | $lp_iv_id = intval($lp_iv_id); |
|
| 2917 | $sql = "SELECT count(*) FROM $table |
|
| 2918 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
|
| 2919 | //@todo seems that this always returns 0 |
|
| 2920 | $res = Database::query($sql); |
|
| 2921 | $num = 0; |
|
| 2922 | if (Database::num_rows($res)) { |
|
| 2923 | $row = Database :: fetch_array($res); |
|
| 2924 | $num = $row[0]; |
|
| 2925 | } |
|
| 2926 | ||
| 2927 | return $num; |
|
| 2928 | } |
|
| 2929 | ||
| 2930 | /** |
|
| 2931 | * Return the objectives as an array for the given lp_iv_id. |
|
| @@ 2654-2675 (lines=22) @@ | ||
| 2651 | * @param array $courseInfo |
|
| 2652 | * @return array with the post info |
|
| 2653 | */ |
|
| 2654 | public function getAttachment($attachmentId, $eventId, $courseInfo) |
|
| 2655 | { |
|
| 2656 | $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 2657 | $courseId = intval($courseInfo['real_id']); |
|
| 2658 | $eventId = intval($eventId); |
|
| 2659 | $attachmentId = intval($attachmentId); |
|
| 2660 | ||
| 2661 | $row = array(); |
|
| 2662 | $sql = "SELECT id, path, filename, comment |
|
| 2663 | FROM $tableAttachment |
|
| 2664 | WHERE |
|
| 2665 | c_id = $courseId AND |
|
| 2666 | agenda_id = $eventId AND |
|
| 2667 | id = $attachmentId |
|
| 2668 | "; |
|
| 2669 | $result = Database::query($sql); |
|
| 2670 | if (Database::num_rows($result) != 0) { |
|
| 2671 | $row = Database::fetch_array($result, 'ASSOC'); |
|
| 2672 | } |
|
| 2673 | ||
| 2674 | return $row; |
|
| 2675 | } |
|
| 2676 | ||
| 2677 | /** |
|
| 2678 | * Add an attachment file into agenda |
|
| @@ 2627-2645 (lines=19) @@ | ||
| 2624 | * @param array $courseInfo |
|
| 2625 | * @return array with the post info |
|
| 2626 | */ |
|
| 2627 | public function getAttachmentList($eventId, $courseInfo) |
|
| 2628 | { |
|
| 2629 | $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 2630 | $courseId = intval($courseInfo['real_id']); |
|
| 2631 | $eventId = intval($eventId); |
|
| 2632 | ||
| 2633 | $sql = "SELECT id, path, filename, comment |
|
| 2634 | FROM $tableAttachment |
|
| 2635 | WHERE |
|
| 2636 | c_id = $courseId AND |
|
| 2637 | agenda_id = $eventId"; |
|
| 2638 | $result = Database::query($sql); |
|
| 2639 | $list = array(); |
|
| 2640 | if (Database::num_rows($result) != 0) { |
|
| 2641 | $list = Database::store_result($result, 'ASSOC'); |
|
| 2642 | } |
|
| 2643 | ||
| 2644 | return $list; |
|
| 2645 | } |
|
| 2646 | ||
| 2647 | /** |
|
| 2648 | * Show a list with all the attachments according to the post's id |
|
| @@ 5051-5072 (lines=22) @@ | ||
| 5048 | * @param int $courseId |
|
| 5049 | * @return array |
|
| 5050 | */ |
|
| 5051 | public static function getCoachesByCourseSession($sessionId, $courseId) |
|
| 5052 | { |
|
| 5053 | $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
|
| 5054 | $sessionId = intval($sessionId); |
|
| 5055 | $courseId = intval($courseId); |
|
| 5056 | ||
| 5057 | $sql = "SELECT user_id FROM $table |
|
| 5058 | WHERE |
|
| 5059 | session_id = '$sessionId' AND |
|
| 5060 | c_id = '$courseId' AND |
|
| 5061 | status = 2"; |
|
| 5062 | $result = Database::query($sql); |
|
| 5063 | ||
| 5064 | $coaches = array(); |
|
| 5065 | if (Database::num_rows($result) > 0) { |
|
| 5066 | while ($row = Database::fetch_row($result)) { |
|
| 5067 | $coaches[] = $row['user_id']; |
|
| 5068 | } |
|
| 5069 | } |
|
| 5070 | ||
| 5071 | return $coaches; |
|
| 5072 | } |
|
| 5073 | ||
| 5074 | /** |
|
| 5075 | * @param int $sessionId |
|