diff --git a/app/controllers/course/plus.php b/app/controllers/course/plus.php index f8132df612da63f099849867fe48db5df5ecb883..1cfe36bf2d874d9f37e5f4f48994851f49dad641 100644 --- a/app/controllers/course/plus.php +++ b/app/controllers/course/plus.php @@ -101,11 +101,21 @@ class Course_PlusController extends AuthenticatedController PageLayout::setTitle(_('Reihenfolge der Werkzeuge ändern')); if (Request::submitted('order')) { CSRFProtection::verifyUnsafeRequest(); - $plugin_id = Request::get('id'); + $plugin_id = explode('_', Request::get('id'))[1]; $newpos = Request::get('index') + 1; if ($this->sem->tools->findOneBy('plugin_id', $plugin_id)) { - $this->sem->tools->findBy('position', $newpos, '>=')->each(function ($p) {$p->position++;}); - $this->sem->tools->findOneBy('plugin_id', $plugin_id)->position = $newpos; + $oldpos = $this->sem->tools->findOneBy('plugin_id', $plugin_id)->position; + 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->store(); $this->render_nothing(); diff --git a/app/views/course/plus/sorttools.php b/app/views/course/plus/sorttools.php index de5759298aaacf5b74df0727c63395cca74b9e0b..8a20aea1c9e2fa43f5b184337fdeb8c6f7594ac6 100644 --- a/app/views/course/plus/sorttools.php +++ b/app/views/course/plus/sorttools.php @@ -2,7 +2,7 @@ <? if ($sem->tools): ?> <? foreach ($sem->tools as $tool): ?> <?php if (!$tool->getStudipModule()) continue; ?> - <article class="draggable" id="<?= $tool->plugin_id ?>"> + <article class="draggable" id="plugin_<?= $tool->plugin_id ?>"> <header> <span class="sg-sortable-handle"></span> <h1><?= htmlready($tool->getDisplayName()) ?></h1> diff --git a/lib/models/Institute.class.php b/lib/models/Institute.class.php index efcb888306d36631b3e7fa1f9543cde5313ee570..86120c1e3fac6d5d25c54d09e2223e965e572f7b 100644 --- a/lib/models/Institute.class.php +++ b/lib/models/Institute.class.php @@ -197,7 +197,8 @@ class Institute extends SimpleORMap implements Range $config['has_many']['tools'] = [ 'class_name' => 'ToolActivation', '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) { return Statusgruppen::findAllByRangeId($institute->id, true);