Code Duplication    Length = 15-29 lines in 10 locations

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

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

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

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

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

@@ 1672-1688 (lines=17) @@
1669
     *
1670
     * @return array
1671
     */
1672
    public static function getAllExerciseEventByExeId($exe_id)
1673
    {
1674
        $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
1675
        $exe_id = intval($exe_id);
1676
        $list = array();
1677
1678
        $sql = "SELECT * FROM $table_track_attempt
1679
                WHERE exe_id = $exe_id
1680
                ORDER BY position";
1681
        $res_question = Database::query($sql);
1682
        if (Database::num_rows($res_question)) {
1683
            while ($row = Database::fetch_array($res_question, 'ASSOC')) {
1684
                $list[$row['question_id']][] = $row;
1685
            }
1686
        }
1687
        return $list;
1688
    }
1689
1690
    /**
1691
     *
@@ 1623-1642 (lines=20) @@
1620
     *
1621
     * @return array
1622
     */
1623
    public static function get_all_exercises_from_lp($lp_id, $course_id)
1624
    {
1625
        $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
1626
        $course_id = intval($course_id);
1627
        $lp_id = intval($lp_id);
1628
        $sql = "SELECT * FROM $lp_item_table
1629
                WHERE
1630
                    c_id = $course_id AND
1631
                    lp_id = '".$lp_id."' AND
1632
                    item_type = 'quiz'
1633
                ORDER BY parent_item_id, display_order";
1634
        $res = Database::query($sql);
1635
1636
        $my_exercise_list = array();
1637
        while ($row = Database::fetch_array($res, 'ASSOC')) {
1638
            $my_exercise_list[] = $row;
1639
        }
1640
1641
        return $my_exercise_list;
1642
    }
1643
1644
    /**
1645
     * This function gets the comments of an exercise

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

@@ 5731-5747 (lines=17) @@
5728
 * @author Julio Montoya <[email protected]>
5729
 * @return int user id
5730
 */
5731
function api_get_access_url_from_user($user_id) {
5732
    $user_id = intval($user_id);
5733
    $table_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
5734
    $table_url          = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
5735
    $sql = "SELECT access_url_id
5736
            FROM $table_url_rel_user url_rel_user
5737
            INNER JOIN $table_url u
5738
            ON (url_rel_user.access_url_id = u.id)
5739
            WHERE user_id = ".intval($user_id);
5740
    $result = Database::query($sql);
5741
    $list = array();
5742
    while ($row = Database::fetch_array($result, 'ASSOC')) {
5743
        $list[] = $row['access_url_id'];
5744
    }
5745
    return $list;
5746
}
5747
5748
/**
5749
 * Gets the status of a user in a course
5750
 * @param int       $user_id

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

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

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

@@ 6355-6375 (lines=21) @@
6352
     *
6353
     * @return array
6354
     */
6355
    public static function getDeletedDocuments($courseInfo, $sessionId = 0)
6356
    {
6357
        $table = Database::get_course_table(TABLE_DOCUMENT);
6358
        $courseId = $courseInfo['real_id'];
6359
        $sessionCondition = api_get_session_condition($sessionId);
6360
        $sql = "SELECT * FROM $table
6361
                WHERE
6362
                  path LIKE '%DELETED%' AND
6363
                  c_id = $courseId
6364
                  $sessionCondition
6365
                ORDER BY path
6366
        ";
6367
6368
        $result = Database::query($sql);
6369
        $files = array();
6370
        while ($document = Database::fetch_array($result, 'ASSOC')) {
6371
            $files[] = $document;
6372
        }
6373
6374
        return $files;
6375
    }
6376
6377
    /**
6378
     * @param int $id

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

@@ 6591-6619 (lines=29) @@
6588
     * @param int $sessionId The session id
6589
     * @return array
6590
     */
6591
    public static function getTotalUserCoursesInSession($sessionId)
6592
    {
6593
        $tableUser = Database::get_main_table(TABLE_MAIN_USER);
6594
        $table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
6595
6596
        if (empty($sessionId)) {
6597
            return [];
6598
        }
6599
6600
        $sql = "SELECT 
6601
                    COUNT(u.id) as count, 
6602
                    u.id, 
6603
                    scu.status status_in_session, 
6604
                    u.status user_status
6605
                FROM $table scu
6606
                INNER JOIN $tableUser u 
6607
                ON scu.user_id = u.id
6608
                WHERE scu.session_id = ".intval($sessionId)."
6609
                GROUP BY u.id";
6610
6611
        $result = Database::query($sql);
6612
6613
        $list = array();
6614
        while ($data = Database::fetch_assoc($result)) {
6615
            $list[] = $data;
6616
        }
6617
6618
        return $list;
6619
    }
6620
6621
    /**
6622
     * Returns list of a few data from session (name, short description, start
@@ 8205-8228 (lines=24) @@
8202
     *
8203
     * @return array
8204
     */
8205
    public static function getCoursesInSession($sessionId)
8206
    {
8207
        if (empty($sessionId)) {
8208
            return [];
8209
        }
8210
8211
        $tblSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
8212
        $tblCourse = Database::get_main_table(TABLE_MAIN_COURSE);
8213
8214
        // list of course in this session
8215
        $sql = "SELECT session_id, c.id
8216
                FROM $tblSessionRelCourse src
8217
                LEFT JOIN $tblCourse c
8218
                ON c.id = src.c_id
8219
                WHERE session_id = ".intval($sessionId);
8220
        $res = Database::query($sql);
8221
8222
        $listResultsCourseId = array();
8223
        while ($data = Database::fetch_assoc($res)) {
8224
            $listResultsCourseId[] = $data['id'];
8225
        }
8226
8227
        return $listResultsCourseId;
8228
    }
8229
8230
    /**
8231
     * Return an array of courses in session for user

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