@@ 1823-1849 (lines=27) @@ | ||
1820 | * @param int $id Numeric ID of the course |
|
1821 | * @return array The course info as an array formatted by api_format_course_array, including category.name |
|
1822 | */ |
|
1823 | function api_get_course_info_by_id($id = null) |
|
1824 | { |
|
1825 | if (!empty($id)) { |
|
1826 | $id = intval($id); |
|
1827 | $course_table = Database::get_main_table(TABLE_MAIN_COURSE); |
|
1828 | $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY); |
|
1829 | $sql = "SELECT |
|
1830 | course.*, |
|
1831 | course_category.code faCode, |
|
1832 | course_category.name faName |
|
1833 | FROM $course_table |
|
1834 | LEFT JOIN $course_cat_table |
|
1835 | ON course.category_code = course_category.code |
|
1836 | WHERE course.id = $id"; |
|
1837 | $result = Database::query($sql); |
|
1838 | $_course = array(); |
|
1839 | if (Database::num_rows($result) > 0) { |
|
1840 | $course_data = Database::fetch_array($result); |
|
1841 | $_course = api_format_course_array($course_data); |
|
1842 | } |
|
1843 | return $_course; |
|
1844 | } |
|
1845 | ||
1846 | global $_course; |
|
1847 | if ($_course == '-1') $_course = array(); |
|
1848 | return $_course; |
|
1849 | } |
|
1850 | ||
1851 | /** |
|
1852 | * Reformat the course array (output by api_get_course_info()) in order, mostly, |
@@ 728-753 (lines=26) @@ | ||
725 | * current course) |
|
726 | * @return array The category |
|
727 | */ |
|
728 | public static function get_category_from_group($group_id, $course_code = null) |
|
729 | { |
|
730 | $table_group = Database:: get_course_table(TABLE_GROUP); |
|
731 | $table_group_cat = Database:: get_course_table(TABLE_GROUP_CATEGORY); |
|
732 | ||
733 | if (empty($group_id)) { |
|
734 | return array(); |
|
735 | } |
|
736 | ||
737 | $course_info = api_get_course_info($course_code); |
|
738 | $course_id = $course_info['real_id']; |
|
739 | ||
740 | $group_id = intval($group_id); |
|
741 | $sql = "SELECT gc.* FROM $table_group_cat gc, $table_group g |
|
742 | WHERE |
|
743 | gc.c_id = $course_id AND |
|
744 | g.c_id = $course_id AND |
|
745 | gc.id = g.category_id AND g.id= $group_id |
|
746 | LIMIT 1"; |
|
747 | $res = Database::query($sql); |
|
748 | $cat = array(); |
|
749 | if (Database::num_rows($res)) { |
|
750 | $cat = Database::fetch_array($res); |
|
751 | } |
|
752 | return $cat; |
|
753 | } |
|
754 | ||
755 | /** |
|
756 | * Delete a group category |