aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2023-08-15 11:40:17 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2023-08-15 11:40:17 +0000
commit2ebb832cd22c396c8d7a767e21c65469451b99f6 (patch)
tree2d37e986071fd0024eae5bef9fc74312984dece9 /app
parentd40194171a96a27922c5b8092ef08605a35ba167 (diff)
simplify search settings code (and drop redundant order value), fixes #2967
Closes #2967 Merge request studip/studip!2013
Diffstat (limited to 'app')
-rw-r--r--app/controllers/globalsearch.php53
-rw-r--r--app/views/global_search/settings.php26
2 files changed, 20 insertions, 59 deletions
diff --git a/app/controllers/globalsearch.php b/app/controllers/globalsearch.php
index 1a5915c..4a198a2 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 a0bb852..65aaa37 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>