Code Duplication    Length = 16-20 lines in 3 locations

main/work/work.lib.php 2 locations

@@ 126-145 (lines=20) @@
123
 *
124
 * @return array
125
 */
126
function get_work_data_by_path($path, $courseId = null)
127
{
128
    $path = Database::escape_string($path);
129
    if (empty($courseId)) {
130
        $courseId = api_get_course_int_id();
131
    } else {
132
        $courseId = intval($courseId);
133
    }
134
135
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
136
    $sql = "SELECT *  FROM  ".$work_table."
137
            WHERE url = '$path' AND c_id = $courseId ";
138
    $result = Database::query($sql);
139
    $return = array();
140
    if (Database::num_rows($result)) {
141
        $return = Database::fetch_array($result, 'ASSOC');
142
    }
143
144
    return $return;
145
}
146
147
/**
148
 * @param int $id
@@ 238-257 (lines=20) @@
235
 *
236
 * @return array
237
 */
238
function get_work_assignment_by_id($id, $courseId = null)
239
{
240
    if (empty($courseId)) {
241
        $courseId = api_get_course_int_id();
242
    } else {
243
        $courseId = intval($courseId);
244
    }
245
    $id = intval($id);
246
247
    $table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
248
    $sql = "SELECT * FROM $table
249
            WHERE c_id = $courseId AND publication_id = $id";
250
    $result = Database::query($sql);
251
    $return = array();
252
    if (Database::num_rows($result)) {
253
        $return = Database::fetch_array($result, 'ASSOC');
254
    }
255
256
    return $return;
257
}
258
259
/**
260
 * @param int $id

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

@@ 2478-2493 (lines=16) @@
2475
 * @param int $user_id If none provided, will use current user
2476
 * @return int User's status (1 for teacher, 5 for student, etc)
2477
 */
2478
function api_get_user_status($user_id = null)
2479
{
2480
    $user_id = intval($user_id);
2481
    if (empty($user_id)) {
2482
        $user_id = api_get_user_id();
2483
    }
2484
    $table = Database::get_main_table(TABLE_MAIN_USER);
2485
    $sql = "SELECT status FROM $table WHERE user_id = $user_id ";
2486
    $result = Database::query($sql);
2487
    $status = null;
2488
    if (Database::num_rows($result)) {
2489
        $row = Database::fetch_array($result);
2490
        $status = $row['status'];
2491
    }
2492
    return $status;
2493
}
2494
2495
/**
2496
 * Checks whether current user is allowed to create courses