diff --git a/app/controllers/globalsearch.php b/app/controllers/globalsearch.php index 1a5915cd877089872e1aa7288c790bc638f90dbf..4a198a200cc81e3cf1aba5320f1dbf154bb11b6e 100644 --- a/app/controllers/globalsearch.php +++ b/app/controllers/globalsearch.php @@ -131,34 +131,24 @@ class GlobalSearchController extends AuthenticatedController Navigation::activateItem('/admin/config/globalsearch'); $this->config = Config::get()->GLOBALSEARCH_MODULES; - $this->modules = []; - // Scan for available modules. - foreach (scandir($GLOBALS['STUDIP_BASE_PATH'] . '/lib/classes/globalsearch') as $filename) { - $path = pathinfo($filename); - if ($path['extension'] === 'php') { - class_exists($path['filename']); + foreach ($this->config as $className => $config) { + if (class_exists($className)) { + $this->modules[$className] = new $className(); } } // Search declared classes for GlobalSearchModules - $endindex = 100; foreach (get_declared_classes() as $className) { - if (is_a($className, 'GlobalSearchModule', true) - && $className !== 'GlobalSearchModule') { - $class = new $className(); + if (is_subclass_of($className, 'GlobalSearchModule')) { // Add new classes at module array end and not activated. - if (in_array($className, array_keys($this->config))) { - $this->modules[$this->config[$className]['order']] = $class; - } else { - $this->modules[$endindex++] = $class; + if (!isset($this->modules[$className])) { + $this->modules[$className] = new $className(); } } } - - ksort($this->modules); } /** @@ -170,40 +160,19 @@ class GlobalSearchController extends AuthenticatedController $config = []; - $order = 1; foreach (Request::getArray('modules') as $module) { $config[$module['class']] = [ - 'order' => $order, 'active' => (bool)$module['active'], 'fulltext' => is_a($module['class'], 'GlobalSearchFulltext', true) && $module['fulltext'] ]; - $order++; } - $success = true; - if (Request::int('async_queries', 0) != Config::get()->GLOBALSEARCH_ASYNC_QUERIES) { - $success = Config::get()->store('GLOBALSEARCH_ASYNC_QUERIES', - ['value' => Request::int('async_queries', 0)]); - Config::get()->GLOBALSEARCH_ASYNC_QUERIES = Request::int('async_queries', 0); - } + Config::get()->store('GLOBALSEARCH_ASYNC_QUERIES', Request::int('async_queries', 0)); + Config::get()->store('GLOBALSEARCH_MAX_RESULT_OF_TYPE', Request::int('entries_per_type', 3)); + Config::get()->store('GLOBALSEARCH_MODULES', $config); - if (Request::int('entries_per_type', 3) != Config::get()->GLOBALSEARCH_MAX_RESULT_OF_TYPE) { - $success = Config::get()->store('GLOBALSEARCH_MAX_RESULT_OF_TYPE', - ['value' => Request::int('entries_per_type', 3)]); - Config::get()->GLOBALSEARCH_MAX_RESULT_OF_TYPE = Request::int('entries_per_type', 3); - } + PageLayout::postSuccess(_('Die Einstellungen wurden gespeichert.')); - if ($config != Config::get()->GLOBALSEARCH_MODULES) { - $success = Config::get()->store('GLOBALSEARCH_MODULES', ['value' => $config]); - } - - if ($success) { - PageLayout::postSuccess(_('Die Einstellungen wurden gespeichert.')); - } else { - PageLayout::postError(_('Die Einstellungen konnten nicht gespeichert werden.')); - } - - $this->relocate('globalsearch/settings'); + $this->redirect('globalsearch/settings'); } - } diff --git a/app/views/global_search/settings.php b/app/views/global_search/settings.php index a0bb852a9971b54b2b6aeba75a9413094c98a78a..65aaa37e971ac64f426390fb9d6abdab5e9a4b95 100644 --- a/app/views/global_search/settings.php +++ b/app/views/global_search/settings.php @@ -45,33 +45,25 @@ </tr> </thead> <tbody> - <?php foreach ($modules as $module) : ?> + <?php foreach ($modules as $className => $module) : ?> <tr> <td class="drag-handle"></td> <td> - <?php $resourcesInactive = (get_class($module) == 'GlobalSearchResources' || - get_class($module) == 'GlobalSearchRoomBookings') && !Config::get()->RESOURCES_ENABLE ?> - <label for="active[<?= htmlReady(get_class($module)) ?>]" - <?php if ($resourcesInactive) : ?> - class="inactive-settings-category" - data-tooltip="<?= htmlReady(sprintf(_('%s sind inaktiv, da die Ressourcenverwaltung derzeit deaktiviert ist.'), $module->getName())) ?>" - <?php endif ?> - > + <label for="active[<?= htmlReady($className) ?>]"> <?= htmlReady($module->getName()) ?> </label> - <input type="hidden" name="modules[<?= htmlReady(get_class($module)) ?>][class]" - value="<?= htmlReady(get_class($module)) ?>"> + <input type="hidden" name="modules[<?= htmlReady($className) ?>][class]" + value="<?= htmlReady($className) ?>"> </td> <td> - <input type="checkbox" id="active[<?= htmlReady(get_class($module)) ?>]" - name="modules[<?= htmlReady(get_class($module)) ?>][active]" value="1" - <?= !empty($config[get_class($module)]['active']) && !$resourcesInactive ? ' checked' : '' ?> - <?= $resourcesInactive ? ' disabled' : '' ?>> + <input type="checkbox" id="active[<?= htmlReady($className) ?>]" + name="modules[<?= htmlReady($className) ?>][active]" value="1" + <?= !empty($config[$className]['active']) ? ' checked' : '' ?>> </td> <td> <?php if (is_a($module, 'GlobalSearchFulltext')) : ?> - <input type="checkbox" name="modules[<?= htmlReady(get_class($module)) ?>][fulltext]" - value="1"<?= $config[get_class($module)]['fulltext'] ? ' checked' : ''?>> + <input type="checkbox" name="modules[<?= htmlReady($className) ?>][fulltext]" + value="1"<?= $config[$className]['fulltext'] ? ' checked' : ''?>> <?php endif ?> </td> </tr> diff --git a/lib/classes/globalsearch/GlobalSearchModule.php b/lib/classes/globalsearch/GlobalSearchModule.php index 7e9f251d2d7d6ebe2ebc1c6326e827c3d631c519..82551c626950b402f02d5c581d9ddb52f1cbd24b 100644 --- a/lib/classes/globalsearch/GlobalSearchModule.php +++ b/lib/classes/globalsearch/GlobalSearchModule.php @@ -218,7 +218,7 @@ abstract class GlobalSearchModule return false; } - if (in_array($module, ['GlobalSearchResources', 'GlobalSearchRoomAssignments']) + if (in_array($module, ['GlobalSearchResources', 'GlobalSearchRoomBookings']) && !Config::get()->RESOURCES_ENABLE ) { return false;