2020-12-17 04:27:41 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// {{{ License
|
|
|
|
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
|
|
|
namespace Plugin\ProfileColor\Controller;
|
|
|
|
|
2020-12-17 08:19:52 +09:00
|
|
|
use App\Core\DB\DB;
|
2020-12-17 04:27:41 +09:00
|
|
|
use App\Core\Form;
|
|
|
|
use function App\Core\I18n\_m;
|
2020-12-17 08:19:52 +09:00
|
|
|
use App\Util\Common;
|
2020-12-19 04:45:45 +09:00
|
|
|
use App\Util\Exception\RedirectException;
|
2021-09-07 03:49:03 +09:00
|
|
|
use Plugin\ProfileColor\Entity;
|
2020-12-17 08:19:52 +09:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ColorType;
|
2020-12-17 04:27:41 +09:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
/**
|
2020-12-17 08:19:52 +09:00
|
|
|
* Profile Color controller
|
2020-12-17 04:27:41 +09:00
|
|
|
*
|
|
|
|
* @package GNUsocial
|
2020-12-17 08:19:52 +09:00
|
|
|
* @category ProfileColor
|
2020-12-17 04:27:41 +09:00
|
|
|
*
|
|
|
|
* @author Daniel Brandao <up201705812@fe.up.pt>
|
|
|
|
* @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
class ProfileColor
|
|
|
|
{
|
|
|
|
/**
|
2020-12-20 05:52:36 +09:00
|
|
|
* Add/change profile color
|
2020-12-17 04:27:41 +09:00
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
*
|
2020-12-20 05:52:36 +09:00
|
|
|
* @throws RedirectException
|
2020-12-17 04:27:41 +09:00
|
|
|
*
|
|
|
|
* @return array template
|
|
|
|
*/
|
2021-07-30 04:20:32 +09:00
|
|
|
public static function profileColorSettings(Request $request)
|
2020-12-17 04:27:41 +09:00
|
|
|
{
|
2020-12-17 08:19:52 +09:00
|
|
|
$user = Common::user();
|
|
|
|
$actor_id = $user->getId();
|
2021-09-18 11:22:27 +09:00
|
|
|
$pcolor = DB::find('profile_color', ['actor_id' => $actor_id]);
|
2020-12-17 08:19:52 +09:00
|
|
|
$color = '#000000';
|
|
|
|
if ($pcolor != null) {
|
2021-09-25 19:17:56 +09:00
|
|
|
$color = $pcolor;
|
2020-12-17 08:19:52 +09:00
|
|
|
}
|
|
|
|
|
2020-12-17 04:27:41 +09:00
|
|
|
$form = Form::create([
|
2020-12-20 05:52:36 +09:00
|
|
|
['color', ColorType::class, ['data' => $color, 'label' => _m('Profile Color'), 'help' => _m('Choose your Profile Color')] ],
|
2020-12-17 04:27:41 +09:00
|
|
|
['hidden', HiddenType::class, []],
|
2021-08-19 02:38:54 +09:00
|
|
|
['save_profile_color', SubmitType::class, ['label' => _m('Submit')]],
|
2020-12-17 04:27:41 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
$data = $form->getData();
|
2020-12-17 08:19:52 +09:00
|
|
|
|
2021-09-25 19:17:56 +09:00
|
|
|
if ($pcolor !== null) {
|
2020-12-17 08:19:52 +09:00
|
|
|
DB::remove($pcolor);
|
|
|
|
DB::flush();
|
|
|
|
}
|
|
|
|
|
2021-09-25 19:17:56 +09:00
|
|
|
$pcolor = Entity\ProfileColor::create(['actor_id' => $actor_id, 'profile_color' => $data['color']]);
|
2020-12-17 08:19:52 +09:00
|
|
|
DB::persist($pcolor);
|
|
|
|
DB::flush();
|
2020-12-19 04:45:45 +09:00
|
|
|
throw new RedirectException();
|
2020-12-17 04:27:41 +09:00
|
|
|
}
|
|
|
|
|
2021-09-25 19:17:56 +09:00
|
|
|
return ['_template' => 'profileColor/profileColorSettings.html.twig', 'form' => $form->createView()];
|
2020-12-17 04:27:41 +09:00
|
|
|
}
|
|
|
|
}
|