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,
$category = Kategorie::find($id); function ($input) {
$category->name = $data['name']; return Studip\Markup::purifyHtml($input);
$category->content = Studip\Markup::purifyHtml($data['content']); }
if ($category->isDirty() && $category->store()) { );
$changed = true;
Visibility::renamePrivacySetting('kat_' . $category->id, $category->name); if ($category->store()) {
} $changed = true;
} 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,61 +8,57 @@ ...@@ -8,61 +8,57 @@
<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): ?>
<input type="hidden" name="ids[]" value="<?= htmlReady($category->id) ?>">
<fieldset> <fieldset>
<legend><?= htmlReady($category->name) ?></legend> <legend style="display: flex; flex-wrap: nowrap; justify-content: space-between">
<span><?= htmlReady($category->name) ?></span>
<span>
<? if ($index > 0): ?>
<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')]) ?>
</a>
<? else: ?>
<?= Icon::create('arr_2up', 'inactive')->asImg(['class' => 'text-top']) ?>
<? endif; ?>
<table style="width: 100%"> <? if ($index < $count - 1): ?>
<colgroup> <a href="<?= $controller->url_for('settings/categories/swap', $category->id, $categories[$index + 1]->id) ?>">
<col> <?= Icon::create('arr_2down', 'sort')->asImg(['class' => 'text-top', 'title' =>_('Kategorie nach unten verschieben')]) ?>
<col width="100px"> </a>
</colgroup> <? else: ?>
<tbody> <?= Icon::create('arr_2down', 'inactive')->asImg(['class' => 'text-top']) ?>
<tr> <? endif; ?>
<td>
<div>
(<?= $visibilities[$category->id] ?>)
</div>
<label> <a href="<?= $controller->url_for('settings/categories/delete', $category->id) ?>">
<?= _('Name') ?> <?= Icon::create('trash')->asImg(['class' => 'text-top', 'title' => _('Kategorie löschen')]) ?>
<input required type="text" name="categories[<?= $category->id ?>][name]" id="name<?= $index ?>" </a>
aria-label="<?= _('Name der Kategorie') ?>" style="width: 100%" </span>
value="<?= htmlReady($category->name) ?>"> </legend>
</label>
<label> <p>
<?= _('Inhalt') ?> (<?= $visibilities[$category->id] ?>)
</p>
<textarea id="content<?= $index ?>" name="categories[<?= $category->id ?>][content]" <label>
class="resizable add_toolbar wysiwyg size-l" style="width: 100%; height: 200px;" <?= _('Name') ?>
aria-label="<?= _('Inhalt der Kategorie:') ?>" <?= I18N::input("category-name-{$category->id}", $category->name, [
><?= wysiwygReady($category->content) ?></textarea> 'aria-label' => _('Name der Kategorie'),
</label> 'class' => 'size-l',
</td> 'id' => "name{$index}",
<td style="vertical-align: top"> 'required' => '',
<? if ($index > 0): ?> ]) ?>
<a href="<?= $controller->url_for('settings/categories/swap', $category->id, $last->id) ?>"> </label>
<?= Icon::create('arr_2up', 'sort')->asImg(['class' => 'text-top', 'title' =>_('Kategorie nach oben verschieben')]) ?>
</a>
<? else: ?>
<?= Icon::create('arr_2up', 'inactive')->asImg(['class' => 'text-top']) ?>
<? endif; ?>
<? if ($index < $count - 1): ?> <label>
<a href="<?= $controller->url_for('settings/categories/swap', $category->id, $categories[$index + 1]->id) ?>"> <?= _('Inhalt') ?>
<?= Icon::create('arr_2down', 'sort')->asImg(['class' => 'text-top', 'title' =>_('Kategorie nach unten verschieben')]) ?>
</a>
<? else: ?>
<?= Icon::create('arr_2down', 'inactive')->asImg(['class' => 'text-top']) ?>
<? endif; ?>
<a href="<?= $controller->url_for('settings/categories/delete', $category->id) ?>"> <?= I18n::textarea("category-content-{$category->id}", $category->content, [
<?= Icon::create('trash')->asImg(['class' => 'text-top', 'title' => _('Kategorie löschen')]) ?> 'aria-label' => _('Inhalt der Kategorie:'),
</a> 'class' => 'resizable add_toolbar wysiwyg size-l',
</td> 'id' => "content{$index}",
</tr> ]) ?>
</tbody> </label>
</table>
</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.
Finish editing this message first!
Please register or to comment