src/Controller/Webmaster/AccountController.php line 97

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Webmaster;
  3. use App\Dictionary\TaxNumber;
  4. use App\Dictionary\WebmasterProperty;
  5. use App\Form\Webmaster\MyDataForm;
  6. use App\Security\ApiUser;
  7. use App\Service\Client\User\PersonService;
  8. use App\Service\Client\User\WebmasterPropertyService;
  9. use App\Service\Client\User\WebmasterService;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. /**
  18.  * @Route("/webmaster/account")
  19.  */
  20. class AccountController extends AbstractController
  21. {
  22.     /**
  23.      * @var WebmasterService
  24.      */
  25.     protected WebmasterService $service;
  26.     /**
  27.      * @var PersonService
  28.      */
  29.     protected PersonService $personService;
  30.     /**
  31.      * @var WebmasterPropertyService
  32.      */
  33.     protected WebmasterPropertyService $webmasterPropertyService;
  34.     /**
  35.      * @param WebmasterService $service
  36.      * @param PersonService $personService
  37.      * @param WebmasterPropertyService $propertyService
  38.      */
  39.     public function __construct(WebmasterService $servicePersonService $personService,
  40.                                 WebmasterPropertyService $propertyService)
  41.     {
  42.         $this->service $service;
  43.         $this->personService $personService;
  44.         $this->webmasterPropertyService $propertyService;
  45.     }
  46.     /**
  47.      * @Route("/meine-daten", methods={"GET", "POST"})
  48.      * @param Request $request
  49.      * @Template()
  50.      * @return array|RedirectResponse
  51.      * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
  52.      * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
  53.      * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
  54.      * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
  55.      */
  56.     public function mydata(Request $request)
  57.     {
  58.         $this->denyAccessUnlessGranted('ROLE_WEBMASTER');
  59.         /**
  60.          * @var $user ApiUser
  61.          */
  62.         $user $this->getUser();
  63.         $form $this->createForm(MyDataForm::class, [], []);
  64.         $form->handleRequest($request);
  65.         if ($form->isSubmitted() && $form->isValid()) {
  66.             $data $form->getData();
  67.             if($this->personService->createPersonSubmissionForAccount($user->getAccountId(), $data)) {
  68.                 $this->addFlash('success''Datenänderung zur Prüfung eingereicht.');
  69.             }
  70.             return $this->redirectToRoute($request->attributes->get('_route'));
  71.         }
  72.         return [
  73.             'form' => $form->createView(),
  74.             'person' => $this->personService->getCurrentPersonForWebmaster($user->getWebmasterId()),
  75.             'taxNumberDictionary' => TaxNumber::getDictionary()
  76.         ];
  77.     }
  78.     /**
  79.      * @Route("/kontakt")
  80.      * @Template()
  81.      * @return array
  82.      */
  83.     public function contact(): array
  84.     {
  85.         $this->denyAccessUnlessGranted('ROLE_WEBMASTER');
  86.         return [
  87.         ];
  88.     }
  89.     /**
  90.      * @Route("/einstellungen")
  91.      * @Template()
  92.      * @param Request $request
  93.      * @return array|JsonResponse
  94.      */
  95.     public function settings(Request $request)
  96.     {
  97.         $this->denyAccessUnlessGranted('ROLE_WEBMASTER');
  98.         /**
  99.          * @var $user ApiUser
  100.          */
  101.         $user $this->getUser();
  102.         $webmasterId $user->getWebmasterId();
  103.         $fields = [
  104.             WebmasterProperty::MINIMUM_PAYOUT_LIMIT => [
  105.                 'label' => 'Auszahlungslimit',
  106.                 'value' => $this->webmasterPropertyService->getPropertyValueForWebmaster(WebmasterProperty::MINIMUM_PAYOUT_LIMIT$webmasterId),
  107.                 'type' => 'select',
  108.                 'options' => [
  109.                     501002505001000
  110.                 ]
  111.             ],
  112.             WebmasterProperty::SKYPE_USERNAME => [
  113.                 'label' => 'Skype Benutzername für Support-Fragen',
  114.                 'value' => $this->webmasterPropertyService->getPropertyValueForWebmaster(WebmasterProperty::SKYPE_USERNAME$webmasterId),
  115.                 'type' => 'text'
  116.             ]
  117.         ];
  118.         if($request->isMethod('POST')) {
  119.             $property trim($request->request->get('property'));
  120.             $value trim($request->request->get('value'));
  121.             $success $this->webmasterPropertyService->updatePropertyValue($property$user->getWebmasterId(), $value);
  122.             return new JsonResponse([
  123.                 'message' => $success 'Daten gespeichert' 'Fehler beim Speichern'
  124.             ], $success Response::HTTP_OK Response::HTTP_INTERNAL_SERVER_ERROR);
  125.         }
  126.         return [
  127.             'fields' => $fields
  128.         ];
  129.     }
  130. }