Code Duplication    Length = 15-19 lines in 6 locations

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

@@ 5072-5089 (lines=18) @@
5069
     * @param int $userId
5070
     * @return array
5071
     */
5072
    public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = null)
5073
    {
5074
        $table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
5075
5076
        $sessionId = intval($sessionId);
5077
        $userId = intval($userId);
5078
5079
        $sql = "SELECT * FROM $table
5080
                WHERE session_id = $sessionId AND user_id = $userId";
5081
5082
        if (!empty($limit)) {
5083
            $limit = intval($limit);
5084
            $sql .= " LIMIT $limit";
5085
        }
5086
        $result = Database::query($sql);
5087
5088
        return Database::store_result($result);
5089
    }
5090
5091
    /**
5092
     * Get information from the track_e_course_access table

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

@@ 157-175 (lines=19) @@
154
     * Get the maximum display order of the thematic item
155
     * @return int	Maximum display order
156
     */
157
    public function get_max_thematic_item($use_session = true)
158
    {
159
        // Database table definition
160
        $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
161
        $session_id   = api_get_session_id();
162
        if ($use_session) {
163
            $condition_session = api_get_session_condition($session_id);
164
        } else {
165
            $condition_session = '';
166
        }
167
        $course_id = api_get_course_int_id();
168
        $sql = "SELECT MAX(display_order)
169
                FROM $tbl_thematic
170
                WHERE c_id = $course_id AND active = 1 $condition_session";
171
        $rs = Database::query($sql);
172
        $row = Database::fetch_array($rs);
173
174
        return $row[0];
175
    }
176
177
    /**
178
     * Move a thematic

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

@@ 1089-1104 (lines=16) @@
1086
     * @param int $group_id
1087
     * @return array
1088
     */
1089
    public static function getTutors($group_id)
1090
    {
1091
        $tutor_user_table = Database :: get_course_table(TABLE_GROUP_TUTOR);
1092
        $course_id = api_get_course_int_id();
1093
        $group_id = intval($group_id);
1094
1095
        $sql = "SELECT user_id FROM $tutor_user_table
1096
                WHERE c_id = $course_id AND group_id = $group_id";
1097
        $res = Database::query($sql);
1098
1099
        $users = array();
1100
        while ($obj = Database::fetch_object($res)) {
1101
            $users[] = api_get_user_info($obj->user_id);
1102
        }
1103
        return $users;
1104
    }
1105
1106
    /**
1107
     * Get only students from a group (not tutors)
@@ 1111-1125 (lines=15) @@
1108
     * @param int $group_id
1109
     * @return array
1110
     */
1111
    public static function getStudents($group_id)
1112
    {
1113
        $group_user_table = Database :: get_course_table(TABLE_GROUP_USER);
1114
        $course_id = api_get_course_int_id();
1115
        $group_id = intval($group_id);
1116
        $sql = "SELECT user_id FROM $group_user_table
1117
                WHERE c_id = $course_id AND group_id = $group_id";
1118
        $res = Database::query($sql);
1119
        $users = array();
1120
1121
        while ($obj = Database::fetch_object($res)) {
1122
            $users[] = api_get_user_info($obj->user_id);
1123
        }
1124
        return $users;
1125
    }
1126
1127
    /**
1128
     * Returns users belonging to any of the group
@@ 1279-1294 (lines=16) @@
1276
     * @param int $group_id
1277
     * @return int Number of students in the given group.
1278
     */
1279
    public static function number_of_students($group_id, $course_id = null)
1280
    {
1281
        $table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
1282
        $group_id = intval($group_id);
1283
        if (empty($course_id)) {
1284
            $course_id = api_get_course_int_id();
1285
        } else {
1286
            $course_id = intval($course_id);
1287
        }
1288
        $sql = "SELECT  COUNT(*) AS number_of_students
1289
                FROM $table_group_user
1290
                WHERE c_id = $course_id AND group_id = $group_id";
1291
        $db_result = Database::query($sql);
1292
        $db_object = Database::fetch_object($db_result);
1293
        return $db_object->number_of_students;
1294
    }
1295
1296
    /**
1297
     * Maximum number of students in a group

main/survey/survey.lib.php 1 location

@@ 1587-1605 (lines=19) @@
1584
     * @param int $course_id
1585
     * @return bool
1586
     */
1587
    public static function is_user_filled_survey($user_id, $survey_id, $course_id)
1588
    {
1589
        $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
1590
1591
        $user_id	= intval($user_id);
1592
        $course_id	= intval($course_id);
1593
        $survey_id	= intval($survey_id);
1594
1595
        $sql = "SELECT DISTINCT user FROM $table_survey_answer
1596
                WHERE
1597
                    c_id		= $course_id AND
1598
                    user		= $user_id AND
1599
                    survey_id	= $survey_id";
1600
        $result = Database::query($sql);
1601
        if (Database::num_rows($result)) {
1602
            return true;
1603
        }
1604
        return false;
1605
    }
1606
1607
    /**
1608
     * This function gets all the persons who have filled the survey