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

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