upstream V3 development https://www.gnusocial.rocks/v3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

94 lines
2.9 KiB

  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace Plugin\ProfileColor\Controller;
  19. use App\Core\DB\DB;
  20. use App\Core\Form;
  21. use App\Util\Exception\ServerException;
  22. use function App\Core\I18n\_m;
  23. use App\Util\Common;
  24. use App\Util\Exception\RedirectException;
  25. use Plugin\ProfileColor\Entity;
  26. use Symfony\Component\Form\Extension\Core\Type\ColorType;
  27. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  28. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  29. use Symfony\Component\HttpFoundation\Request;
  30. /**
  31. * Profile Color controller
  32. *
  33. * @package GNUsocial
  34. * @category ProfileColor
  35. *
  36. * @author Daniel Brandao <up201705812@fe.up.pt>
  37. * @author Eliseu Amaro <mail@eliseuama.ro>
  38. * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org
  39. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  40. */
  41. class ProfileColor
  42. {
  43. /**
  44. * Change Profile color background
  45. * @param Request $request
  46. * @return array
  47. * @throws RedirectException
  48. * @throws ServerException
  49. */
  50. public static function profileColorSettings(Request $request)
  51. {
  52. $user = Common::user();
  53. $actor_id = $user->getId();
  54. $pcolor = DB::findOneBy('profile_color', ['actor_id' => $actor_id]);
  55. $form = Form::create([
  56. ['color', ColorType::class, [
  57. 'html5' => true,
  58. 'data' => "#000000",
  59. 'label' => _m('Profile Color'),
  60. 'help' => _m('Choose your Profile Color')]
  61. ],
  62. ['hidden', HiddenType::class, []],
  63. ['save_profile_color', SubmitType::class, ['label' => _m('Submit')]],
  64. ]);
  65. $form->handleRequest($request);
  66. if ($form->isSubmitted() && $form->isValid()) {
  67. if ($pcolor !== null) {
  68. DB::remove($pcolor);
  69. DB::flush();
  70. }
  71. $data = $form->getData();
  72. $pcolor = Entity\ProfileColor::create(['actor_id' => $actor_id, 'color' => $data['color']]);
  73. DB::persist($pcolor);
  74. DB::flush();
  75. throw new RedirectException();
  76. }
  77. return ['_template' => 'profileColor/profileColorSettings.html.twig', 'profile_color' => $form->createView()];
  78. }
  79. }