Skip to content
Snippets Groups Projects
Commit 41e0f42d authored by André Noack's avatar André Noack
Browse files

Resolve "Reihenfolge der Tools in Einrichtungen falsch"

parent 48f8f303
No related branches found
No related tags found
No related merge requests found
...@@ -101,11 +101,21 @@ class Course_PlusController extends AuthenticatedController ...@@ -101,11 +101,21 @@ class Course_PlusController extends AuthenticatedController
PageLayout::setTitle(_('Reihenfolge der Werkzeuge ändern')); PageLayout::setTitle(_('Reihenfolge der Werkzeuge ändern'));
if (Request::submitted('order')) { if (Request::submitted('order')) {
CSRFProtection::verifyUnsafeRequest(); CSRFProtection::verifyUnsafeRequest();
$plugin_id = Request::get('id'); $plugin_id = explode('_', Request::get('id'))[1];
$newpos = Request::get('index') + 1; $newpos = Request::get('index') + 1;
if ($this->sem->tools->findOneBy('plugin_id', $plugin_id)) { if ($this->sem->tools->findOneBy('plugin_id', $plugin_id)) {
$this->sem->tools->findBy('position', $newpos, '>=')->each(function ($p) {$p->position++;}); $oldpos = $this->sem->tools->findOneBy('plugin_id', $plugin_id)->position;
$this->sem->tools->findOneBy('plugin_id', $plugin_id)->position = $newpos; if ($oldpos < $newpos) {
$this->sem->tools->findBy('position', $newpos, '>')->each(function ($p) {
$p->position++;
});
$this->sem->tools->findOneBy('plugin_id', $plugin_id)->position = $newpos + 1;
} else {
$this->sem->tools->findBy('position', $newpos, '>=')->each(function ($p) {
$p->position++;
});
$this->sem->tools->findOneBy('plugin_id', $plugin_id)->position = $newpos;
}
$this->sem->tools->orderBy('position asc')->each(function ($p) {static $pos = 0; $p->position = $pos++;}); $this->sem->tools->orderBy('position asc')->each(function ($p) {static $pos = 0; $p->position = $pos++;});
$this->sem->tools->store(); $this->sem->tools->store();
$this->render_nothing(); $this->render_nothing();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<? if ($sem->tools): ?> <? if ($sem->tools): ?>
<? foreach ($sem->tools as $tool): ?> <? foreach ($sem->tools as $tool): ?>
<?php if (!$tool->getStudipModule()) continue; ?> <?php if (!$tool->getStudipModule()) continue; ?>
<article class="draggable" id="<?= $tool->plugin_id ?>"> <article class="draggable" id="plugin_<?= $tool->plugin_id ?>">
<header> <header>
<span class="sg-sortable-handle"></span> <span class="sg-sortable-handle"></span>
<h1><?= htmlready($tool->getDisplayName()) ?></h1> <h1><?= htmlready($tool->getDisplayName()) ?></h1>
......
...@@ -197,7 +197,8 @@ class Institute extends SimpleORMap implements Range ...@@ -197,7 +197,8 @@ class Institute extends SimpleORMap implements Range
$config['has_many']['tools'] = [ $config['has_many']['tools'] = [
'class_name' => 'ToolActivation', 'class_name' => 'ToolActivation',
'assoc_foreign_key' => 'range_id', 'assoc_foreign_key' => 'range_id',
'on_delete' => 'delete', 'order_by' => 'ORDER BY position',
'on_delete' => 'delete'
]; ];
$config['additional_fields']['all_status_groups']['get'] = function ($institute) { $config['additional_fields']['all_status_groups']['get'] = function ($institute) {
return Statusgruppen::findAllByRangeId($institute->id, true); return Statusgruppen::findAllByRangeId($institute->id, true);
......
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