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

@@ 1135-1156 (lines=22) @@
1132
     * @return int User id
1133
     * @assert ('0','---') === 0
1134
     */
1135
    public static function get_user_id_from_original_id($original_user_id_value, $original_user_id_name)
1136
    {
1137
        $t_uf = Database::get_main_table(TABLE_EXTRA_FIELD);
1138
        $t_ufv = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
1139
        $extraFieldType = EntityExtraField::USER_FIELD_TYPE;
1140
        $sql = "SELECT item_id as user_id
1141
                FROM $t_uf uf
1142
                INNER JOIN $t_ufv ufv
1143
                ON ufv.field_id=uf.id
1144
                WHERE
1145
                    variable='$original_user_id_name' AND
1146
                    value='$original_user_id_value' AND
1147
                    extra_field_type = $extraFieldType
1148
                ";
1149
        $res = Database::query($sql);
1150
        $row = Database::fetch_object($res);
1151
        if ($row) {
1152
            return $row->user_id;
1153
        } else {
1154
            return 0;
1155
        }
1156
    }
1157
1158
    /**
1159
     * Check if a username is available

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

@@ 4146-4158 (lines=13) @@
4143
 * @param   string  language name (the corresponding name of the language-folder in the filesystem)
4144
 * @return  int     id of the language
4145
 */
4146
function api_get_language_id($language)
4147
{
4148
    $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
4149
    if (empty($language)) {
4150
        return null;
4151
    }
4152
    $language = Database::escape_string($language);
4153
    $sql = "SELECT id FROM $tbl_language
4154
            WHERE dokeos_folder = '$language' LIMIT 1";
4155
    $result = Database::query($sql);
4156
    $row = Database::fetch_array($result);
4157
    return $row['id'];
4158
}
4159
4160
/**
4161
 * Gets language of the requested type for the current user. Types are :