From 9dcac1b5473709f6f5d2843fa4120ff2050e8074 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+github@gmail.com> Date: Mon, 8 Nov 2021 17:39:44 +0100 Subject: [PATCH] make studygroup terms translatable, fixes #400 --- app/controllers/course/studygroup.php | 15 +++----- app/views/course/studygroup/globalmodules.php | 2 +- .../5.1.9_tic11418_studygroup_terms_i18n.php | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 db/migrations/5.1.9_tic11418_studygroup_terms_i18n.php diff --git a/app/controllers/course/studygroup.php b/app/controllers/course/studygroup.php index 80f71988ebe..d2d347819bc 100644 --- a/app/controllers/course/studygroup.php +++ b/app/controllers/course/studygroup.php @@ -860,17 +860,10 @@ class Course_StudygroupController extends AuthenticatedController // get institutes $institutes = StudygroupModel::getInstitutes(); - $default_inst = Config::Get()->STUDYGROUP_DEFAULT_INST; + $default_inst = $this->flash['institute'] ?? Config::Get()->STUDYGROUP_DEFAULT_INST; // Nutzungsbedingungen - $terms = Config::Get()->STUDYGROUP_TERMS; - - if ($this->flash['institute']) { - $default_inst = $this->flash['institute']; - } - if ($this->flash['terms']) { - $terms = $this->flash['terms']; - } + $terms = $this->flash['terms'] ?? Config::Get()->STUDYGROUP_TERMS; PageLayout::setTitle(_('Verwaltung studentischer Arbeitsgruppen')); Navigation::activateItem('/admin/config/studygroup'); @@ -910,7 +903,7 @@ class Course_StudygroupController extends AuthenticatedController if ($errors) { $this->flash['messages'] = ['error' => ['title' => 'Die Studiengruppen konnten nicht aktiviert werden!', 'details' => $errors]]; $this->flash['institute'] = Request::get('institute'); - $this->flash['terms'] = Request::get('terms'); + $this->flash['terms'] = Request::i18n('terms'); } if (!$errors) { @@ -922,7 +915,7 @@ class Course_StudygroupController extends AuthenticatedController if (Request::get('institute')) { $cfg->store('STUDYGROUP_DEFAULT_INST', Request::get('institute')); - $cfg->store('STUDYGROUP_TERMS', Request::get('terms')); + $cfg->store('STUDYGROUP_TERMS', Request::i18n('terms')); PageLayout::postSuccess(_('Die Einstellungen wurden gespeichert!')); } else { PageLayout::postError(_('Fehler beim Speichern der Einstellung!')); diff --git a/app/views/course/studygroup/globalmodules.php b/app/views/course/studygroup/globalmodules.php index 391a3095b2a..a081294d8ad 100644 --- a/app/views/course/studygroup/globalmodules.php +++ b/app/views/course/studygroup/globalmodules.php @@ -71,7 +71,7 @@ use Studip\Button, Studip\LinkButton; <label> <?= _('Geben Sie hier Nutzungsbedingungen für die Studiengruppen ein. ' . 'Diese müssen akzeptiert werden, bevor eine Studiengruppe angelegt werden kann.') ?> - <textarea name="terms"><?= htmlReady($terms) ?></textarea> + <?= I18N::textarea('terms', $terms) ?> </label> </fieldset> <footer> diff --git a/db/migrations/5.1.9_tic11418_studygroup_terms_i18n.php b/db/migrations/5.1.9_tic11418_studygroup_terms_i18n.php new file mode 100644 index 00000000000..7537d5112e5 --- /dev/null +++ b/db/migrations/5.1.9_tic11418_studygroup_terms_i18n.php @@ -0,0 +1,34 @@ +<?php +/** + * @author Jan-Hendrik Willms <tleilax+studip@gmail.com> + * @see https://develop.studip.de/trac/ticket/11418 + */ +class Tic11418StudygroupTermsI18n extends Migration +{ + public function description() + { + return 'Changes config type to i18n for field STUDYGROUP_TERMS'; + } + + protected function up() + { + $query = "UPDATE `config` + SET `type` = 'i18n' + WHERE `field` = 'STUDYGROUP_TERMS'"; + DBManager::get()->exec($query); + } + + protected function down() + { + $query = "DELETE FROM `i18n` + WHERE `object_id` = MD5('STUDYGROUP_TERMS') + AND `table` = 'config' + AND `field` = 'value'"; + DBManager::get()->exec($query); + + $query = "UPDATE `config` + SET `type` = 'string' + WHERE `field` = 'STUDYGROUP_TERMS'"; + DBManager::get()->exec($query); + } +} -- GitLab