diff --git a/db/migrations/5.2.16_remove_global_search_my_courses.php b/db/migrations/5.2.16_remove_global_search_my_courses.php new file mode 100644 index 0000000000000000000000000000000000000000..254886261da341c288cfc2ff3723a56daf102399 --- /dev/null +++ b/db/migrations/5.2.16_remove_global_search_my_courses.php @@ -0,0 +1,54 @@ +<?php +return new class extends Migration +{ + public function description() + { + return 'Remove global search for my courses'; + } + + protected function up() + { + foreach (['config', 'config_values'] as $table) { + $this->removeConfiguration($table); + } + + $query = "DELETE `config_values` + FROM `config` + LEFT JOIN `config_values` USING (`field`) + WHERE `field` = 'GLOBALSEARCHMODULES' + AND `config`.`value` = `config_values`.`value`"; + DBManager::get()->exec($query); + } + + protected function down() + { + // We will not activate the search module since we cannot know it's + // previous state + } + + private function removeConfiguration(string $table): void + { + $query = "SELECT `value` + FROM `{$table}` + WHERE `field` = 'GLOBALSEARCH_MODULES'"; + $json = DBManager::get()->fetchColumn($query); + + if (!$json) { + return; + } + + $modules = json_decode($json, true); + $modules = array_filter( + $modules, + function ($index) { + return $index !== 'GlobalSearchMyCourses'; + }, + ARRAY_FILTER_USE_KEY + ); + + $query = "UPDATE `{$table}` + SET `value` = ? + WHERE `field` = 'GLOBALSEARCH_MODULES'"; + DBManager::get()->execute($query, [json_encode($modules)]); + } +}; diff --git a/lib/classes/globalsearch/GlobalSearchCourses.php b/lib/classes/globalsearch/GlobalSearchCourses.php index 9de5535dba2166d271aafa9fb07f0417525d4a11..853f8112c99bcc790156d37786ed02685e1fa971 100644 --- a/lib/classes/globalsearch/GlobalSearchCourses.php +++ b/lib/classes/globalsearch/GlobalSearchCourses.php @@ -59,7 +59,6 @@ class GlobalSearchCourses extends GlobalSearchModule implements GlobalSearchFull } $visibility = ''; - $seminaruser = ''; $semester_join = ''; $institute_condition = ''; $seminar_type_condition = ''; @@ -68,11 +67,6 @@ class GlobalSearchCourses extends GlobalSearchModule implements GlobalSearchFull // visibility if (!$GLOBALS['perm']->have_perm('admin')) { $visibility = "courses.`visible` = 1 AND "; - $seminaruser = " AND NOT EXISTS ( - SELECT 1 FROM `seminar_user` - WHERE `seminar_id` = `courses`.`Seminar_id` - AND `user_id` = " . DBManager::get()->quote($GLOBALS['user']->id) . " - ) "; } // generate SQL for the given sidebar filter (semester, institute, seminar_type) @@ -120,7 +114,6 @@ class GlobalSearchCourses extends GlobalSearchModule implements GlobalSearchFull OR courses.`VeranstaltungsNummer` LIKE {$query} OR CONCAT(a.`Nachname`, ', ', a.`Vorname`, ' ', a.`Nachname`) LIKE {$query} ) - {$seminaruser} {$institute_condition} {$seminar_type_condition} {$semester_condition} diff --git a/lib/classes/globalsearch/GlobalSearchMyCourses.php b/lib/classes/globalsearch/GlobalSearchMyCourses.php deleted file mode 100644 index 6558f787ba5113a6428aa12faf982496ded828c1..0000000000000000000000000000000000000000 --- a/lib/classes/globalsearch/GlobalSearchMyCourses.php +++ /dev/null @@ -1,200 +0,0 @@ -<?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) - $semester_join = ''; - $institute_condition = ''; - $seminar_type_condition = ''; - $semester_condition = ''; - if ($filter['category'] === self::class || $filter['category'] == 'show_all_categories') { - if (!empty($filter['semester'])) { - if ($filter['semester'] === 'future') { - $semester = Semester::findCurrent(); - $next_semester = Semester::findNext(); - - $semester_ids = [$semester->id]; - if ($next_semester) { - $semester_ids[] = $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 ( - semester_courses.semester_id IS NULL OR semester_courses.semester_id IN (" . join(',', array_map([DBManager::get(), 'quote'], $semester_ids)) . ") - ) "; - } - if (!empty($filter['institute'])) { - $institutes = self::getInstituteIdsForSQL($filter['institute']); - $institute_condition = " AND `courses`.`Institut_id` IN (" .DBManager::get()->quote($institutes). ") "; - } - if (!empty($filter['seminar_type'])) { - $seminar_types = self::getSeminarTypesForSQL($filter['seminar_type']); - $seminar_type_condition = " AND `courses`.`status` IN (" .DBManager::get()->quote($seminar_types). ") "; - } - } - - $search = str_replace(" ", "% ", $search); - $query = DBManager::get()->quote("%{$search}%"); - $user_id = DBManager::get()->quote($GLOBALS['user']->id); - $sql = "SELECT SQL_CALC_FOUND_ROWS courses.* - FROM `seminare` AS courses - JOIN `seminar_user` USING (`Seminar_id`) - JOIN `sem_types` ON (courses.`status` = `sem_types`.`id`) - {$semester_join} - WHERE `user_id` = {$user_id} - AND (courses.`Name` LIKE {$query} - OR courses.`VeranstaltungsNummer` LIKE {$query} - OR CONCAT_WS(' ', `sem_types`.`name`, courses.`Name`) LIKE {$query} - ) - {$institute_condition} - {$seminar_type_condition} - {$semester_condition} - GROUP BY courses.Seminar_id - ORDER BY `start_time` DESC - LIMIT " . $limit; - return $sql; - } - - /** - * Returns an array of information for the found element. Following informations (key: description) are necessary - * - * - name: The name of the object - * - url: The url to send the user to when he clicks the link - * - * Additional informations are: - * - * - additional: Subtitle for the hit - * - expand: Url if the user further expands the search - * - img: Avatar for the - * - * @param array $data - * @param string $search - * @return array - */ - public static function filter($data, $search) - { - $course = Course::buildExisting($data); - $seminar = new Seminar($course); - $turnus_string = $seminar->getDatesExport([ - 'short' => true, - 'shrink' => true, - ]); - //Shorten, if string too long (add link for details.php) - if (mb_strlen($turnus_string) > 70) { - $turnus_string = htmlReady(mb_substr($turnus_string, 0, mb_strpos(mb_substr($turnus_string, 70, mb_strlen($turnus_string)), ',') + 71)); - $turnus_string .= ' ... <a href="' . URLHelper::getURL('dispatch.php/course/details/index/' . $course->id) . '">(' . _('mehr') . ')</a>'; - } else { - $turnus_string = htmlReady($turnus_string); - } - $lecturers = $course->getMembersWithStatus('dozent'); - $semester = $course->start_semester; - - // If you are not root, perhaps not all available subcourses are visible. - $visibleChildren = $course->children; - if (!$GLOBALS['perm']->have_perm(Config::get()->SEM_VISIBILITY_PERM)) { - $visibleChildren = $visibleChildren->filter(function($c) { - return $c->visible; - }); - } - $result_children = []; - foreach($visibleChildren as $child) { - $result_children[] = self::filter($child, $search); - } - - $result = [ - 'id' => $course->id, - 'number' => self::mark($course->veranstaltungsnummer, $search), - 'name' => self::mark($course->getFullName(), $search), - 'url' => URLHelper::getURL('seminar_main.php', ['cid' => $course->id], true), - 'date' => htmlReady($semester->short_name), - 'dates' => $turnus_string, - 'has_children' => count($course->children) > 0, - 'children' => $result_children, - 'additional' => implode(', ', - array_filter( - array_map( - function ($lecturer, $index) use ($search, $course) { - if ($index < 3) { - return self::mark($lecturer->getUserFullname(), $search); - } else if ($index == 3) { - return '... (' . _('mehr') . ')'; - } - }, - $lecturers, - array_keys($lecturers) - ) - ) - ), - 'expand' => self::getSearchURL($search), - ]; - if ($course->getSemClass()->offsetGet('studygroup_mode')) { - $avatar = StudygroupAvatar::getAvatar($course->id); - } else { - $avatar = CourseAvatar::getAvatar($course->id); - } - $result['img'] = $avatar->getUrl(Avatar::MEDIUM); - return $result; - } - - /** - * Returns the URL that can be called for a full search. - * - * @param string $searchterm what to search for? - * @return string URL to the full search, containing the searchterm and the category - */ - public static function getSearchURL($searchterm) - { - return URLHelper::getURL('dispatch.php/search/globalsearch', [ - 'q' => $searchterm, - 'category' => self::class - ]); - } - -} diff --git a/resources/assets/javascripts/lib/search.js b/resources/assets/javascripts/lib/search.js index f8108cda2b51732f9c47ccfb1a4d94d90bea0c2e..ff3a98d8c46b65bffc27528e43da9eecc83a79ac 100644 --- a/resources/assets/javascripts/lib/search.js +++ b/resources/assets/javascripts/lib/search.js @@ -180,7 +180,7 @@ const Search = { fullsearch, categoryBodyDiv ) { - var hasSubcourses = (categoryName === 'GlobalSearchMyCourses' || categoryName === 'GlobalSearchCourses') && result.has_children; + var hasSubcourses = categoryName === 'GlobalSearchCourses' && result.has_children; // Create single result entry. var single = $('<section>');