xref: /webtrees/app/Http/RequestHandlers/SelectTheme.php (revision d403609d9adfb78373074e21cba0e7fd0ec71fde)
1a0801ffbSGreg Roach<?php
23976b470SGreg Roach
3a0801ffbSGreg Roach/**
4a0801ffbSGreg Roach * webtrees: online genealogy
5a0801ffbSGreg Roach * Copyright (C) 2019 webtrees development team
6a0801ffbSGreg Roach * This program is free software: you can redistribute it and/or modify
7a0801ffbSGreg Roach * it under the terms of the GNU General Public License as published by
8a0801ffbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a0801ffbSGreg Roach * (at your option) any later version.
10a0801ffbSGreg Roach * This program is distributed in the hope that it will be useful,
11a0801ffbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a0801ffbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a0801ffbSGreg Roach * GNU General Public License for more details.
14a0801ffbSGreg Roach * You should have received a copy of the GNU General Public License
15a0801ffbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a0801ffbSGreg Roach */
17a0801ffbSGreg Roachdeclare(strict_types=1);
18a0801ffbSGreg Roach
19a0801ffbSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
20a0801ffbSGreg Roach
21a0801ffbSGreg Roachuse Fig\Http\Message\StatusCodeInterface;
22a0801ffbSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
23a0801ffbSGreg Roachuse Fisharebest\Webtrees\Session;
24a0801ffbSGreg Roachuse Psr\Http\Message\ResponseInterface;
25a0801ffbSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
26a0801ffbSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
273976b470SGreg Roach
28a0801ffbSGreg Roachuse function response;
29a0801ffbSGreg Roach
30a0801ffbSGreg Roach/**
31a0801ffbSGreg Roach * Select a new theme for the current session.
32a0801ffbSGreg Roach */
33a0801ffbSGreg Roachclass SelectTheme implements RequestHandlerInterface, StatusCodeInterface
34a0801ffbSGreg Roach{
35a0801ffbSGreg Roach    /**
36a0801ffbSGreg Roach     * @param ServerRequestInterface $request
37a0801ffbSGreg Roach     *
38a0801ffbSGreg Roach     * @return ResponseInterface
39a0801ffbSGreg Roach     */
40a0801ffbSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
41a0801ffbSGreg Roach    {
42*d403609dSGreg Roach        $user  = $request->getAttribute('user');
43a0801ffbSGreg Roach        $theme = $request->getParsedBody()['theme'];
44a0801ffbSGreg Roach
45a0801ffbSGreg Roach        Session::put('theme', $theme);
46*d403609dSGreg Roach        $user->setPreference('theme', $theme);
47a0801ffbSGreg Roach
48a0801ffbSGreg Roach        return response('', self::STATUS_NO_CONTENT);
49a0801ffbSGreg Roach    }
50a0801ffbSGreg Roach}
51