Code Duplication    Length = 16-20 lines in 3 locations

main/work/work.lib.php 2 locations

@@ 185-204 (lines=20) @@
182
 *
183
 * @return array
184
 */
185
function get_work_data_by_path($path, $courseId = null)
186
{
187
    $path = Database::escape_string($path);
188
    if (empty($courseId)) {
189
        $courseId = api_get_course_int_id();
190
    } else {
191
        $courseId = intval($courseId);
192
    }
193
194
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
195
    $sql = "SELECT *  FROM  ".$work_table."
196
            WHERE url = '$path' AND c_id = $courseId ";
197
    $result = Database::query($sql);
198
    $return = array();
199
    if (Database::num_rows($result)) {
200
        $return = Database::fetch_array($result, 'ASSOC');
201
    }
202
203
    return $return;
204
}
205
206
/**
207
 * @param int $id
@@ 296-315 (lines=20) @@
293
 *
294
 * @return array
295
 */
296
function get_work_assignment_by_id($id, $courseId = null)
297
{
298
    if (empty($courseId)) {
299
        $courseId = api_get_course_int_id();
300
    } else {
301
        $courseId = intval($courseId);
302
    }
303
    $id = intval($id);
304
305
    $table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
306
    $sql = "SELECT * FROM $table
307
            WHERE c_id = $courseId AND publication_id = $id";
308
    $result = Database::query($sql);
309
    $return = array();
310
    if (Database::num_rows($result)) {
311
        $return = Database::fetch_array($result, 'ASSOC');
312
    }
313
314
    return $return;
315
}
316
317
/**
318
 * @param int $id

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

@@ 2454-2469 (lines=16) @@
2451
 * @param int $user_id. If none provided, will use current user
2452
 * @result int User's status (1 for teacher, 5 for student, etc)
2453
 */
2454
function api_get_user_status($user_id = null)
2455
{
2456
    $user_id = intval($user_id);
2457
    if (empty($user_id)) {
2458
        $user_id = api_get_user_id();
2459
    }
2460
    $table = Database::get_main_table(TABLE_MAIN_USER);
2461
    $sql = "SELECT status FROM $table WHERE user_id = $user_id ";
2462
    $result = Database::query($sql);
2463
    $status = null;
2464
    if (Database::num_rows($result)) {
2465
        $row = Database::fetch_array($result);
2466
        $status = $row['status'];
2467
    }
2468
    return $status;
2469
}
2470
2471
/**
2472
 * Checks whether current user is allowed to create courses