Skip to content
Snippets Groups Projects
Commit 2ebb832c authored by Elmar Ludwig's avatar Elmar Ludwig Committed by Jan-Hendrik Willms
Browse files

simplify search settings code (and drop redundant order value), fixes #2967

Closes #2967

Merge request studip/studip!2013
parent d4019417
No related branches found
No related tags found
No related merge requests found
...@@ -131,34 +131,24 @@ class GlobalSearchController extends AuthenticatedController ...@@ -131,34 +131,24 @@ class GlobalSearchController extends AuthenticatedController
Navigation::activateItem('/admin/config/globalsearch'); Navigation::activateItem('/admin/config/globalsearch');
$this->config = Config::get()->GLOBALSEARCH_MODULES; $this->config = Config::get()->GLOBALSEARCH_MODULES;
$this->modules = []; $this->modules = [];
// Scan for available modules. foreach ($this->config as $className => $config) {
foreach (scandir($GLOBALS['STUDIP_BASE_PATH'] . '/lib/classes/globalsearch') as $filename) { if (class_exists($className)) {
$path = pathinfo($filename); $this->modules[$className] = new $className();
if ($path['extension'] === 'php') {
class_exists($path['filename']);
} }
} }
// Search declared classes for GlobalSearchModules // Search declared classes for GlobalSearchModules
$endindex = 100;
foreach (get_declared_classes() as $className) { foreach (get_declared_classes() as $className) {
if (is_a($className, 'GlobalSearchModule', true) if (is_subclass_of($className, 'GlobalSearchModule')) {
&& $className !== 'GlobalSearchModule') {
$class = new $className();
// Add new classes at module array end and not activated. // Add new classes at module array end and not activated.
if (in_array($className, array_keys($this->config))) { if (!isset($this->modules[$className])) {
$this->modules[$this->config[$className]['order']] = $class; $this->modules[$className] = new $className();
} else {
$this->modules[$endindex++] = $class;
} }
} }
} }
ksort($this->modules);
} }
/** /**
...@@ -170,40 +160,19 @@ class GlobalSearchController extends AuthenticatedController ...@@ -170,40 +160,19 @@ class GlobalSearchController extends AuthenticatedController
$config = []; $config = [];
$order = 1;
foreach (Request::getArray('modules') as $module) { foreach (Request::getArray('modules') as $module) {
$config[$module['class']] = [ $config[$module['class']] = [
'order' => $order,
'active' => (bool)$module['active'], 'active' => (bool)$module['active'],
'fulltext' => is_a($module['class'], 'GlobalSearchFulltext', true) && $module['fulltext'] 'fulltext' => is_a($module['class'], 'GlobalSearchFulltext', true) && $module['fulltext']
]; ];
$order++;
} }
$success = true; Config::get()->store('GLOBALSEARCH_ASYNC_QUERIES', Request::int('async_queries', 0));
if (Request::int('async_queries', 0) != Config::get()->GLOBALSEARCH_ASYNC_QUERIES) { Config::get()->store('GLOBALSEARCH_MAX_RESULT_OF_TYPE', Request::int('entries_per_type', 3));
$success = Config::get()->store('GLOBALSEARCH_ASYNC_QUERIES', Config::get()->store('GLOBALSEARCH_MODULES', $config);
['value' => Request::int('async_queries', 0)]);
Config::get()->GLOBALSEARCH_ASYNC_QUERIES = Request::int('async_queries', 0);
}
if (Request::int('entries_per_type', 3) != Config::get()->GLOBALSEARCH_MAX_RESULT_OF_TYPE) { PageLayout::postSuccess(_('Die Einstellungen wurden gespeichert.'));
$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);
}
if ($config != Config::get()->GLOBALSEARCH_MODULES) { $this->redirect('globalsearch/settings');
$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');
} }
} }
...@@ -45,33 +45,25 @@ ...@@ -45,33 +45,25 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($modules as $module) : ?> <?php foreach ($modules as $className => $module) : ?>
<tr> <tr>
<td class="drag-handle"></td> <td class="drag-handle"></td>
<td> <td>
<?php $resourcesInactive = (get_class($module) == 'GlobalSearchResources' || <label for="active[<?= htmlReady($className) ?>]">
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 ?>
>
<?= htmlReady($module->getName()) ?> <?= htmlReady($module->getName()) ?>
</label> </label>
<input type="hidden" name="modules[<?= htmlReady(get_class($module)) ?>][class]" <input type="hidden" name="modules[<?= htmlReady($className) ?>][class]"
value="<?= htmlReady(get_class($module)) ?>"> value="<?= htmlReady($className) ?>">
</td> </td>
<td> <td>
<input type="checkbox" id="active[<?= htmlReady(get_class($module)) ?>]" <input type="checkbox" id="active[<?= htmlReady($className) ?>]"
name="modules[<?= htmlReady(get_class($module)) ?>][active]" value="1" name="modules[<?= htmlReady($className) ?>][active]" value="1"
<?= !empty($config[get_class($module)]['active']) && !$resourcesInactive ? ' checked' : '' ?> <?= !empty($config[$className]['active']) ? ' checked' : '' ?>>
<?= $resourcesInactive ? ' disabled' : '' ?>>
</td> </td>
<td> <td>
<?php if (is_a($module, 'GlobalSearchFulltext')) : ?> <?php if (is_a($module, 'GlobalSearchFulltext')) : ?>
<input type="checkbox" name="modules[<?= htmlReady(get_class($module)) ?>][fulltext]" <input type="checkbox" name="modules[<?= htmlReady($className) ?>][fulltext]"
value="1"<?= $config[get_class($module)]['fulltext'] ? ' checked' : ''?>> value="1"<?= $config[$className]['fulltext'] ? ' checked' : ''?>>
<?php endif ?> <?php endif ?>
</td> </td>
</tr> </tr>
......
...@@ -218,7 +218,7 @@ abstract class GlobalSearchModule ...@@ -218,7 +218,7 @@ abstract class GlobalSearchModule
return false; return false;
} }
if (in_array($module, ['GlobalSearchResources', 'GlobalSearchRoomAssignments']) if (in_array($module, ['GlobalSearchResources', 'GlobalSearchRoomBookings'])
&& !Config::get()->RESOURCES_ENABLE && !Config::get()->RESOURCES_ENABLE
) { ) {
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment