Code Duplication    Length = 15-22 lines in 11 locations

plugin/courselegal/CourseLegalPlugin.php 1 location

@@ 67-84 (lines=18) @@
64
     *
65
     * @return array
66
     */
67
    public function getUserAcceptedLegal($userId, $courseId, $sessionId)
68
    {
69
        $userId = intval($userId);
70
        $courseId = intval($courseId);
71
        $sessionId = intval($sessionId);
72
73
        $table = Database::get_main_table('session_rel_course_rel_user_legal');
74
        $sql = "SELECT *
75
                FROM $table
76
                WHERE user_id = $userId AND c_id = $courseId AND session_id = $sessionId";
77
        $result = Database::query($sql);
78
        $data = array();
79
        if (Database::num_rows($result) > 0) {
80
            $data = Database::fetch_array($result, 'ASSOC');
81
        }
82
83
        return $data;
84
    }
85
86
    /**
87
     * @param int $userId

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

@@ 327-341 (lines=15) @@
324
     *
325
     * @return array
326
     */
327
    public static function getChildren($categoryCode)
328
    {
329
        $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
330
        $categoryCode = Database::escape_string($categoryCode);
331
        $sql = "SELECT code, id FROM $tbl_category 
332
                WHERE parent_id = '$categoryCode'";
333
        $result = Database::query($sql);
334
        $children = [];
335
        while ($row = Database::fetch_array($result, 'ASSOC')) {
336
            $children[] = $row;
337
            $subChildren = self::getChildren($row['code']);
338
            $children = array_merge($children, $subChildren);
339
        }
340
341
        return $children;
342
    }
343
344
    /**

main/lp/learnpath.class.php 2 locations

@@ 2837-2852 (lines=16) @@
2834
     * @param   integer course id
2835
     * @return	integer	Number of interactions
2836
     */
2837
    public static function get_interactions_count_from_db($lp_iv_id, $course_id)
2838
    {
2839
        $table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
2840
        $lp_iv_id = intval($lp_iv_id);
2841
        $course_id = intval($course_id);
2842
2843
        $sql = "SELECT count(*) FROM $table
2844
                WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
2845
        $res = Database::query($sql);
2846
        $num = 0;
2847
        if (Database::num_rows($res)) {
2848
            $row = Database::fetch_array($res);
2849
            $num = $row[0];
2850
        }
2851
        return $num;
2852
    }
2853
2854
    /**
2855
     * Return the interactions as an array for the given lp_iv_id.
@@ 2911-2927 (lines=17) @@
2908
     * @param	integer	Item View ID
2909
     * @return	integer	Number of objectives
2910
     */
2911
    public static function get_objectives_count_from_db($lp_iv_id, $course_id)
2912
    {
2913
        $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
2914
        $course_id = intval($course_id);
2915
        $lp_iv_id = intval($lp_iv_id);
2916
        $sql = "SELECT count(*) FROM $table
2917
                WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
2918
        //@todo seems that this always returns 0
2919
        $res = Database::query($sql);
2920
        $num = 0;
2921
        if (Database::num_rows($res)) {
2922
            $row = Database::fetch_array($res);
2923
            $num = $row[0];
2924
        }
2925
2926
        return $num;
2927
    }
2928
2929
    /**
2930
     * Return the objectives as an array for the given lp_iv_id.

main/inc/lib/attendance.lib.php 4 locations

@@ 1221-1241 (lines=21) @@
1218
     * @param	int	attendance id
1219
     * @return 	int attendance calendar id
1220
     */
1221
    public function get_next_attendance_calendar_id($attendance_id)
1222
    {
1223
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1224
        $attendance_id = intval($attendance_id);
1225
        $course_id = api_get_course_int_id();
1226
1227
        $sql = "SELECT id FROM $tbl_attendance_calendar
1228
                WHERE
1229
                    c_id = $course_id AND
1230
                    attendance_id = '$attendance_id' AND
1231
                    done_attendance = 0
1232
                ORDER BY date_time
1233
                LIMIT 1";
1234
        $rs = Database::query($sql);
1235
        $next_calendar_id = 0;
1236
        if (Database::num_rows($rs) > 0) {
1237
            $row = Database::fetch_array($rs);
1238
            $next_calendar_id = $row['id'];
1239
        }
1240
1241
        return $next_calendar_id;
1242
    }
1243
1244
    /**
@@ 1249-1269 (lines=21) @@
1246
     * @param	int	attendance id
1247
     * @return 	int UNIX time format datetime
1248
     */
1249
    public function get_next_attendance_calendar_datetime($attendance_id)
1250
    {
1251
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1252
        $course_id = api_get_course_int_id();
1253
        $attendance_id = intval($attendance_id);
1254
        $sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1255
                WHERE
1256
                    c_id = $course_id AND
1257
                    attendance_id = '$attendance_id' AND
1258
                    done_attendance = 0
1259
                ORDER BY date_time
1260
                LIMIT 1";
1261
        $rs = Database::query($sql);
1262
        $next_calendar_datetime = 0;
1263
        if (Database::num_rows($rs) > 0) {
1264
            $row = Database::fetch_array($rs);
1265
            $next_calendar_datetime = api_get_local_time($row['date_time']);
1266
        }
1267
1268
        return $next_calendar_datetime;
1269
    }
