Code Duplication    Length = 15-28 lines in 26 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/specific_fields_manager.lib.php 1 location

@@ 151-176 (lines=26) @@
148
 * @param int $ref_id representative id inside one tool item
149
 * @return array
150
 */
151
function get_specific_field_values_list_by_prefix(
152
    $prefix,
153
    $course_code,
154
    $tool_id,
155
    $ref_id
156
) {
157
    $table_sf = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
158
    $table_sfv = Database:: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
159
    $sql = 'SELECT sfv.value FROM %s sf LEFT JOIN %s sfv ON sf.id = sfv.field_id'.
160
        ' WHERE sf.code = \'%s\' AND sfv.c_id = \'%s\' AND tool_id = \'%s\' AND sfv.ref_id = %s';
161
    $sql = sprintf(
162
        $sql,
163
        $table_sf,
164
        $table_sfv,
165
        $prefix,
166
        $course_code,
167
        $tool_id,
168
        $ref_id
169
    );
170
    $sql_result = Database::query($sql);
171
    while ($result = Database::fetch_array($sql_result)) {
172
        $return_array[] = $result;
173
    }
174
175
    return $return_array;
176
}
177
178
/**
179
 * Add a specific field value

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

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

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

@@ 24-41 (lines=18) @@
21
     * @author Isaac Flores <[email protected]>
22
     * @return array Contain glossary terms
23
     */
24
    public static function get_glossary_terms()
25
    {
26
        $glossary_data  = array();
27
        $glossary_table = Database::get_course_table(TABLE_GLOSSARY);
28
        $session_id = api_get_session_id();
29
        $sql_filter = api_get_session_condition($session_id);
30
        $course_id = api_get_course_int_id();
31
32
        $sql = "SELECT glossary_id as id, name, description
33
		        FROM $glossary_table
34
		        WHERE c_id = $course_id $sql_filter";
35
        $rs = Database::query($sql);
36
        while ($row = Database::fetch_array($rs)) {
37
            $glossary_data[] = $row;
38
        }
39
40
        return $glossary_data;
41
    }
42
43
    /**
44
     * Get glossary term by glossary id

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

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

main/inc/lib/groupmanager.lib.php 3 locations

@@ 1104-1124 (lines=21) @@
1101
     * @param int $group_id iid
1102
     * @return array
1103
     */
1104
    public static function getTutors($group_id)
1105
    {
1106
        $groupTable = Database :: get_course_table(TABLE_GROUP);
1107
        $tutor_user_table = Database :: get_course_table(TABLE_GROUP_TUTOR);
1108
        $course_id = api_get_course_int_id();
1109
        $group_id = intval($group_id);
1110
1111
        $sql = "SELECT user_id 
1112
                FROM $tutor_user_table gu
1113
                INNER JOIN $groupTable g
1114
                ON (gu.group_id = g.id and g.c_id = gu.c_id)
1115
                WHERE gu.c_id = $course_id AND g.id = $group_id";
1116
        $res = Database::query($sql);
1117
1118
        $users = array();
1119
        while ($obj = Database::fetch_object($res)) {
1120
            $users[] = api_get_user_info($obj->user_id);
1121
        }
1122
1123
        return $users;
1124
    }
1125
1126
    /**
1127
     * Get only students from a group (not tutors)
@@ 1164-1181 (lines=18) @@
1161
     * @param array $groups list of group ids
1162
     * @return array list of user ids
1163
     */
1164
    public static function get_groups_users($groups = array())
1165
    {
1166
        $result = array();
1167
        $tbl_group_user = Database::get_course_table(TABLE_GROUP_USER);
1168
        $course_id = api_get_course_int_id();
1169
1170
        $groups = array_map('intval', $groups);
1171
        // protect individual elements with surrounding quotes
1172
        $groups = implode(', ', $groups);
1173
        $sql = "SELECT DISTINCT user_id
1174
                FROM $tbl_group_user gu
1175
                WHERE c_id = $course_id AND gu.group_id IN ($groups)";
1176
        $rs = Database::query($sql);
1177
        while ($row = Database::fetch_array($rs)) {
1178
            $result[] = $row['user_id'];
1179
        }
1180
1181
        return $result;
1182
    }
1183
1184
    /**
@@ 2004-2023 (lines=20) @@
2001
     * @param int $user_id
2002
     * @return array
2003
     */
2004
    public static function get_user_group_name($user_id)
2005
    {
2006
        $table_group_user = Database::get_course_table(TABLE_GROUP_USER);
2007
        $table_group = Database::get_course_table(TABLE_GROUP);
2008
        $user_id = intval($user_id);
2009
        $course_id = api_get_course_int_id();
2010
        $sql = "SELECT name
2011
                FROM $table_group g 
2012
                INNER JOIN $table_group_user gu
2013
                ON (gu.group_id = g.iid)
2014
                WHERE
2015
                  gu.c_id= $course_id AND
2016
                  g.c_id= $course_id AND
2017
                  gu.user_id = $user_id";
2018
        $res = Database::query($sql);
2019
        $groups = array();
2020
        while ($group = Database::fetch_array($res)) {
2021
            $groups[] .= $group['name'];
2022
        }
2023
        return $groups;
2024
    }
