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

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