Skip to content
Snippets Groups Projects
Select Git revision
21 results Searching

plugin.manifest

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    GlobalSearchMyCourses.php 7.95 KiB
    <?php
    /**
     * GlobalSearchModule for my courses
     *
     * @author      Thomas Hackl <thomas.hackl@uni-passau.de>
     * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
     * @category    Stud.IP
     * @since       4.1
     */
    class GlobalSearchMyCourses extends GlobalSearchModule
    {
        /**
         * Returns the displayname for this module
         *
         * @return string
         */
        public static function getName()
        {
            return _('Meine Veranstaltungen');
        }
    
        /**
         * Returns the filters that are displayed in the sidebar of the global search.
         *
         * @return array Filters for this class.
         */
        public static function getFilters()
        {
            return ['semester', 'institute', 'seminar_type'];
        }
    
        /**
         * Transforms the search request into an sql statement, that provides the id (same as getId) as type and
         * the object id, that is later passed to the filter.
         *
         * This function is required to make use of the mysql union parallelism
         *
         * @param string $search the input query string
         * @param array $filter an array with search limiting filter information (e.g. 'category', 'semester', etc.)
         * @return string SQL Query to discover elements for the search
         */
        public static function getSQL($search, $filter, $limit)
        {
            if (!$search) {
                return null;
            }
    
            // generate SQL for the given sidebar filter (semester, institute, seminar_type)
            if ($filter['category'] === self::class || $filter['category'] == 'show_all_categories') {
                if ($filter['semester']) {
                    if ($filter['semester'] === 'future') {
                        $semester = Semester::findCurrent();
                        $next_semester = Semester::findNext();
                        $semester_ids = array_filter([$semester->id, $next_semester->id]);
                    } else {
                        $semester = Semester::findByTimestamp($filter['semester']);
                        $semester_ids = [$semester->id];
                    }
                    $semester_join = "LEFT JOIN semester_courses ON (courses.Seminar_id = semester_courses.course_id) ";
                    $semester_condition = "
                        AND (
                            `courses`.start_time <= " . DBManager::get()->quote($semester->beginn) ."
                            AND (`semester_courses`.semester_id IS NULL OR semester_courses.semester_id IN (" . join(',', array_map([DBManager::get(), 'quote'], $semester_ids)) . "))
                        ) ";
                }
                if ($filter['institute']) {
                    $institutes = self::getInstituteIdsForSQL($filter['institute']);
                    $institute_condition = " AND `courses`.`Institut_id` IN (" .DBManager::get()->quote($institutes). ") ";
                }
                if ($filter['seminar_type']) {