diff --git a/controllers/categories.php b/controllers/categories.php index a566392c5c2b3f2c4e39049b2ead4f3087b5b146..912445c8c0fc342cb8b236f4a43207a462e45353 100644 --- a/controllers/categories.php +++ b/controllers/categories.php @@ -328,25 +328,29 @@ class CategoriesController extends BookableController { */ public function buildSidebar(): void { + $user_id = User::findCurrent()->user_id; + $actions = new ActionsWidget(); $actions->setTitle('Ansichten'); - if (Request::option('view')) { - $_SESSION['Bookable']['categories_view'] = Request::option('view'); + if (Request::option('layout')) { + $layout = Request::option('layout') === 'card' ? 1 : 0; + UserConfig::get($user_id)->store('BOOKABLE_TILE_LAYOUT', $layout); } - if (Request::option('view') === 'card' - || (!empty($_SESSION['Bookable']['categories_view']) && $_SESSION['Bookable']['categories_view'] === 'card')) { + $this->tile_layout = UserConfig::get($user_id)->BOOKABLE_TILE_LAYOUT; + + if ($this->tile_layout) { $actions->addLink( _('Listenansicht'), - URLHelper::getURL('', ['view' => 'list', 'search_keyword' => Request::get('search_keyword')]), + URLHelper::getURL('', ['layout' => 'list', 'search_keyword' => Request::get('search_keyword')]), Icon::create('view-list') ); } else { $actions->addLink( _('Kachelansicht'), - URLHelper::getURL('', ['view' => 'card', 'search_keyword' => Request::get('search_keyword')]), + URLHelper::getURL('', ['layout' => 'card', 'search_keyword' => Request::get('search_keyword')]), Icon::create('block-gallery') ); } diff --git a/migrations/03_add_log_actions.php b/migrations/03_add_log_actions.php index 71658b5be99d6707f5f1d812505a20c1ea281744..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/migrations/03_add_log_actions.php +++ b/migrations/03_add_log_actions.php @@ -1,19 +0,0 @@ -<?php - -final class AddLogActions extends Migration -{ - public function up() - { - StudipLog::registerActionPlugin( - 'BOOKABLE_BOOKING_STATUS', - 'Der Buchungsstand Änderung', - '%user ändert/setzt Buchung(ID: %affected) im %sem(%coaffected). %info', - Bookable::class - ); - } - - public function down() - { - StudipLog::unregisterAction('BOOKABLE_BOOKING_STATUS'); - } -} diff --git a/migrations/04_add_user_config.php b/migrations/04_add_user_config.php new file mode 100644 index 0000000000000000000000000000000000000000..853e18aa1e9a39dc06ad745f4e37cec4d14159bf --- /dev/null +++ b/migrations/04_add_user_config.php @@ -0,0 +1,31 @@ +<?php + +final class AddUserConfig extends Migration +{ + public function up() + { + DBManager::get()->execute( + "INSERT IGNORE INTO `config` VALUES (:field, :value, :type, :range, :section, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)", + [ + 'field' => 'BOOKABLE_TILE_LAYOUT', + 'value' => 1, + 'type' => 'boolean', + 'range' => 'user', + 'section' => 'Bookable', + 'description' => 'Konfiguration der Ansicht der Kategorien' + ] + ); + } + + public function down() + { + $sql = "DELETE `config`, `config_values` FROM `config` + LEFT JOIN `config_values` USING (`field`) + WHERE `field` = :field"; + + DBManager::get()->execute( + $sql, + ['field' => 'BOOKABLE_TILE_LAYOUT'] + ); + } +} diff --git a/views/categories/index.php b/views/categories/index.php index f943e5d219440154431c0f20ad5297105ac04e05..25c60c9ececc2750a2100e78c7d26c73b6263ac8 100644 --- a/views/categories/index.php +++ b/views/categories/index.php @@ -4,11 +4,12 @@ * @var Bookable\Models\BookableCategory[] $categories * @var Bookable $plugin * @var bool $is_admin + * @var bool $tile_layout */ ?> <div class="bookable "> - <? if (Request::get('view') === 'card' || (!empty($_SESSION['Bookable']['categories_view']) && $_SESSION['Bookable']['categories_view'] === 'card')) : ?> + <? if ($tile_layout) : ?> <ul class="categories-card-container use-utility-classes"> <? foreach ($categories as $category): ?> <li>