Code Duplication    Length = 26-27 lines in 2 locations

main/inc/lib/groupmanager.lib.php 1 location

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

main/inc/lib/api.lib.php 1 location

@@ 1814-1840 (lines=27) @@
1811
 * @param int $id Numeric ID of the course
1812
 * @return array The course info as an array formatted by api_format_course_array, including category.name
1813
 */
1814
function api_get_course_info_by_id($id = null)
1815
{
1816
    if (!empty($id)) {
1817
        $id = intval($id);
1818
        $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
1819
        $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
1820
        $sql = "SELECT
1821
                    course.*,
1822
                    course_category.code faCode,
1823
                    course_category.name faName
1824
                FROM $course_table
1825
                LEFT JOIN $course_cat_table
1826
                ON course.category_code =  course_category.code
1827
                WHERE course.id = $id";
1828
        $result = Database::query($sql);
1829
        $_course = array();
1830
        if (Database::num_rows($result) > 0) {
1831
            $course_data = Database::fetch_array($result);
1832
            $_course = api_format_course_array($course_data);
1833
        }
1834
        return $_course;
1835
    }
1836
1837
    global $_course;
1838
    if ($_course == '-1') $_course = array();
1839
    return $_course;
1840
}
1841
1842
/**
1843
 * Reformat the course array (output by api_get_course_info()) in order, mostly,