2025
2026
    /**

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

@@ 5346-5368 (lines=23) @@
5343
     * @param string $endDate
5344
     * @return array
5345
     */
5346
    public static function getCourseAccessPerCourseAndSession(
5347
        $courseId,
5348
        $sessionId,
5349
        $startDate,
5350
        $endDate
5351
    ) {
5352
        $table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
5353
        $courseId = intval($courseId);
5354
        $sessionId = intval($sessionId);
5355
        $startDate = Database::escape_string($startDate);
5356
        $endDate = Database::escape_string($endDate);
5357
5358
        $sql = "SELECT * FROM $table
5359
                WHERE
5360
                    c_id = $courseId AND
5361
                    session_id = $sessionId AND
5362
                    login_course_date BETWEEN '$startDate' AND '$endDate'
5363
                ";
5364
5365
        $result = Database::query($sql);
5366
5367
        return Database::store_result($result);
5368
    }
5369
5370
    /**
5371
     * Get login information from the track_e_course_access table, for any
@@ 5377-5394 (lines=18) @@
5374
     * @param int $userId
5375
     * @return array
5376
     */
5377
    public static function getFirstCourseAccessPerSessionAndUser($sessionId, $userId)
5378
    {
5379
        $sessionId = intval($sessionId);
5380
        $userId = intval($userId);
5381
5382
        $table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
5383
        $sql = "SELECT * FROM $table
5384
                WHERE session_id = $sessionId AND user_id = $userId
5385
                ORDER BY login_course_date ASC
5386
                LIMIT 1";
5387
5388
        $result = Database::query($sql);
5389
        $courseAccess = array();
5390
        if (Database::num_rows($result)) {
5391
            $courseAccess = Database::fetch_array($result, 'ASSOC');
5392
        }
5393
        return $courseAccess;
5394
    }
5395
5396
    /**
5397
     * @param int $courseId

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

@@ 6173-6193 (lines=21) @@
6170
     *
6171
     * @return array
6172
     */
6173
    public static function getDeletedDocuments($courseInfo, $sessionId = 0)
6174
    {
6175
        $table = Database::get_course_table(TABLE_DOCUMENT);
6176
        $courseId = $courseInfo['real_id'];
6177
        $sessionCondition = api_get_session_condition($sessionId);
6178
        $sql = "SELECT * FROM $table
6179
                WHERE
6180
                  path LIKE '%DELETED%' AND
6181
                  c_id = $courseId
6182
                  $sessionCondition
6183
                ORDER BY path
6184
        ";
6185
6186
        $result = Database::query($sql);
6187
        $files = array();
6188
        while ($document = Database::fetch_array($result, 'ASSOC')) {
6189
            $files[] = $document;
6190
        }
6191
6192
        return $files;
6193
    }
6194
6195
    /**
6196
     * @param int $id

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

@@ 1522-1547 (lines=26) @@
1519
     * @param int $session_id
1520
     * @return mixed
1521
     */
1522
    public static function count_exercise_result_not_validated($exercise_id, $courseId, $session_id = 0)
1523
    {
1524
        $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
1525
        $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
1526
        $courseId = intval($courseId);
1527
        $session_id = intval($session_id);
1528
        $exercise_id = intval($exercise_id);
1529
1530
        $sql = "SELECT count(e.exe_id) as count
1531
                FROM $table_track_exercises e
1532
                LEFT JOIN $table_track_attempt a
1533
                ON e.exe_id = a.exe_id
1534
                WHERE
1535
                    exe_exo_id = $exercise_id AND
1536
                    c_id = '$courseId' AND
1537
                    e.session_id = $session_id  AND
1538
                    orig_lp_id = 0 AND
1539
                    marks IS NULL AND
1540
                    status = '' AND
1541
                    orig_lp_item_id = 0
1542
                ORDER BY e.exe_id";
1543
        $res = Database::query($sql);
1544
        $row = Database::fetch_array($res, 'ASSOC');
1545
1546
        return $row['count'];
1547
    }
1548
1549
    /**
1550
     * Gets all exercise BEST results attempts (NO Exercises in LPs) from a given exercise id, course, session per user
@@ 1673-1689 (lines=17) @@
1670
     *
1671
     * @return array
1672
     */
1673
    public static function getAllExerciseEventByExeId($exe_id)
1674
    {
1675
        $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
1676
        $exe_id = intval($exe_id);
1677
        $list = array();
1678
1679
        $sql = "SELECT * FROM $table_track_attempt
1680
                WHERE exe_id = $exe_id
1681
                ORDER BY position";
1682
        $res_question = Database::query($sql);
1683
        if (Database::num_rows($res_question)) {
1684
            while ($row = Database::fetch_array($res_question, 'ASSOC')) {
1685
                $list[$row['question_id']][] = $row;
1686
            }
1687
        }
1688
        return $list;
1689
    }
