Code Duplication    Length = 15-28 lines in 13 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/agenda.lib.php 2 locations

@@ 2323-2344 (lines=22) @@
2320
     * @param array $courseInfo
2321
     * @return array with the post info
2322
     */
2323
    public function getAttachment($attachmentId, $eventId, $courseInfo)
2324
    {
2325
        $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
2326
        $courseId = intval($courseInfo['real_id']);
2327
        $eventId = intval($eventId);
2328
        $attachmentId = intval($attachmentId);
2329
2330
        $row = array();
2331
        $sql = "SELECT id, path, filename, comment
2332
                FROM $tableAttachment
2333
                WHERE
2334
                    c_id = $courseId AND
2335
                    agenda_id = $eventId AND
2336
                    id = $attachmentId
2337
                ";
2338
        $result = Database::query($sql);
2339
        if (Database::num_rows($result) != 0) {
2340
            $row = Database::fetch_array($result, 'ASSOC');
2341
        }
2342
2343
        return $row;
2344
    }
2345
2346
    /**
2347
     * Add an attachment file into agenda
@@ 2296-2314 (lines=19) @@
2293
     * @param array $courseInfo
2294
     * @return array with the post info
2295
     */
2296
    public function getAttachmentList($eventId, $courseInfo)
2297
    {
2298
        $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
2299
        $courseId = intval($courseInfo['real_id']);
2300
        $eventId = intval($eventId);
2301
2302
        $sql = "SELECT id, path, filename, comment
2303
                FROM $tableAttachment
2304
                WHERE
2305
                    c_id = $courseId AND
2306
                    agenda_id = $eventId";
2307
        $result = Database::query($sql);
2308
        $list = array();
2309
        if (Database::num_rows($result) != 0) {
2310
            $list = Database::store_result($result, 'ASSOC');
2311
        }
2312
2313
        return $list;
2314
    }
2315
2316
    /**
2317
     * Show a list with all the attachments according to the post's id

main/exercise/TestCategory.php 1 location

@@ 236-254 (lines=19) @@
233
     *
234
     * @return int
235
     */
236
    public static function getCategoryForQuestion($questionId, $courseId = 0)
237
    {
238
        if (empty($courseId)) {
239
            $courseId = api_get_course_int_id();
240
        }
241
        $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
242
        $questionId = intval($questionId);
243
        $sql = "SELECT category_id
244
                FROM $table
245
                WHERE question_id = $questionId AND c_id = $courseId";
246
        $res = Database::query($sql);
247
        $result = 0;
248
        if (Database::num_rows($res) > 0) {
249
            $data = Database::fetch_array($res);
250
            $result = $data['category_id'];
251
        }
252
253
        return $result;
254
    }
255
256
    /**
257
     * true if question id has a category

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

@@ 1203-1223 (lines=21) @@
1200
     * @param	int	attendance id
1201
     * @return 	int attendance calendar id
1202
     */
1203
    public function get_next_attendance_calendar_id($attendance_id)
1204
    {
1205
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1206
        $attendance_id = intval($attendance_id);
1207
        $course_id = api_get_course_int_id();
1208
1209
        $sql = "SELECT id FROM $tbl_attendance_calendar
1210
                WHERE
1211
                    c_id = $course_id AND
1212
                    attendance_id = '$attendance_id' AND
1213
                    done_attendance = 0
1214
                ORDER BY date_time
1215
                LIMIT 1";
1216
        $rs = Database::query($sql);
1217
        $next_calendar_id = 0;
1218
        if (Database::num_rows($rs) > 0) {
1219
            $row = Database::fetch_array($rs);
1220
            $next_calendar_id = $row['id'];
1221
        }
1222
1223
        return $next_calendar_id;
1224
    }
1225
1226
    /**
@@ 1231-1251 (lines=21) @@
1228
     * @param	int	attendance id
1229
     * @return 	int UNIX time format datetime
1230
     */
1231
    public function get_next_attendance_calendar_datetime($attendance_id)
1232
    {
1233
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1234
        $course_id = api_get_course_int_id();
1235
        $attendance_id = intval($attendance_id);
1236
        $sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1237
                WHERE
1238
                    c_id = $course_id AND
1239
                    attendance_id = '$attendance_id' AND
1240
                    done_attendance = 0
1241
                ORDER BY date_time
1242
                LIMIT 1";
1243
        $rs = Database::query($sql);
1244
        $next_calendar_datetime = 0;
1245
        if (Database::num_rows($rs) > 0) {
1246
            $row = Database::fetch_array($rs);
1247
            $next_calendar_datetime = api_get_local_time($row['date_time']);
1248
        }
1249
1250
        return $next_calendar_datetime;
1251
    }
1252
1253
    /**
1254
     * Get user' score from current attendance
@@ 1306-1323 (lines=18) @@
1303
     * @param	int	attendance calendar id
1304
     * @return	array attendance calendar data
1305
     */
1306
    public function get_attendance_calendar_by_id($calendar_id)
