Skip to content
Snippets Groups Projects
Commit 330ddc50 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

allow profile categories to be translated, fixes #1260

Closes #1260

Merge request studip/studip!769
parent d4927ddb
No related branches found
No related tags found
No related merge requests found
...@@ -135,23 +135,26 @@ class Settings_CategoriesController extends Settings_SettingsController ...@@ -135,23 +135,26 @@ class Settings_CategoriesController extends Settings_SettingsController
*/ */
public function store_action() public function store_action()
{ {
$request = Request::getInstance();
$changed = false; $changed = false;
$categories = $request['categories']; Kategorie::findEachMany(
foreach ($categories as $id => $data) { function (Kategorie $category) use (&$changed) {
if (empty($data['name'])) { $category->name = Request::i18n("category-name-{$category->id}");
PageLayout::postError(_('Kategorien ohne Namen können nicht gespeichert werden!')); $category->content = Request::i18n(
continue; "category-content-{$category->id}",
null,
function ($input) {
return Studip\Markup::purifyHtml($input);
} }
$category = Kategorie::find($id); );
$category->name = $data['name'];
$category->content = Studip\Markup::purifyHtml($data['content']); if ($category->store()) {
if ($category->isDirty() && $category->store()) {
$changed = true; $changed = true;
Visibility::renamePrivacySetting('kat_' . $category->id, $category->name); Visibility::renamePrivacySetting("kat_{$category->id}", $category->name->original());
}
} }
},
Request::optionArray('ids')
);
if ($changed) { if ($changed) {
PageLayout::postSuccess(_('Kategorien geändert!')); PageLayout::postSuccess(_('Kategorien geändert!'));
......
...@@ -8,38 +8,12 @@ ...@@ -8,38 +8,12 @@
<input type="hidden" name="studip_ticket" value="<?= get_ticket() ?>"> <input type="hidden" name="studip_ticket" value="<?= get_ticket() ?>">
<? foreach ($categories as $index => $category): ?> <? foreach ($categories as $index => $category): ?>
<fieldset> <input type="hidden" name="ids[]" value="<?= htmlReady($category->id) ?>">
<legend><?= htmlReady($category->name) ?></legend>
<table style="width: 100%">
<colgroup>
<col>
<col width="100px">
</colgroup>
<tbody>
<tr>
<td>
<div>
(<?= $visibilities[$category->id] ?>)
</div>
<label>
<?= _('Name') ?>
<input required type="text" name="categories[<?= $category->id ?>][name]" id="name<?= $index ?>"
aria-label="<?= _('Name der Kategorie') ?>" style="width: 100%"
value="<?= htmlReady($category->name) ?>">
</label>
<label>
<?= _('Inhalt') ?>
<textarea id="content<?= $index ?>" name="categories[<?= $category->id ?>][content]" <fieldset>
class="resizable add_toolbar wysiwyg size-l" style="width: 100%; height: 200px;" <legend style="display: flex; flex-wrap: nowrap; justify-content: space-between">
aria-label="<?= _('Inhalt der Kategorie:') ?>" <span><?= htmlReady($category->name) ?></span>
><?= wysiwygReady($category->content) ?></textarea> <span>
</label>
</td>
<td style="vertical-align: top">
<? if ($index > 0): ?> <? if ($index > 0): ?>
<a href="<?= $controller->url_for('settings/categories/swap', $category->id, $last->id) ?>"> <a href="<?= $controller->url_for('settings/categories/swap', $category->id, $last->id) ?>">
<?= Icon::create('arr_2up', 'sort')->asImg(['class' => 'text-top', 'title' =>_('Kategorie nach oben verschieben')]) ?> <?= Icon::create('arr_2up', 'sort')->asImg(['class' => 'text-top', 'title' =>_('Kategorie nach oben verschieben')]) ?>
...@@ -59,10 +33,32 @@ ...@@ -59,10 +33,32 @@
<a href="<?= $controller->url_for('settings/categories/delete', $category->id) ?>"> <a href="<?= $controller->url_for('settings/categories/delete', $category->id) ?>">
<?= Icon::create('trash')->asImg(['class' => 'text-top', 'title' => _('Kategorie löschen')]) ?> <?= Icon::create('trash')->asImg(['class' => 'text-top', 'title' => _('Kategorie löschen')]) ?>
</a> </a>
</td> </span>
</tr> </legend>
</tbody>
</table> <p>
(<?= $visibilities[$category->id] ?>)
</p>
<label>
<?= _('Name') ?>
<?= I18N::input("category-name-{$category->id}", $category->name, [
'aria-label' => _('Name der Kategorie'),
'class' => 'size-l',
'id' => "name{$index}",
'required' => '',
]) ?>
</label>
<label>
<?= _('Inhalt') ?>
<?= I18n::textarea("category-content-{$category->id}", $category->content, [
'aria-label' => _('Inhalt der Kategorie:'),
'class' => 'resizable add_toolbar wysiwyg size-l',
'id' => "content{$index}",
]) ?>
</label>
</fieldset> </fieldset>
<? $last = $category; <? $last = $category;
endforeach; ?> endforeach; ?>
......
<? <?php
/* /**
* Kategorie model * Kategorie model
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -12,14 +12,16 @@ ...@@ -12,14 +12,16 @@
* @category Stud.IP * @category Stud.IP
* @since 2.4 * @since 2.4
* *
* @property string kategorie_id database column * @property string $kategorie_id database column
* @property string id alias column for kategorie_id * @property string $id alias column for kategorie_id
* @property string range_id database column * @property string $range_id database column
* @property string name database column * @property string|I18NString $name database column
* @property string content database column * @property string|I18NString $content database column
* @property string mkdate database column * @property int $mkdate database column
* @property string chdate database column * @property int $chdate database column
* @property string priority database column * @property int $priority database column
*
* @property User $user
*/ */
class Kategorie extends SimpleORMap class Kategorie extends SimpleORMap
...@@ -32,6 +34,19 @@ class Kategorie extends SimpleORMap ...@@ -32,6 +34,19 @@ class Kategorie extends SimpleORMap
protected static function configure($config = []) protected static function configure($config = [])
{ {
$config['db_table'] = 'kategorien'; $config['db_table'] = 'kategorien';
$config['belongs_to'] = [
'user' => [
'class_name' => User::class,
'foreign_key' => 'range_id',
],
];
$config['i18n_fields'] = [
'name' => true,
'content' => true,
];
parent::configure($config); parent::configure($config);
} }
...@@ -39,9 +54,9 @@ class Kategorie extends SimpleORMap ...@@ -39,9 +54,9 @@ class Kategorie extends SimpleORMap
* Finds all categories of a specific user * Finds all categories of a specific user
* *
* @param string $user_id Id of the user * @param string $user_id Id of the user
* @return array of category objects * @return Kategorie[] of category objects
*/ */
public static function findByUserId($user_id) public static function findByUserId(string $user_id): array
{ {
return self::findByRange_id($user_id, 'ORDER BY priority'); return self::findByRange_id($user_id, 'ORDER BY priority');
} }
...@@ -50,9 +65,9 @@ class Kategorie extends SimpleORMap ...@@ -50,9 +65,9 @@ class Kategorie extends SimpleORMap
* Increases all category priorities of a user * Increases all category priorities of a user
* *
* @param string $user_id Id of the user * @param string $user_id Id of the user
* @return number of changed records * @return bool indicating if anything has changed
*/ */
public static function increasePrioritiesByUserId($user_id) public static function increasePrioritiesByUserId(string $user_id): bool
{ {
$query = "UPDATE kategorien SET priority = priority + 1 WHERE range_id = ?"; $query = "UPDATE kategorien SET priority = priority + 1 WHERE range_id = ?";
$statement = DBManager::get()->prepare($query); $statement = DBManager::get()->prepare($query);
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
* @property SimpleORMapCollection contacts has_many Contact * @property SimpleORMapCollection contacts has_many Contact
* @property UserInfo info has_one UserInfo * @property UserInfo info has_one UserInfo
* @property UserOnline online has_one UserOnline * @property UserOnline online has_one UserOnline
* @property Kategorie[]|SimpleORMapCollection $profile_categories has_many Kategorie
*/ */
class User extends AuthUserMd5 implements Range, PrivacyObject class User extends AuthUserMd5 implements Range, PrivacyObject
{ {
...@@ -158,11 +159,18 @@ class User extends AuthUserMd5 implements Range, PrivacyObject ...@@ -158,11 +159,18 @@ class User extends AuthUserMd5 implements Range, PrivacyObject
'class_name' => ConsultationBooking::class, 'class_name' => ConsultationBooking::class,
'on_delete' => 'delete', 'on_delete' => 'delete',
]; ];
$config['has_many']['profile_categories'] = [
'class_name' => Kategorie::class,
'assoc_foreign_key' => 'range_id',
'on_delete' => 'delete',
];
$config['has_many']['mvv_assignments'] = [ $config['has_many']['mvv_assignments'] = [
'class_name' => MvvContact::class, 'class_name' => MvvContact::class,
'assoc_foreign_key' => 'contact_id', 'assoc_foreign_key' => 'contact_id',
'on_delete' => 'delete', 'on_delete' => 'delete',
'order_by' => 'ORDER BY priority',
]; ];
$config['has_and_belongs_to_many']['domains'] = [ $config['has_and_belongs_to_many']['domains'] = [
...@@ -874,7 +882,7 @@ class User extends AuthUserMd5 implements Range, PrivacyObject ...@@ -874,7 +882,7 @@ class User extends AuthUserMd5 implements Range, PrivacyObject
} }
} }
foreach (Kategorie::findByUserId($this->id) as $category) { foreach ($this->profile_categories as $category) {
$homepage_elements['kat_' . $category->id] = [ $homepage_elements['kat_' . $category->id] = [
'name' => $category->name, 'name' => $category->name,
'visibility' => $homepage_visibility['kat_' . $category->id] ?: get_default_homepage_visibility($this->id), 'visibility' => $homepage_visibility['kat_' . $category->id] ?: get_default_homepage_visibility($this->id),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment