Code Duplication    Length = 15-29 lines in 10 locations

main/survey/surveyUtil.class.php 1 location

@@ 2447-2463 (lines=17) @@
2444
     * @author Patrick Cool <[email protected]>, Ghent University
2445
     * @version September 2007
2446
     */
2447
    public static function get_invitations($survey_code)
2448
    {
2449
        $course_id = api_get_course_int_id();
2450
        // Database table definition
2451
        $table_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
2452
2453
        $sql = "SELECT * FROM $table_survey_invitation
2454
		        WHERE
2455
		            c_id = $course_id AND
2456
		            survey_code = '".Database::escape_string($survey_code)."'";
2457
        $result = Database::query($sql);
2458
        $return = array();
2459
        while ($row = Database::fetch_array($result)) {
2460
            $return[$row['user']] = $row;
2461
        }
2462
        return $return;
2463
    }
2464
2465
    /**
2466
     * This function displays the form for searching a survey

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

@@ 1703-1719 (lines=17) @@
1700
     *
1701
     * @return array
1702
     */
1703
    public static function getAllExerciseEventByExeId($exe_id)
1704
    {
1705
        $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
1706
        $exe_id = intval($exe_id);
1707
        $list = array();
1708
1709
        $sql = "SELECT * FROM $table_track_attempt
1710
                WHERE exe_id = $exe_id
1711
                ORDER BY position";
1712
        $res_question = Database::query($sql);
1713
        if (Database::num_rows($res_question)) {
1714
            while ($row = Database::fetch_array($res_question, 'ASSOC')) {
1715
                $list[$row['question_id']][] = $row;
1716
            }
1717
        }
1718
        return $list;
1719
    }
1720
1721
    /**
1722
     *
@@ 1654-1673 (lines=20) @@
1651
     *
1652
     * @return array
1653
     */
1654
    public static function get_all_exercises_from_lp($lp_id, $course_id)
1655
    {
1656
        $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
1657
        $course_id = intval($course_id);
1658
        $lp_id = intval($lp_id);
1659
        $sql = "SELECT * FROM $lp_item_table
1660
                WHERE
1661
                    c_id = $course_id AND
1662
                    lp_id = '".$lp_id."' AND
1663
                    item_type = 'quiz'
1664
                ORDER BY parent_item_id, display_order";
1665
        $res = Database::query($sql);
1666
1667
        $my_exercise_list = array();
1668
        while ($row = Database::fetch_array($res, 'ASSOC')) {
1669
            $my_exercise_list[] = $row;
1670
        }
1671
1672
        return $my_exercise_list;
1673
    }
1674
1675
    /**
1676
     * This function gets the comments of an exercise

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

@@ 5702-5718 (lines=17) @@
5699
 * @author Julio Montoya <[email protected]>
5700
 * @return int user id
5701
 */
5702
function api_get_access_url_from_user($user_id) {
5703
    $user_id = intval($user_id);
5704
    $table_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
5705
    $table_url          = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
5706
    $sql = "SELECT access_url_id
5707
            FROM $table_url_rel_user url_rel_user
5708
            INNER JOIN $table_url u
5709
            ON (url_rel_user.access_url_id = u.id)
5710
            WHERE user_id = ".intval($user_id);
5711
    $result = Database::query($sql);
5712
    $list = array();
5713
    while ($row = Database::fetch_array($result, 'ASSOC')) {
5714
        $list[] = $row['access_url_id'];
5715
    }
5716
    return $list;
5717
}
5718
5719
/**
5720
 * Gets the status of a user in a course
5721
 * @param int       $user_id

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

@@ 4021-4035 (lines=15) @@
4018
     * @param int $userId
4019
     * @return array
4020
     */
4021
    public static function get_user_course_categories($userId = 0)
4022
    {
4023
        $userId = empty($userId) ? api_get_user_id() : (int) $userId;
4024
        $table_category = Database::get_main_table(TABLE_USER_COURSE_CATEGORY);
4025
        $sql = "SELECT * FROM $table_category 
4026
                WHERE user_id = $userId
4027
                ORDER BY sort ASC
4028
                ";
4029
        $result = Database::query($sql);
4030
        $output = array();
4031
        while ($row = Database::fetch_array($result, 'ASSOC')) {
4032
            $output[$row['id']] = $row;
4033
        }
4034
        return $output;
4035
    }
4036
4037
    /**
4038
     * Return an array the user_category id and title for the course $courseId for user $userId

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

@@ 6371-6391 (lines=21) @@
6368
     *
6369
     * @return array
6370
     */
