diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2021-11-04 13:28:13 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2021-11-04 13:28:13 +0000 |
| commit | bca463638c5b919a34ec90f3909c2eb44d2d1f77 (patch) | |
| tree | 7941a9e178dff09ad8a98367ed59bbf43d926846 /app | |
| parent | 0fe45573d21b5110a46de7b6dc60cbcec3f99de7 (diff) | |
fixes #132
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/consultation/admin.php | 91 | ||||
| -rw-r--r-- | app/controllers/consultation/consultation_controller.php | 6 | ||||
| -rw-r--r-- | app/views/consultation/admin/block-responsibilities.php | 50 | ||||
| -rw-r--r-- | app/views/consultation/admin/create.php | 25 | ||||
| -rw-r--r-- | app/views/consultation/admin/edit.php | 34 | ||||
| -rw-r--r-- | app/views/consultation/admin/edit_room.php | 21 | ||||
| -rw-r--r-- | app/views/consultation/admin/index.php | 9 | ||||
| -rw-r--r-- | app/views/consultation/block-description.php | 20 |
8 files changed, 180 insertions, 76 deletions
diff --git a/app/controllers/consultation/admin.php b/app/controllers/consultation/admin.php index 12c77a7..0ca50b3 100644 --- a/app/controllers/consultation/admin.php +++ b/app/controllers/consultation/admin.php @@ -140,11 +140,11 @@ class Consultation_AdminController extends ConsultationController $block = new ConsultationBlock(); $block->range = $this->range; - $this->responsible = $block->responsible_persons; + $this->responsible = $block->getPossibleResponsibilites(); } elseif ($this->range instanceof Institute) { $block = new ConsultationBlock(); $block->range = $this->range; - $this->responsible = $block->responsible_persons; + $this->responsible = $block->getPossibleResponsibilites(); } } @@ -182,10 +182,20 @@ class Consultation_AdminController extends ConsultationController $block->confirmation_text = trim(Request::get('confirmation-text')) ?: null; $block->note = Request::get('note'); $block->size = Request::int('size', 1); - $block->teacher_id = Request::option('teacher_id') ?: null; $block->createSlots(Request::int('duration')); $stored += $block->store(); + + // Store block responsibilites + foreach (Request::getArray('responsibilities') as $type => $ids) { + foreach ($ids as $id) { + ConsultationResponsibility::create([ + 'block_id' => $block->id, + 'range_id' => $id, + 'range_type' => $type, + ]); + } + } } } catch (OverlapException $e) { $this->keepRequest(); @@ -211,13 +221,9 @@ class Consultation_AdminController extends ConsultationController $this->relocate('consultation/admin'); } - public function note_action($block_id, $slot_id = null, $page = 0) + public function note_action($block_id, $slot_id, $page = 0) { - if ($slot_id) { - PageLayout::setTitle(_('Anmerkung zu diesem Termin bearbeiten')); - } else { - PageLayout::setTitle(_('Anmerkung zu diesem Block bearbeiten')); - } + PageLayout::setTitle(_('Anmerkung zu diesem Termin bearbeiten')); $this->block = $this->loadBlock($block_id); $this->slot_id = $slot_id; @@ -228,20 +234,10 @@ class Consultation_AdminController extends ConsultationController $note = trim(Request::get('note')); - $changed = false; - if ($slot_id) { - $slot = $this->block->slots->find($slot_id); - $slot->note = $note; - $changed = $slot->store(); - } else { - $this->block->note = $note; - foreach ($this->block->slots as $slot) { - $slot->note = ''; - } - $changed = $this->block->store(); - } - if ($changed) { - PageLayout::postSuccess(_('Der Block wurde bearbeitet')); + $slot = $this->block->slots->find($slot_id); + $slot->note = $note; + if ($slot->store()) { + PageLayout::postSuccess(_('Die Anmerkung wurde bearbeitet')); } if ($this->block->is_expired) { @@ -344,20 +340,60 @@ class Consultation_AdminController extends ConsultationController } } - public function edit_room_action($block_id, $page = 0) + public function edit_action($block_id, $page = 0) { - PageLayout::setTitle(_('Ort des Blocks bearbeiten')); + PageLayout::setTitle(_('Block bearbeiten')); $this->block = $this->loadBlock($block_id); $this->page = $page; + + $this->responsible = false; + if ($this->block->range instanceof Course || $this->block->range instanceof Institute) { + $this->responsible = $this->block->getPossibleResponsibilites(); + } } - public function store_room_action($block_id, $page = 0) + public function store_edited_action($block_id, $page = 0) { CSRFProtection::verifyUnsafeRequest(); $this->block = $this->loadBlock($block_id); - $this->block->room = Request::get('room'); + $this->block->room = trim(Request::get('room')); + $this->block->note = trim(Request::get('note')); + + foreach ($this->block->slots as $slot) { + $slot->note = ''; + } + + // Store block responsibilites + $responsibilities = array_merge( + ['user' => [], 'statusgroup' => [], 'institute' => []], + Request::getArray('responsibilities') + ); + foreach ($responsibilities as $type => $ids) { + $of_type = $this->block->responsibilities->filter(function ($responsibility) use ($type) { + return $responsibility->range_type === $type; + }); + + // Delete removed responsibilites + $of_type->each(function ($responsibility) use ($ids) { + if (!in_array($responsibility->range_id, $ids)) { + $responsibility->delete(); + } + }); + // Add new responsibilities + foreach ($ids as $id) { + if (!$of_type->findOneBy('range_id', $id)) { + ConsultationResponsibility::create([ + 'block_id' => $this->block->id, + 'range_id' => $id, + 'range_type' => $type, + ]); + } + } + } + + $this->block->store(); PageLayout::postSuccess(_('Der Block wurde gespeichert.')); @@ -577,7 +613,6 @@ class Consultation_AdminController extends ConsultationController function ($slot) use (&$deleted) { $index = $slot->is_expired ? 'expired' : 'current'; - $slot->removeEvent(); $deleted[$index] += $slot->delete(); }, "JOIN consultation_blocks USING (block_id) WHERE range_id = ? AND range_type = ?", diff --git a/app/controllers/consultation/consultation_controller.php b/app/controllers/consultation/consultation_controller.php index c69ab16..eba81ff 100644 --- a/app/controllers/consultation/consultation_controller.php +++ b/app/controllers/consultation/consultation_controller.php @@ -77,6 +77,12 @@ abstract class ConsultationController extends AuthenticatedController $this->flash['request'] = Request::getInstance()->getIterator()->getArrayCopy(); } + /** + * @param $block_id + * + * @return ConsultationBlock|ConsultationBlock[] + * @throws AccessDeniedException + */ protected function loadBlock($block_id) { if (is_array($block_id)) { diff --git a/app/views/consultation/admin/block-responsibilities.php b/app/views/consultation/admin/block-responsibilities.php new file mode 100644 index 0000000..ea3531a --- /dev/null +++ b/app/views/consultation/admin/block-responsibilities.php @@ -0,0 +1,50 @@ +<?php +$block = $block ?? false; +$selected = function ($type, $id) use ($block) { + if (!$block ) { + return ''; + } + $matched = $block->responsibilities->filter(function ($responsibility) use ($type, $id) { + return $responsibility->range_type === $type && $responsibility->range_id === $id; + }); + return count($matched) > 0 ? 'selected' : ''; +} +?> +<? if (!empty($responsible['users'])): ?> + <label> + <?= _('Durchführende Person(en)') ?> + <select name="responsibilities[user][]" multiple class="nested-select"> + <? foreach ($responsible['users'] as $user): ?> + <option value="<?= htmlReady($user->id) ?>" <?= $selected('user', $user->id) ?>> + <?= htmlReady($user->getFullName()) ?> + </option> + <? endforeach; ?> + </select> + </label> +<? endif; ?> + +<? if (!empty($responsible['groups'])): ?> + <label> + <?= _('Durchführende Gruppe(n)') ?> + <select name="responsibilities[statusgroup][]" multiple class="nested-select"> + <? foreach ($responsible['groups'] as $group): ?> + <option value="<?= htmlReady($group->id) ?>" <?= $selected('statusgroup', $group->id) ?>> + <?= htmlReady($group->getName()) ?> + </option> + <? endforeach; ?> + </select> + </label> +<? endif; ?> + +<? if (!empty($responsible['institutes'])): ?> + <label> + <?= _('Durchführende Einrichtung(en)') ?> + <select name="responsibilities[institute][]" multiple class="nested-select"> + <? foreach ($responsible['institutes'] as $institute): ?> + <option value="<?= htmlReady($institute->id) ?>" <?= $selected('institute', $institute->id) ?>> + <?= htmlReady($institute->getFullname()) ?> + </option> + <? endforeach; ?> + </select> + </label> +<? endif; ?> diff --git a/app/views/consultation/admin/create.php b/app/views/consultation/admin/create.php index 4630cee..d8727ef 100644 --- a/app/views/consultation/admin/create.php +++ b/app/views/consultation/admin/create.php @@ -36,7 +36,7 @@ $intervals = [ <fieldset> <legend> - <?= _('Neue Terminblöcke anlegen') ?> + <?= _('Ort und Zeit') ?> </legend> <label> @@ -119,19 +119,18 @@ $intervals = [ <input required type="text" name="size" id="size" min="1" max="50" value="<?= Request::int('size', 1) ?>"> </label> + </fieldset> - <? if ($responsible): ?> - <label> - <?= _('Durchführende Person') ?> - <select name="teacher_id"> - <option value=""></option> - <? foreach ($responsible as $user): ?> - <option value="<?= htmlReady($user->id) ?>"> - <?= htmlReady($user->getFullName()) ?> - </option> - <? endforeach; ?> - </select> - <? endif; ?> +<? if ($responsible): ?> + <fieldset> + <legend><?= _('Durchführende Person(en), Gruppe(n) oder Einrichtung(en)') ?></legend> + + <?= $this->render_partial('consultation/admin/block-responsibilities.php', compact('responsible')) ?> + </fieldset> +<? endif; ?> + + <fieldset> + <legend><?= _('Weitere Einstellungen') ?></legend> <label> <?= _('Information zu den Terminen in diesem Block') ?> diff --git a/app/views/consultation/admin/edit.php b/app/views/consultation/admin/edit.php new file mode 100644 index 0000000..6f1911a --- /dev/null +++ b/app/views/consultation/admin/edit.php @@ -0,0 +1,34 @@ +<form action="<?= $controller->store_edited($block, $page) ?>" method="post" class="default"> + <?= CSRFProtection::tokenTag() ?> + + <?= MessageBox::info( + _('Das Ändern der Informationen wird auch alle Termine dieses Blocks ändern.') + )->hideClose() ?> + + <fieldset> + <legend><?= _('Terminblock bearbeiten') ?></legend> + + <label> + <span class="required"><?= _('Ort') ?></span> + <input required type="text" name="room" placeholder="<?= _('Ort') ?>" + value="<?= htmlReady($block->room) ?>"> + </label> + + <label> + <?=_('Information zu den Terminen in diesem Block') ?> (<?= _('Öffentlich einsehbar') ?>) + <textarea name="note"><?= htmlReady($block->note ) ?></textarea> + </label> + + <? if ($responsible): ?> + <?= $this->render_partial('consultation/admin/block-responsibilities.php', compact('responsible', 'block')) ?> + <? endif; ?> + </fieldset> + + <footer data-dialog-button> + <?= Studip\Button::createAccept(_('Speichern')) ?> + <?= Studip\LinkButton::createCancel( + _('Abbrechen'), + $controller->indexURL($page) + ) ?> + </footer> +</form> diff --git a/app/views/consultation/admin/edit_room.php b/app/views/consultation/admin/edit_room.php index 6c52436..e69de29 100644 --- a/app/views/consultation/admin/edit_room.php +++ b/app/views/consultation/admin/edit_room.php @@ -1,21 +0,0 @@ -<form action="<?= $controller->store_room($block, $page) ?>" method="post" class="default"> - <?= CSRFProtection::tokenTag() ?> - - <fieldset> - <legend><?= _('Ort des Terminblocks bearbeiten') ?></legend> - - <label> - <span class="required"><?= _('Ort') ?></span> - <input required type="text" name="room" placeholder="<?= _('Ort') ?>" - value="<?= htmlReady($block->room) ?>"> - </label> - </fieldset> - - <footer data-dialog-button> - <?= Studip\Button::createAccept(_('Speichern')) ?> - <?= Studip\LinkButton::createCancel( - _('Abbrechen'), - $controller->indexURL($page) - ) ?> - </footer> -</form> diff --git a/app/views/consultation/admin/index.php b/app/views/consultation/admin/index.php index 5d0a7da..6ee7550 100644 --- a/app/views/consultation/admin/index.php +++ b/app/views/consultation/admin/index.php @@ -45,13 +45,8 @@ </th> <th class="actions"> <?= ActionMenu::get()->addLink( - $controller->edit_roomURL($block['block'], $page), - _('Raum bearbeiten'), - Icon::create('edit'), - ['data-dialog' => 'size=auto'] - )->addLink( - $controller->noteURL($block['block'], 0, $page), - _('Information bearbeiten'), + $controller->editURL($block['block'], 0, $page), + _('Bearbeiten'), Icon::create('edit'), ['data-dialog' => 'size=auto'] )->addLink( diff --git a/app/views/consultation/block-description.php b/app/views/consultation/block-description.php index df3d0bd..4d037ff 100644 --- a/app/views/consultation/block-description.php +++ b/app/views/consultation/block-description.php @@ -6,13 +6,6 @@ date('H:i', $block->end) ) ?> -<? if ($block->teacher): ?> -/ -<a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $block->teacher->username]) ?>"> - <?= htmlReady($block->teacher->getFullName()) ?> -</a> -<? endif; ?> - (<?= formatLinks($block->room) ?>) <? if ($block->show_participants): ?> @@ -20,6 +13,19 @@ <?= tooltipIcon(_('Die Namen der buchenden Person sind sichtbar')) ?> <? endif; ?> +<? if (count($block->responsibilities) > 0): ?> +<br> +<ul class="narrow list-csv"> +<? foreach ($block->responsibilities as $responsibility): ?> + <li> + <a href="<?= URLHelper::getLink($responsibility->getURL(), [], true) ?>"> + <?= htmlReady($responsibility->getName()) ?> + </a> + </li> +<? endforeach; ?> +</ul> +<? endif; ?> + <? if ($block->note): ?> <br> <small> |
