Code Duplication    Length = 13-22 lines in 4 locations

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

@@ 787-803 (lines=17) @@
784
     * @param string $event_type
785
     * @return array|bool
786
     */
787
    public static function get_events_by_user_and_type($user_id, $event_type)
788
    {
789
        $TABLETRACK_DEFAULT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
790
        $user_id = intval($user_id);
791
        $event_type = Database::escape_string($event_type);
792
793
        $sql = "SELECT * FROM $TABLETRACK_DEFAULT
794
                WHERE default_value_type = 'user_id' AND
795
                      default_value = $user_id AND
796
                      default_event_type = '$event_type'
797
                ORDER BY default_date ";
798
        $result = Database::query($sql);
799
        if ($result) {
800
            return Database::store_result($result, 'ASSOC');
801
        }
802
        return false;
803
    }
804
805
    /**
806
     * Save the new message for one event and for one language

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/api.lib.php 1 location

@@ 4204-4216 (lines=13) @@
4201
 * @param   string  language name (the corresponding name of the language-folder in the filesystem)
4202
 * @return  int     id of the language
4203
 */
4204
function api_get_language_id($language)
4205
{
4206
    $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
4207
    if (empty($language)) {
4208
        return null;
4209
    }
4210
    $language = Database::escape_string($language);
4211
    $sql = "SELECT id FROM $tbl_language
4212
            WHERE dokeos_folder = '$language' LIMIT 1";
4213
    $result = Database::query($sql);
4214
    $row = Database::fetch_array($result);
4215
    return $row['id'];
4216
}
4217
4218
/**
4219
 * Gets language of the requested type for the current user. Types are :

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

@@ 1168-1189 (lines=22) @@
1165
     * @return int User id
1166
     * @assert ('0','---') === 0
1167
     */
1168
    public static function get_user_id_from_original_id($original_user_id_value, $original_user_id_name)
1169
    {
1170
        $t_uf = Database::get_main_table(TABLE_EXTRA_FIELD);
1171
        $t_ufv = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
1172
        $extraFieldType = EntityExtraField::USER_FIELD_TYPE;
1173
        $sql = "SELECT item_id as user_id
1174
                FROM $t_uf uf
1175
                INNER JOIN $t_ufv ufv
1176
                ON ufv.field_id=uf.id
1177
                WHERE
1178
                    variable='$original_user_id_name' AND
1179
                    value='$original_user_id_value' AND
1180
                    extra_field_type = $extraFieldType
1181
                ";
1182
        $res = Database::query($sql);
1183
        $row = Database::fetch_object($res);
1184
        if ($row) {
1185
            return $row->user_id;
1186
        } else {
1187
            return 0;
1188
        }
1189
    }
1190
1191
    /**
1192
     * Check if a username is available