|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
-
- namespace Lc\ShopBundle\Controller\Backend;
-
- use App\Repository\UserRepository;
- use Doctrine\ORM\EntityManagerInterface;
- use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
- use FOS\UserBundle\Model\UserManagerInterface;
- use Lc\ShopBundle\Context\MerchantUtilsInterface;
- use Lc\ShopBundle\Context\NewsInterface;
- use Lc\ShopBundle\Context\OrderUtilsInterface;
- use Lc\ShopBundle\Context\UserInterface;
- use Lc\ShopBundle\Services\CreditUtils;
- use Lc\ShopBundle\Services\Utils;
- use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
- use Symfony\Bridge\Doctrine\Form\Type\EntityType;
- use Symfony\Component\Form\Extension\Core\Type\SubmitType;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Symfony\Component\Security\Core\Security;
- use Symfony\Contracts\Translation\TranslatorInterface;
-
- class UserMerchantController extends AdminController
- {
- protected $creditUtils;
-
- public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, MerchantUtilsInterface $merchantUtils, MailjetTransport $mailjetTransport, OrderUtilsInterface $orderUtils, TranslatorInterface $translator, CreditUtils $creditUtils)
- {
- parent::__construct($security, $userManager, $em, $utils, $merchantUtils, $mailjetTransport, $orderUtils, $translator);
- $this->creditUtils = $creditUtils;
- }
-
- protected function newAction()
- {
- $this->dispatch(EasyAdminEvents::PRE_NEW);
-
- $entity = $this->executeDynamicMethod('createNew<EntityName>Entity');
-
- $easyadmin = $this->request->attributes->get('easyadmin');
- $easyadmin['item'] = $entity;
- $this->request->attributes->set('easyadmin', $easyadmin);
-
- $fields = $this->entity['new']['fields'];
-
- $newForm = $this->executeDynamicMethod('create<EntityName>NewForm', [$entity, $fields]);
-
- $newForm->handleRequest($this->request);
-
- //ETAPE 1 Choix de l'utilisateur
- $user = $newForm->get('user')->getData();
-
- if ($user == null) {
- $user = $this->getUserViaFirstStepForm($entity);
- }
-
- if (!$user instanceof UserInterface) return $user;
- else {
-
- $userMerchant = $this->creditUtils->activeCredit($user);
-
- return $this->redirectToRoute('easyadmin', [
- 'action' => 'edit',
- 'entity' => $this->entity['name'],
- 'id' => $userMerchant->getId()
- ]);
- }
- }
-
- public function getUserViaFirstStepForm($entity)
- {
- $userClass = $this->em->getClassMetadata(UserInterface::class);
-
- $userChoiceForm = $this->createFormBuilder($entity)
- ->add('user', EntityType::class, array(
- 'class' => $userClass->name
- ))
- ->add('nextStep', SubmitType::class)
- ->getForm();
- $userChoiceForm->handleRequest($this->request);
- if ($userChoiceForm->isSubmitted() && $userChoiceForm->isValid()) {
- return $userChoiceForm->get('user')->getData();
- }
-
- $parameters = [
- 'form' => $userChoiceForm->createView(),
- 'formView' => 'default',
- 'entity' => $entity,
- ];
-
- return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]);
- }
-
- /**
- * The method that is executed when the user performs a 'show' action on an entity.
- *
- * @return Response
- */
- public function showAction()
- {
- $this->dispatch(EasyAdminEvents::PRE_SHOW);
-
- $id = $this->request->query->get('id');
- $easyadmin = $this->request->attributes->get('easyadmin');
- $entity = $easyadmin['item'];
-
- $fields = $this->entity['show']['fields'];
- $deleteForm = $this->createDeleteForm($this->entity['name'], $id);
-
- $this->dispatch(EasyAdminEvents::POST_SHOW, [
- 'deleteForm' => $deleteForm,
- 'fields' => $fields,
- 'entity' => $entity,
- ]);
-
- $parameters = [
- 'entity' => $entity,
- 'fields' => $fields,
- 'delete_form' => $deleteForm->createView()
- ];
-
- return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
- }
-
- /**
- * Réécriture de edit action pr rediriger vers le show */
- public function editAction()
- {
- $id = $this->request->query->get('id');
- $entity = $this->request->query->get('entity');
-
- return $this->redirectToRoute('easyadmin', [
- 'action' => 'show',
- 'entity' => $entity,
- 'id' => $id
- ]);
- }
-
- }
|