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

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

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

@@ 4164-4176 (lines=13) @@
4161
 * @param   string  language name (the corresponding name of the language-folder in the filesystem)
4162
 * @return  int     id of the language
4163
 */
4164
function api_get_language_id($language)
4165
{
4166
    $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
4167
    if (empty($language)) {
4168
        return null;
4169
    }
4170
    $language = Database::escape_string($language);
4171
    $sql = "SELECT id FROM $tbl_language
4172
            WHERE dokeos_folder = '$language' LIMIT 1";
4173
    $result = Database::query($sql);
4174
    $row = Database::fetch_array($result);
4175
    return $row['id'];
4176
}
4177
4178
/**
4179
 * Gets language of the requested type for the current user. Types are :