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

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

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/inc/lib/sessionmanager.lib.php 1 location

@@ 5037-5058 (lines=22) @@
5034
     * @param int $courseId
5035
     * @return array
5036
     */
5037
    public static function getCoachesByCourseSession($sessionId, $courseId)
5038
    {
5039
        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
5040
        $sessionId = intval($sessionId);
5041
        $courseId = intval($courseId);
5042
5043
        $sql = "SELECT user_id FROM $table
5044
                WHERE
5045
                    session_id = '$sessionId' AND
5046
                    c_id = '$courseId' AND
5047
                    status = 2";
5048
        $result = Database::query($sql);
5049
5050
        $coaches = array();
5051
        if (Database::num_rows($result) > 0) {
5052
            while ($row = Database::fetch_row($result)) {
5053
                $coaches[] = $row[0];
5054
            }
5055
        }
5056
5057
        return $coaches;
5058
    }
5059
5060
    /**
5061
     * @param int $sessionId

main/lp/learnpath.class.php 2 locations

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