Code Duplication    Length = 16-28 lines in 8 locations

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

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

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

@@ 5474-5491 (lines=18) @@
5471
     * @param int $userId
5472
     * @return array
5473
     */
5474
    public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = null)
5475
    {
5476
        $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
5477
5478
        $sessionId = intval($sessionId);
5479
        $userId = intval($userId);
5480
5481
        $sql = "SELECT * FROM $table
5482
                WHERE session_id = $sessionId AND user_id = $userId";
5483
5484
        if (!empty($limit)) {
5485
            $limit = intval($limit);
5486
            $sql .= " LIMIT $limit";
5487
        }
5488
        $result = Database::query($sql);
5489
5490
        return Database::store_result($result);
5491
    }
5492
5493
    /**
5494
     * Get information from the track_e_course_access table

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

@@ 126-147 (lines=22) @@
123
     *
124
     * @return bool
125
     */
126
    public static function hasVersion($language, $version)
127
    {
128
        $table = Database::get_main_table(TABLE_MAIN_LEGAL);
129
        $language = intval($language);
130
        $version = intval($version);
131
132
        if (empty($language)) {
133
            return false;
134
        }
135
136
        $sql = "SELECT version FROM $table
137
                WHERE 
138
                    language_id = '$language' AND 
139
                    version = '$version'                
140
                LIMIT 1 ";
141
        $result = Database::query($sql);
142
        if (Database::num_rows($result) > 0) {
143
            return true;
144
        } else {
145
            return false;
146
        }
147
    }
148
149
    /**
150
     * @param string $content

main/inc/lib/AnnouncementManager.php 1 location

@@ 933-960 (lines=28) @@
930
     * @param int $annoucement_id
931
     * @return array
932
     */
933
    public static function get_by_id($course_id, $annoucement_id)
934
    {
935
        $annoucement_id = intval($annoucement_id);
936
        $course_id = $course_id ? intval($course_id) : api_get_course_int_id();
937
938
        $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
939
        $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
940
941
        $sql = "SELECT DISTINCT 
942
                    announcement.id, 
943
                    announcement.title, 
944
                    announcement.content
945
               FROM $tbl_announcement announcement
946
               INNER JOIN $tbl_item_property ip
947
               ON
948
                    announcement.id = ip.ref AND
949
                    announcement.c_id = ip.c_id
950
               WHERE
951
                    announcement.c_id = $course_id AND
952
                    ip.tool='announcement' AND
953
                    announcement.id = $annoucement_id
954
                ";
955
        $result = Database::query($sql);
956
        if (Database::num_rows($result)) {
957
            return Database::fetch_array($result);
958
        }
959
        return [];
960
    }
961
962
    /**
963
     * this function gets all the groups of the course,

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

@@ 1324-1339 (lines=16) @@
1321
     * @param int $group_id id
1322
     * @return int Number of students in the given group.
1323
     */
1324
    public static function number_of_students($group_id, $course_id = null)
1325
    {
1326
        $table_group_user = Database::get_course_table(TABLE_GROUP_USER);
1327
        $group_id = intval($group_id);
1328
        if (empty($course_id)) {
1329
            $course_id = api_get_course_int_id();
1330
        } else {
1331
            $course_id = intval($course_id);
1332
        }
1333
        $sql = "SELECT COUNT(*) AS number_of_students
1334
                FROM $table_group_user
1335
                WHERE c_id = $course_id AND group_id = $group_id";
1336
        $result = Database::query($sql);
1337
        $db_object = Database::fetch_object($result);
1338
1339
        return $db_object->number_of_students;
1340
    }
1341
1342
    /**
@@ 1762-1784 (lines=23) @@
1759
     * @todo use the function user_has_access that includes this function
1760
     * @author Patrick Cool <[email protected]>, Ghent University
1761
     */
1762
    public static function is_tutor_of_group($user_id, $groupInfo)
1763
    {
1764
        if (empty($groupInfo)) {
1765
            return false;
1766
        }
1767
        $table_group_tutor = Database::get_course_table(TABLE_GROUP_TUTOR);
1768
        $user_id = intval($user_id);
1769
        $group_id = intval($groupInfo['id']);
1770
1771
        $course_id = api_get_course_int_id();
1772
1773
        $sql = "SELECT * FROM $table_group_tutor
1774
                WHERE 
1775
                    c_id = $course_id AND 
1776
                    user_id = $user_id AND 
1777
                    group_id = $group_id";
1778
        $result = Database::query($sql);
1779
        if (Database::num_rows($result) > 0) {
1780
            return true;
1781
        } else {
1782
            return false;
1783
        }
1784
    }
1785
1786
    /**
1787
     * Is the user part of this group? This can be a tutor or a normal member

main/inc/lib/TicketManager.php 1 location

@@ 163-179 (lines=17) @@
160
     *
161
     * @return bool
162
     */
163
    public static function deleteCategory($id)
164
    {
165
        $id = intval($id);
166
        if (empty($id)) {
167
            return false;
168
        }
169
170
        $table = Database::get_main_table(TABLE_TICKET_TICKET);
171
        $sql = "UPDATE $table SET category_id = NULL WHERE category_id = $id";
172
        Database::query($sql);
173
174
        $table = Database::get_main_table(TABLE_TICKET_CATEGORY);
175
        $sql = "DELETE FROM $table WHERE id = $id";
176
        Database::query($sql);
177
178
        return true;
179
    }
180
181
    /**
182
     * @param int $categoryId

main/survey/survey.lib.php 1 location

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