@@ 729-754 (lines=26) @@ | ||
726 | * current course) |
|
727 | * @return array The category |
|
728 | */ |
|
729 | public static function get_category_from_group($group_id, $course_code = null) |
|
730 | { |
|
731 | $table_group = Database:: get_course_table(TABLE_GROUP); |
|
732 | $table_group_cat = Database:: get_course_table(TABLE_GROUP_CATEGORY); |
|
733 | ||
734 | if (empty($group_id)) { |
|
735 | return array(); |
|
736 | } |
|
737 | ||
738 | $course_info = api_get_course_info($course_code); |
|
739 | $course_id = $course_info['real_id']; |
|
740 | ||
741 | $group_id = intval($group_id); |
|
742 | $sql = "SELECT gc.* FROM $table_group_cat gc, $table_group g |
|
743 | WHERE |
|
744 | gc.c_id = $course_id AND |
|
745 | g.c_id = $course_id AND |
|
746 | gc.id = g.category_id AND g.id= $group_id |
|
747 | LIMIT 1"; |
|
748 | $res = Database::query($sql); |
|
749 | $cat = array(); |
|
750 | if (Database::num_rows($res)) { |
|
751 | $cat = Database::fetch_array($res); |
|
752 | } |
|
753 | return $cat; |
|
754 | } |
|
755 | ||
756 | /** |
|
757 | * Delete a group category |
@@ 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, |