<?php
namespace App\Controller\Webmaster;
use App\Dictionary\TaxNumber;
use App\Dictionary\WebmasterProperty;
use App\Form\Webmaster\MyDataForm;
use App\Security\ApiUser;
use App\Service\Client\User\PersonService;
use App\Service\Client\User\WebmasterPropertyService;
use App\Service\Client\User\WebmasterService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/webmaster/account")
*/
class AccountController extends AbstractController
{
/**
* @var WebmasterService
*/
protected WebmasterService $service;
/**
* @var PersonService
*/
protected PersonService $personService;
/**
* @var WebmasterPropertyService
*/
protected WebmasterPropertyService $webmasterPropertyService;
/**
* @param WebmasterService $service
* @param PersonService $personService
* @param WebmasterPropertyService $propertyService
*/
public function __construct(WebmasterService $service, PersonService $personService,
WebmasterPropertyService $propertyService)
{
$this->service = $service;
$this->personService = $personService;
$this->webmasterPropertyService = $propertyService;
}
/**
* @Route("/meine-daten", methods={"GET", "POST"})
* @param Request $request
* @Template()
* @return array|RedirectResponse
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*/
public function mydata(Request $request)
{
$this->denyAccessUnlessGranted('ROLE_WEBMASTER');
/**
* @var $user ApiUser
*/
$user = $this->getUser();
$form = $this->createForm(MyDataForm::class, [], []);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
if($this->personService->createPersonSubmissionForAccount($user->getAccountId(), $data)) {
$this->addFlash('success', 'Datenänderung zur Prüfung eingereicht.');
}
return $this->redirectToRoute($request->attributes->get('_route'));
}
return [
'form' => $form->createView(),
'person' => $this->personService->getCurrentPersonForWebmaster($user->getWebmasterId()),
'taxNumberDictionary' => TaxNumber::getDictionary()
];
}
/**
* @Route("/kontakt")
* @Template()
* @return array
*/
public function contact(): array
{
$this->denyAccessUnlessGranted('ROLE_WEBMASTER');
return [
];
}
/**
* @Route("/einstellungen")
* @Template()
* @param Request $request
* @return array|JsonResponse
*/
public function settings(Request $request)
{
$this->denyAccessUnlessGranted('ROLE_WEBMASTER');
/**
* @var $user ApiUser
*/
$user = $this->getUser();
$webmasterId = $user->getWebmasterId();
$fields = [
WebmasterProperty::MINIMUM_PAYOUT_LIMIT => [
'label' => 'Auszahlungslimit',
'value' => $this->webmasterPropertyService->getPropertyValueForWebmaster(WebmasterProperty::MINIMUM_PAYOUT_LIMIT, $webmasterId),
'type' => 'select',
'options' => [
50, 100, 250, 500, 1000
]
],
WebmasterProperty::SKYPE_USERNAME => [
'label' => 'Skype Benutzername für Support-Fragen',
'value' => $this->webmasterPropertyService->getPropertyValueForWebmaster(WebmasterProperty::SKYPE_USERNAME, $webmasterId),
'type' => 'text'
]
];
if($request->isMethod('POST')) {
$property = trim($request->request->get('property'));
$value = trim($request->request->get('value'));
$success = $this->webmasterPropertyService->updatePropertyValue($property, $user->getWebmasterId(), $value);
return new JsonResponse([
'message' => $success ? 'Daten gespeichert' : 'Fehler beim Speichern'
], $success ? Response::HTTP_OK : Response::HTTP_INTERNAL_SERVER_ERROR);
}
return [
'fields' => $fields
];
}
}