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
@@ 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/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/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/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_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/lp/learnpath.class.php 2 locations

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

@@ 5329-5351 (lines=23) @@
5326
     * @param string $endDate
5327
     * @return array
5328
     */
5329
    public static function getCourseAccessPerCourseAndSession(
5330
        $courseId,
5331
        $sessionId,
5332
        $startDate,
5333
        $endDate
5334
    ) {
5335
        $table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
5336
        $courseId = intval($courseId);
5337
        $sessionId = intval($sessionId);
5338
        $startDate = Database::escape_string($startDate);
5339
        $endDate = Database::escape_string($endDate);
5340
5341
        $sql = "SELECT * FROM $table
5342
                WHERE
5343
                    c_id = $courseId AND
5344
                    session_id = $sessionId AND
5345
                    login_course_date BETWEEN '$startDate' AND '$endDate'
5346
                ";
5347
5348
        $result = Database::query($sql);
5349
5350
        return Database::store_result($result);
5351
    }
5352
5353
    /**
5354
     * Get login information from the track_e_course_access table, for any
@@ 5360-5377 (lines=18) @@
5357
     * @param int $userId
5358
     * @return array
5359
     */
5360
    public static function getFirstCourseAccessPerSessionAndUser($sessionId, $userId)
5361
    {
5362
        $sessionId = intval($sessionId);
5363
        $userId = intval($userId);
5364
5365
        $table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
5366
        $sql = "SELECT * FROM $table
5367
                WHERE session_id = $sessionId AND user_id = $userId
5368
                ORDER BY login_course_date ASC
5369
                LIMIT 1";
5370
5371
        $result = Database::query($sql);
5372
        $courseAccess = array();
5373
        if (Database::num_rows($result)) {
5374
            $courseAccess = Database::fetch_array($result, 'ASSOC');
5375
        }
5376
        return $courseAccess;
5377
    }
5378
5379
    /**
5380
     * @param int $courseId

main/exercise/exercise.class.php 2 locations

@@ 6383-6400 (lines=18) @@
6380
        return $question_count;
6381
    }
6382
6383
    function get_exercise_list_ordered()
6384
    {
6385
        $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER);
6386
        $course_id = api_get_course_int_id();
6387
        $session_id = api_get_session_id();
6388
        $sql = "SELECT exercise_id, exercise_order
6389
                FROM $table_exercise_order
6390
                WHERE c_id = $course_id AND session_id = $session_id
6391
                ORDER BY exercise_order";
6392
        $result = Database::query($sql);
6393
        $list = array();
6394
        if (Database::num_rows($result)) {
6395
            while ($row = Database::fetch_array($result, 'ASSOC')) {
6396
                $list[$row['exercise_order']] = $row['exercise_id'];
6397
            }
6398
        }
6399
        return $list;
6400
    }
6401
6402
    /**
6403
     * Get categories added in the exercise--category matrix
@@ 8284-8306 (lines=23) @@
8281
     * @param int $sessionId
8282
     * @return array exercises
8283
     */
8284
    public function getExercisesByCouseSession($courseId, $sessionId)
8285
    {
8286
        $courseId = intval($courseId);
8287
        $sessionId = intval($sessionId);
8288
8289
        $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
8290
        $sql = "SELECT * FROM $tbl_quiz cq
8291
                WHERE
8292
                    cq.c_id = %s AND
8293
                    (cq.session_id = %s OR cq.session_id = 0) AND
8294
                    cq.active = 0
8295
                ORDER BY cq.id";
8296
        $sql = sprintf($sql, $courseId, $sessionId);
8297
8298
        $result = Database::query($sql);
8299
8300
        $rows = array();
8301
        while ($row = Database::fetch_array($result, 'ASSOC')) {
8302
            $rows[] = $row;
8303
        }
8304
8305
        return $rows;
8306
    }
8307
8308
    /**
8309
     *

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

@@ 5081-5102 (lines=22) @@
5078
     * @param int $courseId
5079
     * @return array
5080
     */
5081
    public static function getCoachesByCourseSession($sessionId, $courseId)
5082
    {
5083
        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
5084
        $sessionId = intval($sessionId);
5085
        $courseId = intval($courseId);
5086
5087
        $sql = "SELECT user_id FROM $table
5088
                WHERE
5089
                    session_id = '$sessionId' AND
5090
                    c_id = '$courseId' AND
5091
                    status = 2";
5092
        $result = Database::query($sql);
5093
5094
        $coaches = array();
5095
        if (Database::num_rows($result) > 0) {
5096
            while ($row = Database::fetch_row($result)) {
5097
                $coaches[] = $row['user_id'];
5098
            }
5099
        }
5100
5101
        return $coaches;
5102
    }
5103
5104
    /**
5105
     * @param int $sessionId
@@ 5775-5793 (lines=19) @@
5772
     * @param int $sessionId
5773
     * @param int $courseId
5774
     */
5775
    public static function addCourseIntroduction($sessionId, $courseId)
5776
    {
5777
        // @todo create a tool intro lib
5778
        $sessionId = intval($sessionId);
5779
        $courseId = intval($courseId);
5780
5781
        $TBL_INTRODUCTION = Database::get_course_table(TABLE_TOOL_INTRO);
5782
        $sql = "SELECT * FROM $TBL_INTRODUCTION WHERE c_id = $courseId";
5783
        $result = Database::query($sql);
5784
        $result = Database::store_result($result, 'ASSOC');
5785
5786
        if (!empty($result)) {
5787
            foreach ($result as $result) {
5788
                // @todo check if relation exits.
5789
                $result['session_id'] = $sessionId;
5790
                Database::insert($TBL_INTRODUCTION, $result);
5791
            }
5792
        }
5793
    }
5794
5795
    /**
5796
     * @param int $sessionId