1307
    {
1308
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1309
        $calendar_id = intval($calendar_id);
1310
        $course_id = api_get_course_int_id();
1311
        $sql = "SELECT * FROM $tbl_attendance_calendar
1312
                WHERE c_id = $course_id AND id = '$calendar_id' ";
1313
        $rs = Database::query($sql);
1314
        $data = array();
1315
        if (Database::num_rows($rs) > 0) {
1316
            while ($row = Database::fetch_array($rs)) {
1317
                $row['date_time'] = api_get_local_time($row['date_time']);
1318
                $data = $row;
1319
            }
1320
        }
1321
1322
        return $data;
1323
    }
1324
1325
    /**
1326
     * Get all attendance calendar data inside current attendance
@@ 1517-1533 (lines=17) @@
1514
     * @param	int	$attendance_id
1515
     * @return	int     count of dates
1516
     */
1517
    public static function get_count_dates_inside_attendance_calendar($attendance_id)
1518
    {
1519
        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1520
        $attendance_id = intval($attendance_id);
1521
        $course_id = api_get_course_int_id();
1522
        $sql = "SELECT count(id) FROM $tbl_attendance_calendar
1523
                WHERE
1524
                    c_id = $course_id AND
1525
                    attendance_id = '$attendance_id'";
1526
        $rs = Database::query($sql);
1527
        $count = 0;
1528
        if (Database::num_rows($rs) > 0) {
1529
            $row = Database::fetch_row($rs);
1530
            $count = $row[0];
1531
        }
1532
        return $count;
1533
    }
1534
1535
    /**
1536
     * check if all calendar of an attendance is done

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

@@ 1494-1521 (lines=28) @@
1491
     *
1492
     * @return array
1493
     */
1494
    public static function getLatestHotPotatoResult(
1495
        $exercisePath,
1496
        $userId,
1497
        $courseId,
1498
        $sessionId
1499
    )
1500
    {
1501
        $table = Database:: get_main_table(
1502
            TABLE_STATISTIC_TRACK_E_HOTPOTATOES
1503
        );
1504
1505
        $courseInfo = api_get_course_info_by_id($courseId);
1506
        $exercisePath = Database::escape_string($exercisePath);
1507
        $userId = intval($userId);
1508
1509
        $sql = "SELECT * FROM $table
1510
            WHERE
1511
                c_id = $courseId AND
1512
                exe_name LIKE '$exercisePath%' AND
1513
                exe_user_id = $userId
1514
            ORDER BY id
1515
            LIMIT 1";
1516
        $result = Database::query($sql);
1517
        $attempt = array();
1518
        if (Database::num_rows($result)) {
1519
            $attempt = Database::fetch_array($result, 'ASSOC');
1520
        }
1521
        return $attempt;
1522
    }
1523
1524
    /**

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

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

main/lp/learnpath.class.php 2 locations

@@ 2816-2831 (lines=16) @@
2813
     * @param   integer course id
2814
     * @return	integer	Number of interactions
2815
     */
2816
    public static function get_interactions_count_from_db($lp_iv_id, $course_id)
2817
    {
2818
        $table = Database :: get_course_table(TABLE_LP_IV_INTERACTION);
2819
        $lp_iv_id = intval($lp_iv_id);
2820
        $course_id = intval($course_id);
2821
2822
        $sql = "SELECT count(*) FROM $table
2823
                WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
2824
        $res = Database::query($sql);
2825
        $num = 0;
2826
        if (Database::num_rows($res)) {
2827
            $row = Database::fetch_array($res);
2828
            $num = $row[0];
2829
        }
2830
        return $num;
2831
    }
2832
2833
    /**
2834
     * Return the interactions as an array for the given lp_iv_id.
@@ 2890-2906 (lines=17) @@
2887
     * @param	integer	Item View ID
2888
     * @return	integer	Number of objectives
2889
     */
2890
    public static function get_objectives_count_from_db($lp_iv_id, $course_id)
2891
    {
2892
        $table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
2893
        $course_id = intval($course_id);
2894
        $lp_iv_id = intval($lp_iv_id);
2895
        $sql = "SELECT count(*) FROM $table
2896
                WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
2897
        //@todo seems that this always returns 0
2898
        $res = Database::query($sql);
2899
        $num = 0;
2900
        if (Database::num_rows($res)) {
2901
            $row = Database :: fetch_array($res);
2902
            $num = $row[0];
2903
        }
2904
2905
        return $num;
2906
    }
2907
2908
    /**
2909
     * Return the objectives as an array for the given lp_iv_id.

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

@@ 5016-5037 (lines=22) @@
5013
     * @param int $courseId
5014
     * @return array
5015
     */
5016
    public static function getCoachesByCourseSession($sessionId, $courseId)
5017
    {
5018
        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
5019
        $sessionId = intval($sessionId);
5020
        $courseId = intval($courseId);
5021
5022
        $sql = "SELECT user_id FROM $table
5023
                WHERE
5024
                    session_id = '$sessionId' AND
5025
                    c_id = '$courseId' AND
5026
                    status = 2";
5027
        $result = Database::query($sql);
5028
5029
        $coaches = array();
5030
        if (Database::num_rows($result) > 0) {
5031
            while ($row = Database::fetch_row($result)) {
5032
                $coaches[] = $row[0];
5033
            }
5034
        }
5035
5036
        return $coaches;
5037
    }
5038
5039
    /**
5040
     * @param int $sessionId