diff --git a/app/controllers/activityfeed.php b/app/controllers/activityfeed.php index 1ea00a06db1fb88e688728ca2b7e79b57270558e..8db677a58bc930370e76d31f296eebcc97ffbf5b 100644 --- a/app/controllers/activityfeed.php +++ b/app/controllers/activityfeed.php @@ -4,6 +4,39 @@ use \Studip\Activity\ActivityProvider; class ActivityfeedController extends AuthenticatedController { + public function configuration_action() + { + $this->config = WidgetHelper::getWidgetUserConfig($GLOBALS['user']->id, 'ACTIVITY_FEED'); + $this->modules = $this->getAllModules(); + $this->context_translations = [ + Context::COURSE => _('Veranstaltungen'), + Context::INSTITUTE => _('Einrichtungen'), + Context::USER => _('Persönlich'), + 'system' => _('Global') + ]; + + PageLayout::setTitle(_('Aktivitäten konfigurieren')); + + $form = Studip\Forms\Form::create(); + + foreach ($this->modules as $context => $provider) { + $fieldset = new Studip\Forms\Fieldset($this->context_translations[$context]); + + $checkboxes = new Studip\Forms\MulticheckboxInput( + "provider[{$context}]", + 'foo', + $this->config[$context] ?? [], + ['options' => $provider] + ); + + $fieldset->addInput($checkboxes); + + $form->addPart($fieldset); + } + + $this->form = $form; + } + public function save_action() { if (Config::get()->ACTIVITY_FEED === NULL) { @@ -78,18 +111,4 @@ class ActivityfeedController extends AuthenticatedController return $modules; } - - public function configuration_action() - { - $this->config = WidgetHelper::getWidgetUserConfig($GLOBALS['user']->id, 'ACTIVITY_FEED'); - $this->modules = $this->getAllModules(); - $this->context_translations = [ - Context::COURSE => _('Veranstaltungen'), - Context::INSTITUTE => _('Einrichtungen'), - Context::USER => _('Persönlich'), - 'system' => _('Global') - ]; - - PageLayout::setTitle(_('Aktivitäten konfigurieren')); - } } diff --git a/app/views/activityfeed/configuration.php b/app/views/activityfeed/configuration.php index ceb87eb2180dd4251d043433bfa70ff1794c8a9d..2197525410fa6ee8ee20e3790fe11b9b89026330 100644 --- a/app/views/activityfeed/configuration.php +++ b/app/views/activityfeed/configuration.php @@ -3,28 +3,29 @@ * @var ActivityfeedController $controller * @var array $modules * @var array $context_translations + * @var \Studip\Forms\Form $form */ ?> -<div id="activityEdit"> - <form id="configure_activity" action="<?= $controller->link_for('activityfeed/save') ?>" method="post" class="default" data-dialog> - <h1><?= _("Anzuzeigende Bereiche:") ?></h1> +<?= $form->render() ?> - <? foreach ($modules as $context => $provider): ?> - <fieldset> - <legend><?= htmlReady($context_translations[$context]) ?></legend> - <? foreach ($provider as $prv_id => $prv_name) : ?> - <label> - <input type="checkbox" name="provider[<?= $context ?>][]" value="<?= htmlReady($prv_id) ?>" - <?= empty($config) || (is_array($config[$context]) && in_array($prv_id, $config[$context])) ? 'checked' : ''?>> - <?= htmlReady($prv_name) ?> - </label> - <? endforeach ?> - </fieldset> - <? endforeach; ?> +<form action="<?= $controller->link_for('activityfeed/save') ?>" method="post" class="default" data-dialog> + <h1><?= _("Anzuzeigende Bereiche:") ?></h1> - <footer data-dialog-button> - <?= Studip\Button::createAccept(_('Speichern')) ?> - <?= Studip\Button::createCancel(_('Abbrechen'), URLHelper::getLink('dispatch.php/start')) ?> - </footer> - </form> -</div> +<? foreach ($modules as $context => $provider): ?> + <fieldset> + <legend><?= htmlReady($context_translations[$context]) ?></legend> + <? foreach ($provider as $prv_id => $prv_name) : ?> + <label> + <input type="checkbox" name="provider[<?= $context ?>][]" value="<?= htmlReady($prv_id) ?>" + <?= empty($config) || (is_array($config[$context]) && in_array($prv_id, $config[$context])) ? 'checked' : ''?>> + <?= htmlReady($prv_name) ?> + </label> + <? endforeach ?> + </fieldset> +<? endforeach; ?> + + <footer data-dialog-button> + <?= Studip\Button::createAccept(_('Speichern')) ?> + <?= Studip\Button::createCancel(_('Abbrechen'), URLHelper::getLink('dispatch.php/start')) ?> + </footer> +</form> diff --git a/lib/classes/forms/MulticheckboxInput.php b/lib/classes/forms/MulticheckboxInput.php new file mode 100644 index 0000000000000000000000000000000000000000..62818b74055202a15283414b3775a054f6062875 --- /dev/null +++ b/lib/classes/forms/MulticheckboxInput.php @@ -0,0 +1,31 @@ +<?php + +namespace Studip\Forms; + +class MulticheckboxInput extends Input +{ + public function render() + { + $options = $this->extractOptionsFromAttributes($this->attributes); + + $name = $this->name; + if (substr($name, -2) === '[]') { + $name .= substr($name, 0, -2); + } + + $template = $GLOBALS['template_factory']->open('forms/multiselect_input'); + $template->title = $this->title; + $template->name = $name; + $template->value = $this->value; + $template->id = md5(uniqid()); + $template->required = $this->required; + $template->attributes = arrayToHtmlAttributes($this->attributes); + $template->options = $options; + return $template->render(); + } + + public function getRequestValue() + { + return \Request::getArray($this->name); + } +} diff --git a/templates/forms/checkbox_input.php b/templates/forms/checkbox_input.php index b689d696f8e32b50b91cc8f6f78b531b3f303b6f..50b2907d029b9d5a15be6fc33675518d83d290b4 100644 --- a/templates/forms/checkbox_input.php +++ b/templates/forms/checkbox_input.php @@ -1,5 +1,5 @@ <input type="hidden" name="<?= htmlReady($name) ?>" value="0"> - <label<?= ($required ? ' class="studiprequired"' : '') ?>> +<label<?= ($required ? ' class="studiprequired"' : '') ?>> <input type="checkbox" v-model="<?= htmlReady($this->name) ?>" name="<?= htmlReady($this->name) ?>"