1270
1271
    /**
1272
     * Get user' score from current attendance
@@ 1324-1341 (lines=18) @@
1321
     * @param	int	attendance calendar id
1322
     * @return	array attendance calendar data
1323
     */
1324
    public function get_attendance_calendar_by_id($calendar_id)
1325
    {
1326
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1327
        $calendar_id = intval($calendar_id);
1328
        $course_id = api_get_course_int_id();
1329
        $sql = "SELECT * FROM $tbl_attendance_calendar
1330
                WHERE c_id = $course_id AND id = '$calendar_id' ";
1331
        $rs = Database::query($sql);
1332
        $data = array();
1333
        if (Database::num_rows($rs) > 0) {
1334
            while ($row = Database::fetch_array($rs)) {
1335
                $row['date_time'] = api_get_local_time($row['date_time']);
1336
                $data = $row;
1337
            }
1338
        }
1339
1340
        return $data;
1341
    }
1342
1343
    /**
1344
     * Get all attendance calendar data inside current attendance
@@ 1534-1550 (lines=17) @@
1531
     * @param	int	$attendance_id
1532
     * @return	int     count of dates
1533
     */
1534
    public static function get_count_dates_inside_attendance_calendar($attendance_id)
1535
    {
1536
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1537
        $attendance_id = intval($attendance_id);
1538
        $course_id = api_get_course_int_id();
1539
        $sql = "SELECT count(id) FROM $tbl_attendance_calendar
1540
                WHERE
1541
                    c_id = $course_id AND
1542
                    attendance_id = '$attendance_id'";
1543
        $rs = Database::query($sql);
1544
        $count = 0;
1545
        if (Database::num_rows($rs) > 0) {
1546
            $row = Database::fetch_row($rs);
1547
            $count = $row[0];
1548
        }
1549
        return $count;
1550
    }
1551
1552
    /**
1553
     * check if all calendar of an attendance is done

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

@@ 2599-2620 (lines=22) @@
2596
     * @param array $courseInfo
2597
     * @return array with the post info
2598
     */
2599
    public function getAttachment($attachmentId, $eventId, $courseInfo)
2600
    {
2601
        $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
2602
        $courseId = intval($courseInfo['real_id']);
2603
        $eventId = intval($eventId);
2604
        $attachmentId = intval($attachmentId);
2605
2606
        $row = array();
2607
        $sql = "SELECT id, path, filename, comment
2608
                FROM $tableAttachment
2609
                WHERE
2610
                    c_id = $courseId AND
2611
                    agenda_id = $eventId AND
2612
                    id = $attachmentId
2613
                ";
2614
        $result = Database::query($sql);
2615
        if (Database::num_rows($result) != 0) {
2616
            $row = Database::fetch_array($result, 'ASSOC');
2617
        }
2618
2619
        return $row;
2620
    }
2621
2622
    /**
2623
     * Add an attachment file into agenda
@@ 2572-2590 (lines=19) @@
2569
     * @param array $courseInfo
2570
     * @return array with the post info
2571
     */
2572
    public function getAttachmentList($eventId, $courseInfo)
2573
    {
2574
        $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
2575
        $courseId = intval($courseInfo['real_id']);
2576
        $eventId = intval($eventId);
2577
2578
        $sql = "SELECT id, path, filename, comment
2579
                FROM $tableAttachment
2580
                WHERE
2581
                    c_id = $courseId AND
2582
                    agenda_id = $eventId";
2583
        $result = Database::query($sql);
2584
        $list = array();
2585
        if (Database::num_rows($result) != 0) {
2586
            $list = Database::store_result($result, 'ASSOC');
2587
        }
2588
2589
        return $list;
2590
    }
2591
2592
    /**
2593
     * Show a list with all the attachments according to the post's id

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

@@ 5311-5332 (lines=22) @@
5308
     * @param int $courseId
5309
     * @return array
5310
     */
5311
    public static function getCoachesByCourseSession($sessionId, $courseId)
5312
    {
5313
        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
5314
        $sessionId = intval($sessionId);
5315
        $courseId = intval($courseId);
5316
5317
        $sql = "SELECT user_id FROM $table
5318
                WHERE
5319
                    session_id = '$sessionId' AND
5320
                    c_id = '$courseId' AND
5321
                    status = 2";
5322
        $result = Database::query($sql);
5323
5324
        $coaches = array();
5325
        if (Database::num_rows($result) > 0) {
5326
            while ($row = Database::fetch_array($result)) {
5327
                $coaches[] = $row['user_id'];
5328
            }
5329
        }
5330
5331
        return $coaches;
5332
    }
5333
5334
    /**
5335
     * @param int $sessionId