Code Duplication    Length = 16-22 lines in 5 locations

main/work/work.lib.php 2 locations

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

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

@@ 4695-4716 (lines=22) @@
4692
     * @return bool    True if the user is a coach
4693
     *
4694
     */
4695
    public static function is_session_course_coach($user_id, $courseId, $session_id)
4696
    {
4697
        $tbl_session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
4698
        // Protect data
4699
        $user_id = intval($user_id);
4700
        $courseId = intval($courseId);
4701
        $session_id = intval($session_id);
4702
        $result = false;
4703
4704
        $sql = "SELECT session_id FROM $tbl_session_course_rel_user
4705
                WHERE
4706
                  session_id = $session_id AND
4707
                  c_id = $courseId AND
4708
                  user_id = $user_id AND
4709
                  status = 2 ";
4710
        $res = Database::query($sql);
4711
4712
        if (Database::num_rows($res) > 0) {
4713
            $result = true;
4714
        }
4715
        return $result;
4716
    }
4717
4718
    /**
4719
     * This function returns an icon path that represents the favicon of the website of which the url given.

main/inc/lib/api.lib.php 2 locations

@@ 2520-2535 (lines=16) @@
2517
 * @param int $user_id If none provided, will use current user
2518
 * @return int User's status (1 for teacher, 5 for student, etc)
2519
 */
2520
function api_get_user_status($user_id = null)
2521
{
2522
    $user_id = intval($user_id);
2523
    if (empty($user_id)) {
2524
        $user_id = api_get_user_id();
2525
    }
2526
    $table = Database::get_main_table(TABLE_MAIN_USER);
2527
    $sql = "SELECT status FROM $table WHERE user_id = $user_id ";
2528
    $result = Database::query($sql);
2529
    $status = null;
2530
    if (Database::num_rows($result)) {
2531
        $row = Database::fetch_array($result);
2532
        $status = $row['status'];
2533
    }
2534
    return $status;
2535
}
2536
2537
/**
2538
 * Checks whether current user is allowed to create courses
@@ 4009-4026 (lines=18) @@
4006
 * @param int $ref
4007
 * @return array|resource
4008
 */
4009
function api_get_track_item_property_history($tool, $ref)
4010
{
4011
    $tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
4012
    $course_id = api_get_course_int_id(); //numeric
4013
    $course_code = api_get_course_id(); //alphanumeric
4014
    $item_property_id = api_get_item_property_id($course_code, $tool, $ref);
4015
    $sql = "SELECT * FROM $tbl_stats_item_property
4016
            WHERE item_property_id = $item_property_id AND course_id = $course_id
4017
            ORDER BY lastedit_date DESC";
4018
    $result = Database::query($sql);
4019
    if ($result == false) {
4020
        $result = array();
4021
    } else {
4022
        $result = Database::store_result($result,'ASSOC');
4023
    }
4024
4025
    return $result;
4026
}
4027
4028
/**
4029
 * Gets item property data from tool of a course id