Code Duplication    Length = 23-26 lines in 4 locations

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

@@ 151-176 (lines=26) @@
148
 * @param int $ref_id representative id inside one tool item
149
 * @return array
150
 */
151
function get_specific_field_values_list_by_prefix(
152
    $prefix,
153
    $course_code,
154
    $tool_id,
155
    $ref_id
156
) {
157
    $table_sf = Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
158
    $table_sfv = Database::get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
159
    $sql = 'SELECT sfv.value FROM %s sf LEFT JOIN %s sfv ON sf.id = sfv.field_id'.
160
        ' WHERE sf.code = \'%s\' AND sfv.c_id = \'%s\' AND tool_id = \'%s\' AND sfv.ref_id = %s';
161
    $sql = sprintf(
162
        $sql,
163
        $table_sf,
164
        $table_sfv,
165
        $prefix,
166
        $course_code,
167
        $tool_id,
168
        $ref_id
169
    );
170
    $sql_result = Database::query($sql);
171
    while ($result = Database::fetch_array($sql_result)) {
172
        $return_array[] = $result;
173
    }
174
175
    return $return_array;
176
}
177
178
/**
179
 * Add a specific field value

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

@@ 1622-1647 (lines=26) @@
1619
     *
1620
     * @return array
1621
     */
1622
    public static function getLatestHotPotatoResult(
1623
        $exercisePath,
1624
        $userId,
1625
        $courseId,
1626
        $sessionId
1627
    ) {
1628
        $table = Database::get_main_table(
1629
            TABLE_STATISTIC_TRACK_E_HOTPOTATOES
1630
        );
1631
        $exercisePath = Database::escape_string($exercisePath);
1632
        $userId = intval($userId);
1633
1634
        $sql = "SELECT * FROM $table
1635
            WHERE
1636
                c_id = $courseId AND
1637
                exe_name LIKE '$exercisePath%' AND
1638
                exe_user_id = $userId
1639
            ORDER BY id
1640
            LIMIT 1";
1641
        $result = Database::query($sql);
1642
        $attempt = array();
1643
        if (Database::num_rows($result)) {
1644
            $attempt = Database::fetch_array($result, 'ASSOC');
1645
        }
1646
        return $attempt;
1647
    }
1648
1649
    /**
1650
     * Gets the exam'data results

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

@@ 3466-3488 (lines=23) @@
3463
     * @param    int        Session id
3464
     * @return    array    Courses list
3465
     */
3466
    public static function get_courses_list_from_session($session_id)
3467
    {
3468
        $session_id = intval($session_id);
3469
3470
        // table definition
3471
        $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
3472
        $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
3473
3474
        $sql = "SELECT DISTINCT code, c_id
3475
                FROM $tbl_session_course sc
3476
                INNER JOIN $courseTable c
3477
                ON sc.c_id = c.id
3478
                WHERE session_id= $session_id";
3479
3480
        $result = Database::query($sql);
3481
3482
        $courses = array();
3483
        while ($row = Database::fetch_array($result)) {
3484
            $courses[$row['code']] = $row;
3485
        }
3486
3487
        return $courses;
3488
    }
3489
3490
    /**
3491
     * Count the number of documents that an user has uploaded to a course

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

@@ 5263-5286 (lines=24) @@
5260
     * @param string $lastname Lastname to search
5261
     * @return array The user list
5262
     */
5263
    public static function getUserByName($firstname, $lastname)
5264
    {
5265
        $firstname = Database::escape_string($firstname);
5266
        $lastname = Database::escape_string($lastname);
5267
5268
        $userTable = Database::get_main_table(TABLE_MAIN_USER);
5269
5270
        $sql = <<<SQL
5271
            SELECT id, username, lastname, firstname
5272
            FROM $userTable
5273
            WHERE 
5274
                firstname LIKE '$firstname%' AND
5275
                lastname LIKE '$lastname%'
5276
SQL;
5277
5278
        $result = Database::query($sql);
5279
5280
        $users = [];
5281
        while ($resultData = Database::fetch_object($result)) {
5282
            $users[] = $resultData;
5283
        }
5284
5285
        return $users;
5286
    }
5287
5288
    /**
5289
     * @param int $optionSelected