1690
1691
    /**
1692
     *

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

@@ 2654-2675 (lines=22) @@
2651
     * @param array $courseInfo
2652
     * @return array with the post info
2653
     */
2654
    public function getAttachment($attachmentId, $eventId, $courseInfo)
2655
    {
2656
        $tableAttachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
2657
        $courseId = intval($courseInfo['real_id']);
2658
        $eventId = intval($eventId);
2659
        $attachmentId = intval($attachmentId);
2660
2661
        $row = array();
2662
        $sql = "SELECT id, path, filename, comment
2663
                FROM $tableAttachment
2664
                WHERE
2665
                    c_id = $courseId AND
2666
                    agenda_id = $eventId AND
2667
                    id = $attachmentId
2668
                ";
2669
        $result = Database::query($sql);
2670
        if (Database::num_rows($result) != 0) {
2671
            $row = Database::fetch_array($result, 'ASSOC');
2672
        }
2673
2674
        return $row;
2675
    }
2676
2677
    /**
2678
     * Add an attachment file into agenda

main/exercise/TestCategory.php 1 location

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

main/lp/learnpath.class.php 2 locations

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

main/exercise/exercise.class.php 2 locations

@@ 6409-6426 (lines=18) @@
6406
        return $question_count;
6407
    }
6408
6409
    function get_exercise_list_ordered()
6410
    {
6411
        $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER);
6412
        $course_id = api_get_course_int_id();
6413
        $session_id = api_get_session_id();
6414
        $sql = "SELECT exercise_id, exercise_order
6415
                FROM $table_exercise_order
6416
                WHERE c_id = $course_id AND session_id = $session_id
6417
                ORDER BY exercise_order";
6418
        $result = Database::query($sql);
6419
        $list = array();
6420
        if (Database::num_rows($result)) {
6421
            while ($row = Database::fetch_array($result, 'ASSOC')) {
6422
                $list[$row['exercise_order']] = $row['exercise_id'];
6423
            }
6424
        }
6425
        return $list;
6426
    }
6427
6428
    /**
6429
     * Get categories added in the exercise--category matrix
@@ 8315-8337 (lines=23) @@
8312
     * @param int $sessionId
8313
     * @return array exercises
8314
     */
8315
    public function getExercisesByCouseSession($courseId, $sessionId)
8316
    {
8317
        $courseId = intval($courseId);
8318
        $sessionId = intval($sessionId);
8319
8320
        $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
8321
        $sql = "SELECT * FROM $tbl_quiz cq
8322
                WHERE
8323
                    cq.c_id = %s AND
8324
                    (cq.session_id = %s OR cq.session_id = 0) AND
8325
                    cq.active = 0
8326
                ORDER BY cq.id";
8327
        $sql = sprintf($sql, $courseId, $sessionId);
8328
8329
        $result = Database::query($sql);
8330
8331
        $rows = array();
8332
        while ($row = Database::fetch_array($result, 'ASSOC')) {
8333
            $rows[] = $row;
8334
        }
8335
8336
        return $rows;
8337
    }
8338
8339
    /**
8340
     *

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

@@ 5100-5121 (lines=22) @@
5097
     * @param int $courseId
5098
     * @return array
5099
     */
5100
    public static function getCoachesByCourseSession($sessionId, $courseId)
5101
    {
5102
        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
5103
        $sessionId = intval($sessionId);
5104
        $courseId = intval($courseId);
5105
5106
        $sql = "SELECT user_id FROM $table
5107
                WHERE
5108
                    session_id = '$sessionId' AND
5109
                    c_id = '$courseId' AND
5110
                    status = 2";
5111
        $result = Database::query($sql);
5112
5113
        $coaches = array();
5114
        if (Database::num_rows($result) > 0) {
5115
            while ($row = Database::fetch_row($result)) {
5116
                $coaches[] = $row['user_id'];
5117
            }
5118
        }
5119
5120
        return $coaches;
5121
    }
5122
5123
    /**
5124
     * @param int $sessionId
@@ 5794-5812 (lines=19) @@
5791
     * @param int $sessionId
5792
     * @param int $courseId
5793
     */
5794
    public static function addCourseIntroduction($sessionId, $courseId)
5795
    {
5796
        // @todo create a tool intro lib
5797
        $sessionId = intval($sessionId);
5798
        $courseId = intval($courseId);
5799
5800
        $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
5801
        $sql = "SELECT * FROM $TBL_INTRODUCTION WHERE c_id = $courseId";
5802
        $result = Database::query($sql);
5803
        $result = Database::store_result($result, 'ASSOC');
5804
5805
        if (!empty($result)) {
5806
            foreach ($result as $result) {
5807
                // @todo check if relation exits.
5808
                $result['session_id'] = $sessionId;
5809
                Database::insert($TBL_INTRODUCTION, $result);
5810
            }
5811
        }
5812
    }
5813
5814
    /**
5815
     * @param int $sessionId