| @@ 432-443 (lines=12) @@ | ||
| 429 | * @param int |
|
| 430 | * @return String |
|
| 431 | */ |
|
| 432 | public static function get_course_id_by_link_id($id_link) |
|
| 433 | { |
|
| 434 | $course_table = Database::get_main_table(TABLE_MAIN_COURSE); |
|
| 435 | $tbl_grade_links = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
| 436 | $sql = 'SELECT c.id FROM ' . $course_table . ' c |
|
| 437 | INNER JOIN ' . $tbl_grade_links . ' l |
|
| 438 | ON c.code = l.course_code |
|
| 439 | WHERE l.id=' . intval($id_link) . ' OR l.category_id=' . intval($id_link); |
|
| 440 | $res = Database::query($sql); |
|
| 441 | $array = Database::fetch_array($res, 'ASSOC'); |
|
| 442 | return $array['id']; |
|
| 443 | } |
|
| 444 | ||
| 445 | /** |
|
| 446 | * @param $type |
|
| @@ 1104-1119 (lines=16) @@ | ||
| 1101 | * |
|
| 1102 | * @return array() |
|
| 1103 | */ |
|
| 1104 | public static function display_rating($type, $blog_id, $item_id) |
|
| 1105 | { |
|
| 1106 | $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); |
|
| 1107 | $course_id = api_get_course_int_id(); |
|
| 1108 | ||
| 1109 | // Calculate rating |
|
| 1110 | $sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating |
|
| 1111 | WHERE |
|
| 1112 | c_id = $course_id AND |
|
| 1113 | blog_id = '".(int)$blog_id."' AND |
|
| 1114 | item_id = '".(int)$item_id."' AND |
|
| 1115 | rating_type = '".Database::escape_string($type)."' "; |
|
| 1116 | $result = Database::query($sql); |
|
| 1117 | $result = Database::fetch_array($result); |
|
| 1118 | return round($result['rating'], 2); |
|
| 1119 | } |
|
| 1120 | ||
| 1121 | /** |
|
| 1122 | * Shows the rating form if not already rated by that user |
|
| @@ 4333-4347 (lines=15) @@ | ||
| 4330 | * @param integer $user_id |
|
| 4331 | * @return int the value of the highest sort of the user_course_category |
|
| 4332 | */ |
|
| 4333 | function api_max_sort_value($user_course_category, $user_id) |
|
| 4334 | { |
|
| 4335 | $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); |
|
| 4336 | $sql = "SELECT max(sort) as max_sort FROM $tbl_course_user |
|
| 4337 | WHERE |
|
| 4338 | user_id='".intval($user_id)."' AND |
|
| 4339 | relation_type<>".COURSE_RELATION_TYPE_RRHH." AND |
|
| 4340 | user_course_cat='".intval($user_course_category)."'"; |
|
| 4341 | $result_max = Database::query($sql); |
|
| 4342 | if (Database::num_rows($result_max) == 1) { |
|
| 4343 | $row_max = Database::fetch_array($result_max); |
|
| 4344 | return $row_max['max_sort']; |
|
| 4345 | } |
|
| 4346 | return 0; |
|
| 4347 | } |
|
| 4348 | ||
| 4349 | /** |
|
| 4350 | * This function converts the string "true" or "false" to a boolean true or false. |
|