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/inc/lib/agenda.lib.php 2 locations

@@ 2638-2659 (lines=22) @@
2635
     * @param array $courseInfo
2636
     * @return array with the post info
2637
     */
2638
    public function getAttachment($attachmentId, $eventId, $courseInfo)
2639
    {
2640
        $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
2641
        $courseId = intval($courseInfo['real_id']);
2642
        $eventId = intval($eventId);
2643
        $attachmentId = intval($attachmentId);
2644
2645
        $row = array();
2646
        $sql = "SELECT id, path, filename, comment
2647
                FROM $tableAttachment
2648
                WHERE
2649
                    c_id = $courseId AND
2650
                    agenda_id = $eventId AND
2651
                    id = $attachmentId
2652
                ";
2653
        $result = Database::query($sql);
2654
        if (Database::num_rows($result) != 0) {
2655
            $row = Database::fetch_array($result, 'ASSOC');
2656
        }
2657
2658
        return $row;
2659
    }
2660
2661
    /**
2662
     * Add an attachment file into agenda
@@ 2611-2629 (lines=19) @@
2608
     * @param array $courseInfo
2609
     * @return array with the post info
2610
     */
2611
    public function getAttachmentList($eventId, $courseInfo)
2612
    {
2613
        $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
2614
        $courseId = intval($courseInfo['real_id']);
2615
        $eventId = intval($eventId);
2616
2617
        $sql = "SELECT id, path, filename, comment
2618
                FROM $tableAttachment
2619
                WHERE
2620
                    c_id = $courseId AND
2621
                    agenda_id = $eventId";
2622
        $result = Database::query($sql);
2623
        $list = array();
2624
        if (Database::num_rows($result) != 0) {
2625
            $list = Database::store_result($result, 'ASSOC');
2626
        }
2627
2628
        return $list;
2629
    }
2630
2631
    /**
2632
     * Show a list with all the attachments according to the post's id

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

@@ 1237-1257 (lines=21) @@
1234
     * @param int    attendance id
1235
     * @return int attendance calendar id
1236
     */
1237
    public function get_next_attendance_calendar_id($attendance_id)
1238
    {
1239
        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1240
        $attendance_id = intval($attendance_id);
1241
        $course_id = api_get_course_int_id();
1242
1243
        $sql = "SELECT id FROM $table
1244
                WHERE
1245
                    c_id = $course_id AND
1246
                    attendance_id = '$attendance_id' AND
1247
                    done_attendance = 0
1248
                ORDER BY date_time
1249
                LIMIT 1";
1250
        $rs = Database::query($sql);
1251
        $next_calendar_id = 0;
1252
        if (Database::num_rows($rs) > 0) {
1253
            $row = Database::fetch_array($rs);
1254
            $next_calendar_id = $row['id'];
1255
        }
1256
1257
        return $next_calendar_id;
1258
    }
1259
1260
    /**
@@ 1265-1285 (lines=21) @@
1262
     * @param int    attendance id
1263
     * @return int UNIX time format datetime
1264
     */
1265
    public function get_next_attendance_calendar_datetime($attendance_id)
1266
    {
1267
        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1268
        $course_id = api_get_course_int_id();
1269
        $attendance_id = intval($attendance_id);
1270
        $sql = "SELECT id, date_time FROM $table
1271
                WHERE
1272
                    c_id = $course_id AND
1273
                    attendance_id = '$attendance_id' AND
1274
                    done_attendance = 0
1275
                ORDER BY date_time
1276
                LIMIT 1";
1277
        $rs = Database::query($sql);
1278
        $next_calendar_datetime = 0;
1279
        if (Database::num_rows($rs) > 0) {
1280
            $row = Database::fetch_array($rs);
1281
            $next_calendar_datetime = api_get_local_time($row['date_time']);
1282
        }
1283
1284
        return $next_calendar_datetime;
1285
    }
1286
1287
    /**
1288
     * Get user' score from current attendance
@@ 1340-1357 (lines=18) @@
1337
     * @param int    attendance calendar id
1338
     * @return array attendance calendar data
1339
     */
1340
    public function get_attendance_calendar_by_id($calendar_id)
1341
    {
1342
        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1343
        $calendar_id = intval($calendar_id);
1344
        $course_id = api_get_course_int_id();
1345
        $sql = "SELECT * FROM $table
1346
                WHERE c_id = $course_id AND id = '$calendar_id' ";
1347
        $rs = Database::query($sql);
1348
        $data = array();
1349
        if (Database::num_rows($rs) > 0) {
1350
            while ($row = Database::fetch_array($rs)) {
1351
                $row['date_time'] = api_get_local_time($row['date_time']);
1352
                $data = $row;
1353
            }
1354
        }
1355
1356
        return $data;
1357
    }
1358
1359
    /**
1360
     * Get all attendance calendar data inside current attendance
@@ 1554-1570 (lines=17) @@
1551
     * @param int $attendance_id
1552
     * @return int     count of dates
1553
     */
1554
    public static function get_count_dates_inside_attendance_calendar($attendance_id)
1555
    {
1556
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1557
        $attendance_id = intval($attendance_id);
1558
        $course_id = api_get_course_int_id();
1559
        $sql = "SELECT count(id) FROM $tbl_attendance_calendar
1560
                WHERE
1561
                    c_id = $course_id AND
1562
                    attendance_id = '$attendance_id'";
1563
        $rs = Database::query($sql);
1564
        $count = 0;
1565
        if (Database::num_rows($rs) > 0) {
1566
            $row = Database::fetch_row($rs);
1567
            $count = $row[0];
1568
        }
1569
        return $count;
1570
    }
1571
1572
    /**
1573
     * check if all calendar of an attendance is done

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

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

main/lp/learnpath.class.php 2 locations

@@ 2860-2875 (lines=16) @@
2857
     * @param   integer course id
2858
     * @return	integer	Number of interactions
2859
     */
2860
    public static function get_interactions_count_from_db($lp_iv_id, $course_id)
2861
    {
2862
        $table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
2863
        $lp_iv_id = intval($lp_iv_id);
2864
        $course_id = intval($course_id);
2865
2866
        $sql = "SELECT count(*) FROM $table
2867
                WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
2868
        $res = Database::query($sql);
2869
        $num = 0;
2870
        if (Database::num_rows($res)) {
2871
            $row = Database::fetch_array($res);
2872
            $num = $row[0];
2873
        }
2874
        return $num;
2875
    }
2876
2877
    /**
2878
     * Return the interactions as an array for the given lp_iv_id.
@@ 2934-2950 (lines=17) @@
2931
     * @param	integer	Item View ID
2932
     * @return	integer	Number of objectives
2933
     */
2934
    public static function get_objectives_count_from_db($lp_iv_id, $course_id)
2935
    {
2936
        $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
2937
        $course_id = intval($course_id);
2938
        $lp_iv_id = intval($lp_iv_id);
2939
        $sql = "SELECT count(*) FROM $table
2940
                WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
2941
        //@todo seems that this always returns 0
2942
        $res = Database::query($sql);
2943
        $num = 0;
2944
        if (Database::num_rows($res)) {
2945
            $row = Database::fetch_array($res);
2946
            $num = $row[0];
2947
        }
2948
2949
        return $num;
2950
    }
2951
2952
    /**
2953
     * Return the objectives as an array for the given lp_iv_id.