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

@@ 2443-2458 (lines=16) @@
2440
 * @param int $user_id If none provided, will use current user
2441
 * @return int User's status (1 for teacher, 5 for student, etc)
2442
 */
2443
function api_get_user_status($user_id = null)
2444
{
2445
    $user_id = intval($user_id);
2446
    if (empty($user_id)) {
2447
        $user_id = api_get_user_id();
2448
    }
2449
    $table = Database::get_main_table(TABLE_MAIN_USER);
2450
    $sql = "SELECT status FROM $table WHERE user_id = $user_id ";
2451
    $result = Database::query($sql);
2452
    $status = null;
2453
    if (Database::num_rows($result)) {
2454
        $row = Database::fetch_array($result);
2455
        $status = $row['status'];
2456
    }
2457
    return $status;
2458
}
2459
2460
/**
2461
 * Checks whether current user is allowed to create courses