Code Duplication    Length = 13-22 lines in 4 locations

main/gradebook/lib/GradebookUtils.php 1 location

@@ 408-422 (lines=15) @@
405
     * @param    int     Link/Resource ID
406
     * @return   bool    false on error, true on success
407
     */
408
    public static function get_resource_from_course_gradebook($link_id)
409
    {
410
        if (empty($link_id)) {
411
            return false;
412
        }
413
        // TODO find the corresponding category (the first one for this course, ordered by ID)
414
        $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
415
        $sql = "SELECT * FROM $l WHERE id = " . (int) $link_id;
416
        $res = Database::query($sql);
417
        $row = array();
418
        if (Database::num_rows($res) > 0) {
419
            $row = Database::fetch_array($res, 'ASSOC');
420
        }
421
        return $row;
422
    }
423
424
    /**
425
     * Return the course id

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

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

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

@@ 4267-4279 (lines=13) @@
4264
 * @param   string  language name (the corresponding name of the language-folder in the filesystem)
4265
 * @return  int     id of the language
4266
 */
4267
function api_get_language_id($language)
4268
{
4269
    $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
4270
    if (empty($language)) {
4271
        return null;
4272
    }
4273
    $language = Database::escape_string($language);
4274
    $sql = "SELECT id FROM $tbl_language
4275
            WHERE dokeos_folder = '$language' LIMIT 1";
4276
    $result = Database::query($sql);
4277
    $row = Database::fetch_array($result);
4278
    return $row['id'];
4279
}
4280
4281
/**
4282
 * Gets language of the requested type for the current user. Types are :

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

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