Code Duplication    Length = 14-24 lines in 4 locations

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

@@ 327-340 (lines=14) @@
324
     *
325
     * @return array
326
     */
327
    public static function getChildren($categoryCode)
328
    {
329
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
330
        $categoryCode = Database::escape_string($categoryCode);
331
        $result = Database::query("SELECT code, id FROM $tbl_category WHERE parent_id = '$categoryCode'");
332
        $children = array();
333
        while ($row = Database::fetch_array($result, 'ASSOC')) {
334
            $children[] = $row;
335
            $subChildren = self::getChildren($row['code']);
336
            $children = array_merge($children, $subChildren);
337
        }
338
339
        return $children;
340
    }
341
342
    /**
343
     * @param string $categoryCode

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

@@ 3280-3302 (lines=23) @@
3277
     * @param    int        Session id
3278
     * @return    array    Courses list
3279
     */
3280
    public static function get_courses_list_from_session($session_id)
3281
    {
3282
        $session_id = intval($session_id);
3283
3284
        // table definition
3285
        $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
3286
        $courseTable = Database :: get_main_table(TABLE_MAIN_COURSE);
3287
3288
        $sql = "SELECT DISTINCT code, c_id
3289
                FROM $tbl_session_course sc
3290
                INNER JOIN $courseTable c
3291
                ON sc.c_id = c.id
3292
                WHERE session_id= $session_id";
3293
3294
        $result = Database::query($sql);
3295
3296
        $courses = array();
3297
        while ($row = Database::fetch_array($result)) {
3298
            $courses[$row['code']] = $row;
3299
        }
3300
3301
        return $courses;
3302
    }
3303
3304
    /**
3305
     * Count the number of documents that an user has uploaded to a course

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

@@ 5152-5175 (lines=24) @@
5149
     * @param string $lastname Lastname to search
5150
     * @return array The user list
5151
     */
5152
    public static function getUserByName($firstname, $lastname)
5153
    {
5154
        $firstname = Database::escape_string($firstname);
5155
        $lastname = Database::escape_string($lastname);
5156
5157
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
5158
5159
        $sql = <<<SQL
5160
            SELECT id, username, lastname, firstname
5161
            FROM $userTable
5162
            WHERE firstname LIKE '$firstname%' AND
5163
                lastname LIKE '$lastname%'
5164
SQL;
5165
5166
        $result = Database::query($sql);
5167
5168
        $users = [];
5169
5170
        while ($resultData = Database::fetch_object($result)) {
5171
            $users[] = $resultData;
5172
        }
5173
5174
        return $users;
5175
    }
5176
5177
    /**
5178
     * @param int $optionSelected

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

@@ 5684-5699 (lines=16) @@
5681
 * @author Julio Montoya <[email protected]>
5682
 * @return int user id
5683
 */
5684
function api_get_access_url_from_user($user_id) {
5685
    $user_id = intval($user_id);
5686
    $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
5687
    $table_url          = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
5688
    $sql = "SELECT access_url_id
5689
            FROM $table_url_rel_user url_rel_user
5690
            INNER JOIN $table_url u
5691
            ON (url_rel_user.access_url_id = u.id)
5692
            WHERE user_id = ".intval($user_id);
5693
    $result = Database::query($sql);
5694
    $url_list = array();
5695
    while ($row = Database::fetch_array($result, 'ASSOC')) {
5696
        $url_list[] = $row['access_url_id'];
5697
    }
5698
    return $url_list;
5699
}
5700
5701
/**
5702
 * Gets the status of a user in a course