| @@ 1201-1221 (lines=21) @@ | ||
| 1198 | * @param int attendance id |
|
| 1199 | * @return int attendance calendar id |
|
| 1200 | */ |
|
| 1201 | public function get_next_attendance_calendar_id($attendance_id) |
|
| 1202 | { |
|
| 1203 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1204 | $attendance_id = intval($attendance_id); |
|
| 1205 | $course_id = api_get_course_int_id(); |
|
| 1206 | ||
| 1207 | $sql = "SELECT id FROM $tbl_attendance_calendar |
|
| 1208 | WHERE |
|
| 1209 | c_id = $course_id AND |
|
| 1210 | attendance_id = '$attendance_id' AND |
|
| 1211 | done_attendance = 0 |
|
| 1212 | ORDER BY date_time |
|
| 1213 | LIMIT 1"; |
|
| 1214 | $rs = Database::query($sql); |
|
| 1215 | $next_calendar_id = 0; |
|
| 1216 | if (Database::num_rows($rs) > 0) { |
|
| 1217 | $row = Database::fetch_array($rs); |
|
| 1218 | $next_calendar_id = $row['id']; |
|
| 1219 | } |
|
| 1220 | return $next_calendar_id; |
|
| 1221 | } |
|
| 1222 | ||
| 1223 | /** |
|
| 1224 | * Get next attendance calendar datetime without presences (done attendances) |
|
| @@ 1228-1248 (lines=21) @@ | ||
| 1225 | * @param int attendance id |
|
| 1226 | * @return int UNIX time format datetime |
|
| 1227 | */ |
|
| 1228 | public function get_next_attendance_calendar_datetime($attendance_id) |
|
| 1229 | { |
|
| 1230 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1231 | $course_id = api_get_course_int_id(); |
|
| 1232 | $attendance_id = intval($attendance_id); |
|
| 1233 | $sql = "SELECT id, date_time FROM $tbl_attendance_calendar |
|
| 1234 | WHERE |
|
| 1235 | c_id = $course_id AND |
|
| 1236 | attendance_id = '$attendance_id' AND |
|
| 1237 | done_attendance = 0 |
|
| 1238 | ORDER BY date_time |
|
| 1239 | LIMIT 1"; |
|
| 1240 | $rs = Database::query($sql); |
|
| 1241 | $next_calendar_datetime = 0; |
|
| 1242 | if (Database::num_rows($rs) > 0) { |
|
| 1243 | $row = Database::fetch_array($rs); |
|
| 1244 | $next_calendar_datetime = api_get_local_time($row['date_time']); |
|
| 1245 | } |
|
| 1246 | ||
| 1247 | return $next_calendar_datetime; |
|
| 1248 | } |
|
| 1249 | ||
| 1250 | /** |
|
| 1251 | * Get user' score from current attendance |
|
| @@ 1303-1320 (lines=18) @@ | ||
| 1300 | * @param int attendance calendar id |
|
| 1301 | * @return array attendance calendar data |
|
| 1302 | */ |
|
| 1303 | public function get_attendance_calendar_by_id($calendar_id) |
|
| 1304 | { |
|
| 1305 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1306 | $calendar_id = intval($calendar_id); |
|
| 1307 | $course_id = api_get_course_int_id(); |
|
| 1308 | $sql = "SELECT * FROM $tbl_attendance_calendar |
|
| 1309 | WHERE c_id = $course_id AND id = '$calendar_id' "; |
|
| 1310 | $rs = Database::query($sql); |
|
| 1311 | $data = array(); |
|
| 1312 | if (Database::num_rows($rs) > 0) { |
|
| 1313 | while ($row = Database::fetch_array($rs)) { |
|
| 1314 | $row['date_time'] = api_get_local_time($row['date_time']); |
|
| 1315 | $data = $row; |
|
| 1316 | } |
|
| 1317 | } |
|
| 1318 | ||
| 1319 | return $data; |
|
| 1320 | } |
|
| 1321 | ||
| 1322 | /** |
|
| 1323 | * Get all attendance calendar data inside current attendance |
|
| @@ 1515-1531 (lines=17) @@ | ||
| 1512 | * @param int $attendance_id |
|
| 1513 | * @return int count of dates |
|
| 1514 | */ |
|
| 1515 | public static function get_count_dates_inside_attendance_calendar($attendance_id) |
|
| 1516 | { |
|
| 1517 | $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 1518 | $attendance_id = intval($attendance_id); |
|
| 1519 | $course_id = api_get_course_int_id(); |
|
| 1520 | $sql = "SELECT count(id) FROM $tbl_attendance_calendar |
|
| 1521 | WHERE |
|
| 1522 | c_id = $course_id AND |
|
| 1523 | attendance_id = '$attendance_id'"; |
|
| 1524 | $rs = Database::query($sql); |
|
| 1525 | $count = 0; |
|
| 1526 | if (Database::num_rows($rs) > 0) { |
|
| 1527 | $row = Database::fetch_row($rs); |
|
| 1528 | $count = $row[0]; |
|
| 1529 | } |
|
| 1530 | return $count; |
|
| 1531 | } |
|
| 1532 | ||
| 1533 | /** |
|
| 1534 | * check if all calendar of an attendance is done |
|
| @@ 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 |
|
| @@ 1496-1523 (lines=28) @@ | ||
| 1493 | * |
|
| 1494 | * @return array |
|
| 1495 | */ |
|
| 1496 | public static function getLatestHotPotatoResult( |
|
| 1497 | $exercisePath, |
|
| 1498 | $userId, |
|
| 1499 | $courseId, |
|
| 1500 | $sessionId |
|
| 1501 | ) |
|
| 1502 | { |
|
| 1503 | $table = Database:: get_main_table( |
|
| 1504 | TABLE_STATISTIC_TRACK_E_HOTPOTATOES |
|
| 1505 | ); |
|
| 1506 | ||
| 1507 | $courseInfo = api_get_course_info_by_id($courseId); |
|
| 1508 | $exercisePath = Database::escape_string($exercisePath); |
|
| 1509 | $userId = intval($userId); |
|
| 1510 | ||
| 1511 | $sql = "SELECT * FROM $table |
|
| 1512 | WHERE |
|
| 1513 | c_id = $courseId AND |
|
| 1514 | exe_name LIKE '$exercisePath%' AND |
|
| 1515 | exe_user_id = $userId |
|
| 1516 | ORDER BY id |
|
| 1517 | LIMIT 1"; |
|
| 1518 | $result = Database::query($sql); |
|
| 1519 | $attempt = array(); |
|
| 1520 | if (Database::num_rows($result)) { |
|
| 1521 | $attempt = Database::fetch_array($result, 'ASSOC'); |
|
| 1522 | } |
|
| 1523 | return $attempt; |
|
| 1524 | } |
|
| 1525 | ||
| 1526 | /** |
|
| @@ 2891-2906 (lines=16) @@ | ||
| 2888 | * @param integer course id |
|
| 2889 | * @return integer Number of interactions |
|
| 2890 | */ |
|
| 2891 | public static function get_interactions_count_from_db($lp_iv_id, $course_id) |
|
| 2892 | { |
|
| 2893 | $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION); |
|
| 2894 | $lp_iv_id = intval($lp_iv_id); |
|
| 2895 | $course_id = intval($course_id); |
|
| 2896 | ||
| 2897 | $sql = "SELECT count(*) FROM $table |
|
| 2898 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
|
| 2899 | $res = Database::query($sql); |
|
| 2900 | $num = 0; |
|
| 2901 | if (Database::num_rows($res)) { |
|
| 2902 | $row = Database::fetch_array($res); |
|
| 2903 | $num = $row[0]; |
|
| 2904 | } |
|
| 2905 | return $num; |
|
| 2906 | } |
|
| 2907 | ||
| 2908 | /** |
|
| 2909 | * Return the interactions as an array for the given lp_iv_id. |
|
| @@ 2965-2981 (lines=17) @@ | ||
| 2962 | * @param integer Item View ID |
|
| 2963 | * @return integer Number of objectives |
|
| 2964 | */ |
|
| 2965 | public static function get_objectives_count_from_db($lp_iv_id, $course_id) |
|
| 2966 | { |
|
| 2967 | $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE); |
|
| 2968 | $course_id = intval($course_id); |
|
| 2969 | $lp_iv_id = intval($lp_iv_id); |
|
| 2970 | $sql = "SELECT count(*) FROM $table |
|
| 2971 | WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id"; |
|
| 2972 | //@todo seems that this always returns 0 |
|
| 2973 | $res = Database::query($sql); |
|
| 2974 | $num = 0; |
|
| 2975 | if (Database::num_rows($res)) { |
|
| 2976 | $row = Database :: fetch_array($res); |
|
| 2977 | $num = $row[0]; |
|
| 2978 | } |
|
| 2979 | ||
| 2980 | return $num; |
|
| 2981 | } |
|
| 2982 | ||
| 2983 | /** |
|
| 2984 | * Return the objectives as an array for the given lp_iv_id. |
|
| @@ 4849-4870 (lines=22) @@ | ||
| 4846 | * @param int $courseId |
|
| 4847 | * @return array |
|
| 4848 | */ |
|
| 4849 | public static function getCoachesByCourseSession($sessionId, $courseId) |
|
| 4850 | { |
|
| 4851 | $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
|
| 4852 | $sessionId = intval($sessionId); |
|
| 4853 | $courseId = intval($courseId); |
|
| 4854 | ||
| 4855 | $sql = "SELECT user_id FROM $table |
|
| 4856 | WHERE |
|
| 4857 | session_id = '$sessionId' AND |
|
| 4858 | c_id = '$courseId' AND |
|
| 4859 | status = 2"; |
|
| 4860 | $result = Database::query($sql); |
|
| 4861 | ||
| 4862 | $coaches = array(); |
|
| 4863 | if (Database::num_rows($result) > 0) { |
|
| 4864 | while ($row = Database::fetch_row($result)) { |
|
| 4865 | $coaches[] = $row[0]; |
|
| 4866 | } |
|
| 4867 | } |
|
| 4868 | ||
| 4869 | return $coaches; |
|
| 4870 | } |
|
| 4871 | ||
| 4872 | /** |
|
| 4873 | * @param int $sessionId |
|
| @@ 2231-2249 (lines=19) @@ | ||
| 2228 | * @param array $courseInfo |
|
| 2229 | * @return array with the post info |
|
| 2230 | */ |
|
| 2231 | public function getAttachmentList($eventId, $courseInfo) |
|
| 2232 | { |
|
| 2233 | $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 2234 | $courseId = intval($courseInfo['real_id']); |
|
| 2235 | $eventId = intval($eventId); |
|
| 2236 | ||
| 2237 | $sql = "SELECT id, path, filename, comment |
|
| 2238 | FROM $tableAttachment |
|
| 2239 | WHERE |
|
| 2240 | c_id = $courseId AND |
|
| 2241 | agenda_id = $eventId"; |
|
| 2242 | $result = Database::query($sql); |
|
| 2243 | $list = array(); |
|
| 2244 | if (Database::num_rows($result) != 0) { |
|
| 2245 | $list = Database::store_result($result, 'ASSOC'); |
|
| 2246 | } |
|
| 2247 | ||
| 2248 | return $list; |
|
| 2249 | } |
|
| 2250 | ||
| 2251 | ||
| 2252 | /** |
|
| @@ 2259-2280 (lines=22) @@ | ||
| 2256 | * @param array $courseInfo |
|
| 2257 | * @return array with the post info |
|
| 2258 | */ |
|
| 2259 | public function getAttachment($attachmentId, $eventId, $courseInfo) |
|
| 2260 | { |
|
| 2261 | $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 2262 | $courseId = intval($courseInfo['real_id']); |
|
| 2263 | $eventId = intval($eventId); |
|
| 2264 | $attachmentId = intval($attachmentId); |
|
| 2265 | ||
| 2266 | $row = array(); |
|
| 2267 | $sql = "SELECT id, path, filename, comment |
|
| 2268 | FROM $tableAttachment |
|
| 2269 | WHERE |
|
| 2270 | c_id = $courseId AND |
|
| 2271 | agenda_id = $eventId AND |
|
| 2272 | id = $attachmentId |
|
| 2273 | "; |
|
| 2274 | $result = Database::query($sql); |
|
| 2275 | if (Database::num_rows($result) != 0) { |
|
| 2276 | $row = Database::fetch_array($result, 'ASSOC'); |
|
| 2277 | } |
|
| 2278 | ||
| 2279 | return $row; |
|
| 2280 | } |
|
| 2281 | ||
| 2282 | /** |
|
| 2283 | * Add an attachment file into agenda |
|
| @@ 6312-6329 (lines=18) @@ | ||
| 6309 | return $question_count; |
|
| 6310 | } |
|
| 6311 | ||
| 6312 | function get_exercise_list_ordered() |
|
| 6313 | { |
|
| 6314 | $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER); |
|
| 6315 | $course_id = api_get_course_int_id(); |
|
| 6316 | $session_id = api_get_session_id(); |
|
| 6317 | $sql = "SELECT exercise_id, exercise_order |
|
| 6318 | FROM $table_exercise_order |
|
| 6319 | WHERE c_id = $course_id AND session_id = $session_id |
|
| 6320 | ORDER BY exercise_order"; |
|
| 6321 | $result = Database::query($sql); |
|
| 6322 | $list = array(); |
|
| 6323 | if (Database::num_rows($result)) { |
|
| 6324 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
| 6325 | $list[$row['exercise_order']] = $row['exercise_id']; |
|
| 6326 | } |
|
| 6327 | } |
|
| 6328 | return $list; |
|
| 6329 | } |
|
| 6330 | ||
| 6331 | /** |
|
| 6332 | * Get categories added in the exercise--category matrix |
|
| @@ 8213-8235 (lines=23) @@ | ||
| 8210 | * @param int $sessionId |
|
| 8211 | * @return array exercises |
|
| 8212 | */ |
|
| 8213 | public function getExercisesByCouseSession($courseId, $sessionId) |
|
| 8214 | { |
|
| 8215 | $courseId = intval($courseId); |
|
| 8216 | $sessionId = intval($sessionId); |
|
| 8217 | ||
| 8218 | $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST); |
|
| 8219 | $sql = "SELECT * FROM $tbl_quiz cq |
|
| 8220 | WHERE |
|
| 8221 | cq.c_id = %s AND |
|
| 8222 | (cq.session_id = %s OR cq.session_id = 0) AND |
|
| 8223 | cq.active = 0 |
|
| 8224 | ORDER BY cq.id"; |
|
| 8225 | $sql = sprintf($sql, $courseId, $sessionId); |
|
| 8226 | ||
| 8227 | $result = Database::query($sql); |
|
| 8228 | ||
| 8229 | $rows = array(); |
|
| 8230 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
| 8231 | $rows[] = $row; |
|
| 8232 | } |
|
| 8233 | ||
| 8234 | return $rows; |
|
| 8235 | } |
|
| 8236 | ||
| 8237 | /** |
|
| 8238 | * |
|