Code Duplication    Length = 14-19 lines in 7 locations

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/inc/lib/api.lib.php 1 location

@@ 3927-3940 (lines=14) @@
3924
 * @param int $ref
3925
 * @return array|resource
3926
 */
3927
function api_get_track_item_property_history($tool, $ref)
3928
{
3929
    $tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
3930
    $course_id = api_get_course_int_id(); //numeric
3931
    $course_code = api_get_course_id(); //alphanumeric
3932
    $item_property_id = api_get_item_property_id($course_code, $tool, $ref);
3933
    $sql = "SELECT * FROM $tbl_stats_item_property
3934
            WHERE item_property_id = $item_property_id AND course_id = $course_id
3935
            ORDER BY lastedit_date DESC";
3936
    $result = Database::query($sql);
3937
    $result = Database::store_result($result,'ASSOC');
3938
3939
    return $result;
3940
}
3941
3942
/**
3943
 * Gets item property data from tool of a course id

main/survey/survey.lib.php 1 location

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

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

@@ 5204-5221 (lines=18) @@
5201
     * @param int $userId
5202
     * @return array
5203
     */
5204
    public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = null)
5205
    {
5206
        $table = Database:: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
5207
5208
        $sessionId = intval($sessionId);
5209
        $userId = intval($userId);
5210
5211
        $sql = "SELECT * FROM $table
5212
                WHERE session_id = $sessionId AND user_id = $userId";
5213
5214
        if (!empty($limit)) {
5215
            $limit = intval($limit);
5216
            $sql .= " LIMIT $limit";
5217
        }
5218
        $result = Database::query($sql);
5219
5220
        return Database::store_result($result);
5221
    }
5222
5223
    /**
5224
     * Get information from the track_e_course_access table