Code Duplication    Length = 13-22 lines in 4 locations

main/gradebook/lib/GradebookUtils.php 1 location

@@ 428-442 (lines=15) @@
425
     * @param    int     Link/Resource ID
426
     * @return   bool    false on error, true on success
427
     */
428
    public static function get_resource_from_course_gradebook($link_id)
429
    {
430
        if (empty($link_id)) {
431
            return false;
432
        }
433
        // TODO find the corresponding category (the first one for this course, ordered by ID)
434
        $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
435
        $sql = "SELECT * FROM $l WHERE id = " . (int) $link_id;
436
        $res = Database::query($sql);
437
        $row = array();
438
        if (Database::num_rows($res) > 0) {
439
            $row = Database::fetch_array($res, 'ASSOC');
440
        }
441
        return $row;
442
    }
443
444
    /**
445
     * Return the course id

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

@@ 1211-1232 (lines=22) @@
1208
     * @return int User id
1209
     * @assert ('0','---') === 0
1210
     */
1211
    public static function get_user_id_from_original_id($original_user_id_value, $original_user_id_name)
1212
    {
1213
        $t_uf = Database::get_main_table(TABLE_EXTRA_FIELD);
1214
        $t_ufv = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
1215
        $extraFieldType = EntityExtraField::USER_FIELD_TYPE;
1216
        $sql = "SELECT item_id as user_id
1217
                FROM $t_uf uf
1218
                INNER JOIN $t_ufv ufv
1219
                ON ufv.field_id=uf.id
1220
                WHERE
1221
                    variable='$original_user_id_name' AND
1222
                    value='$original_user_id_value' AND
1223
                    extra_field_type = $extraFieldType
1224
                ";
1225
        $res = Database::query($sql);
1226
        $row = Database::fetch_object($res);
1227
        if ($row) {
1228
            return $row->user_id;
1229
        } else {
1230
            return 0;
1231
        }
1232
    }
1233
1234
    /**
1235
     * Check if a username is available

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

@@ 798-814 (lines=17) @@
795
     * @param string $event_type
796
     * @return array|bool
797
     */
798
    public static function get_events_by_user_and_type($user_id, $event_type)
799
    {
800
        $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
801
        $user_id = intval($user_id);
802
        $event_type = Database::escape_string($event_type);
803
804
        $sql = "SELECT * FROM $table
805
                WHERE default_value_type = 'user_id' AND
806
                      default_value = $user_id AND
807
                      default_event_type = '$event_type'
808
                ORDER BY default_date ";
809
        $result = Database::query($sql);
810
        if ($result) {
811
            return Database::store_result($result, 'ASSOC');
812
        }
813
        return false;
814
    }
815
816
    /**
817
     * Save the new message for one event and for one language

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

@@ 4285-4297 (lines=13) @@
4282
 * @param   string  language name (the corresponding name of the language-folder in the filesystem)
4283
 * @return  int     id of the language
4284
 */
4285
function api_get_language_id($language)
4286
{
4287
    $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
4288
    if (empty($language)) {
4289
        return null;
4290
    }
4291
    $language = Database::escape_string($language);
4292
    $sql = "SELECT id FROM $tbl_language
4293
            WHERE dokeos_folder = '$language' LIMIT 1";
4294
    $result = Database::query($sql);
4295
    $row = Database::fetch_array($result);
4296
    return $row['id'];
4297
}
4298
4299
/**
4300
 * Gets language of the requested type for the current user. Types are :