Code Duplication    Length = 15-24 lines in 8 locations

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

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

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

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

main/survey/survey.lib.php 1 location

@@ 4106-4122 (lines=17) @@
4103
     * @author Patrick Cool <[email protected]>, Ghent University
4104
     * @version September 2007
4105
     */
4106
    public static function get_invitations($survey_code)
4107
    {
4108
        $course_id = api_get_course_int_id();
4109
        // Database table definition
4110
        $table_survey_invitation 	= Database :: get_course_table(TABLE_SURVEY_INVITATION);
4111
4112
        $sql = "SELECT * FROM $table_survey_invitation
4113
		        WHERE
4114
		            c_id = $course_id AND
4115
		            survey_code = '".Database::escape_string($survey_code)."'";
4116
        $result = Database::query($sql);
4117
        $return = array();
4118
        while ($row = Database::fetch_array($result)) {
4119
            $return[$row['user']] = $row;
4120
        }
4121
        return $return;
4122
    }
4123
4124
    /**
4125
     * This function displays the form for searching a survey

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

@@ 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
     *
@@ 1624-1643 (lines=20) @@
1621
     *
1622
     * @return array
1623
     */
1624
    public static function get_all_exercises_from_lp($lp_id, $course_id)
1625
    {
1626
        $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
1627
        $course_id = intval($course_id);
1628
        $lp_id = intval($lp_id);
1629
        $sql = "SELECT * FROM $lp_item_table
1630
                WHERE
1631
                    c_id = $course_id AND
1632
                    lp_id = '".$lp_id."' AND
1633
                    item_type = 'quiz'
1634
                ORDER BY parent_item_id, display_order";
1635
        $res = Database::query($sql);
1636
1637
        $my_exercise_list = array();
1638
        while ($row = Database::fetch_array($res, 'ASSOC')) {
1639
            $my_exercise_list[] = $row;
1640
        }
1641
1642
        return $my_exercise_list;
1643
    }
1644
1645
    /**
1646
     * This function gets the comments of an exercise

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

@@ 5669-5685 (lines=17) @@
5666
 * @author Julio Montoya <[email protected]>
5667
 * @return int user id
5668
 */
5669
function api_get_access_url_from_user($user_id) {
5670
    $user_id = intval($user_id);
5671
    $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
5672
    $table_url          = Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
5673
    $sql = "SELECT access_url_id
5674
            FROM $table_url_rel_user url_rel_user
5675
            INNER JOIN $table_url u
5676
            ON (url_rel_user.access_url_id = u.id)
5677
            WHERE user_id = ".intval($user_id);
5678
    $result = Database::query($sql);
5679
    $list = array();
5680
    while ($row = Database::fetch_array($result, 'ASSOC')) {
5681
        $list[] = $row['access_url_id'];
5682
    }
5683
    return $list;
5684
}
5685
5686
/**
5687
 * Gets the status of a user in a course
5688
 * @param int       $user_id

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

@@ 7809-7832 (lines=24) @@
7806
     *
7807
     * @return array
7808
     */
7809
    public static function getCoursesInSession($sessionId)
7810
    {
7811
        if (empty($sessionId)) {
7812
            return [];
7813
        }
7814
7815
        $tblSessionRelCourse = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
7816
        $tblCourse = Database::get_main_table(TABLE_MAIN_COURSE);
7817
7818
        // list of course in this session
7819
        $sql = "SELECT session_id, c.id
7820
                FROM $tblSessionRelCourse src
7821
                LEFT JOIN $tblCourse c
7822
                ON c.id = src.c_id
7823
                WHERE session_id = ".intval($sessionId);
7824
        $res = Database::query($sql);
7825
7826
        $listResultsCourseId = array();
7827
        while ($data = Database::fetch_assoc($res)) {
7828
            $listResultsCourseId[] = $data['id'];
7829
        }
7830
7831
        return $listResultsCourseId;
7832
    }
7833
7834
    /**
7835
     * Return an array of courses in session for user