6371
    public static function getDeletedDocuments($courseInfo, $sessionId = 0)
6372
    {
6373
        $table = Database::get_course_table(TABLE_DOCUMENT);
6374
        $courseId = $courseInfo['real_id'];
6375
        $sessionCondition = api_get_session_condition($sessionId);
6376
        $sql = "SELECT * FROM $table
6377
                WHERE
6378
                  path LIKE '%DELETED%' AND
6379
                  c_id = $courseId
6380
                  $sessionCondition
6381
                ORDER BY path
6382
        ";
6383
6384
        $result = Database::query($sql);
6385
        $files = array();
6386
        while ($document = Database::fetch_array($result, 'ASSOC')) {
6387
            $files[] = $document;
6388
        }
6389
6390
        return $files;
6391
    }
6392
6393
    /**
6394
     * @param int $id

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

@@ 710-729 (lines=20) @@
707
     * @param int $limit
708
     * @return array
709
     */
710
    public function searchByField($tag, $field_id, $limit = 10)
711
    {
712
        $field_id = intval($field_id);
713
        $limit = intval($limit);
714
        $tag = Database::escape_string($tag);
715
        $sql = "SELECT DISTINCT id, option_display_text
716
                FROM {$this->table}
717
                WHERE
718
                    field_id = '".$field_id."' AND
719
                    option_value LIKE '%$tag%'
720
                ORDER BY option_value
721
                LIMIT 0, $limit
722
                ";
723
        $result = Database::query($sql);
724
        $values = array();
725
        if (Database::num_rows($result)) {
726
            $values = Database::store_result($result, 'ASSOC');
727
        }
728
729
        return $values;
730
    }
731
732

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

@@ 660-674 (lines=15) @@
657
     * @param string $course_code The course (default = current course)
658
     * @return array
659
     */
660
    public static function get_categories($course_code = null)
661
    {
662
        $course_info = api_get_course_info($course_code);
663
        $course_id = $course_info['real_id'];
664
        $table_group_cat = Database::get_course_table(TABLE_GROUP_CATEGORY);
665
        $sql = "SELECT * FROM $table_group_cat
666
                WHERE c_id = $course_id
667
                ORDER BY display_order";
668
        $res = Database::query($sql);
669
        $cats = array();
670
        while ($cat = Database::fetch_array($res)) {
671
            $cats[] = $cat;
672
        }
673
        return $cats;
674
    }
675
676
    /**
677
     * Get a group category

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

@@ 6585-6613 (lines=29) @@
6582
     * @param int $sessionId The session id
6583
     * @return array
6584
     */
6585
    public static function getTotalUserCoursesInSession($sessionId)
6586
    {
6587
        $tableUser = Database::get_main_table(TABLE_MAIN_USER);
6588
        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
6589
6590
        if (empty($sessionId)) {
6591
            return [];
6592
        }
6593
6594
        $sql = "SELECT 
6595
                    COUNT(u.id) as count, 
6596
                    u.id, 
6597
                    scu.status status_in_session, 
6598
                    u.status user_status
6599
                FROM $table scu
6600
                INNER JOIN $tableUser u 
6601
                ON scu.user_id = u.id
6602
                WHERE scu.session_id = ".intval($sessionId)."
6603
                GROUP BY u.id";
6604
6605
        $result = Database::query($sql);
6606
6607
        $list = array();
6608
        while ($data = Database::fetch_assoc($result)) {
6609
            $list[] = $data;
6610
        }
6611
6612
        return $list;
6613
    }
6614
6615
    /**
6616
     * Returns list of a few data from session (name, short description, start
@@ 8233-8256 (lines=24) @@
8230
     *
8231
     * @return array
8232
     */
8233
    public static function getCoursesInSession($sessionId)
8234
    {
8235
        if (empty($sessionId)) {
8236
            return [];
8237
        }
8238
8239
        $tblSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
8240
        $tblCourse = Database::get_main_table(TABLE_MAIN_COURSE);
8241
8242
        // list of course in this session
8243
        $sql = "SELECT session_id, c.id
8244
                FROM $tblSessionRelCourse src
8245
                LEFT JOIN $tblCourse c
8246
                ON c.id = src.c_id
8247
                WHERE session_id = ".intval($sessionId);
8248
        $res = Database::query($sql);
8249
8250
        $listResultsCourseId = array();
8251
        while ($data = Database::fetch_assoc($res)) {
8252
            $listResultsCourseId[] = $data['id'];
8253
        }
8254
8255
        return $listResultsCourseId;
8256
    }
8257
8258
    /**
8259
     * Return an array of courses in session for user