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.

73 lines
2.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\User;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  6. use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
  7. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  8. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  9. use Lc\CaracoleBundle\Resolver\SectionResolver;
  10. use Lc\SovBundle\Controller\AbstractAdminController;
  11. use Lc\SovBundle\Definition\RolesDefinition;
  12. use Lc\SovBundle\Definition\RolesDefinitionInterface;
  13. use Lc\SovBundle\Doctrine\EntityManager;
  14. use Lc\SovBundle\Model\User\UserInterface;
  15. use Lc\SovBundle\Translation\TranslatorAdmin;
  16. use Symfony\Component\Cache\Adapter\AdapterInterface;
  17. use Symfony\Component\HttpFoundation\RequestStack;
  18. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  19. use Lc\SovBundle\Controller\User\UserAdminController as SovUserAdminController;
  20. abstract class UserAdminController extends SovUserAdminController
  21. {
  22. public static function getSubscribedServices()
  23. {
  24. return array_merge(parent::getSubscribedServices(), [
  25. 'merchant_resolver' => MerchantResolver::class,
  26. 'section_resolver' => SectionResolver::class,
  27. ]);
  28. }
  29. public function __construct(
  30. SessionInterface $session,
  31. RequestStack $request,
  32. EntityManager $em,
  33. TranslatorAdmin $translatorAdmin,
  34. RolesDefinitionInterface $rolesDefinition,
  35. MerchantResolver $merchantResolver
  36. ) {
  37. parent::__construct($session, $request, $em, $translatorAdmin, $rolesDefinition);
  38. }
  39. public function configureCrud(Crud $crud): Crud
  40. {
  41. $crud->overrideTemplate('crud/new', '@LcCaracole/admin/user/user_new.html.twig');
  42. return parent::configureCrud($crud); // TODO: Change the autogenerated stub
  43. }
  44. public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
  45. {
  46. $this->updateUserMerchantRoles($entityManager, $entityInstance);
  47. parent::updateEntity($entityManager,$entityInstance);
  48. }
  49. /* public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
  50. {
  51. $this->updateUserMerchantRoles($entityManager,$entityInstance);
  52. parent::updateEntity($entityManager,$entityInstance);
  53. }*/
  54. protected function updateUserMerchantRoles($entityManager, UserInterface $user){
  55. $userMerchant = $this->get('merchant_resolver')->getUserMerchant($user);
  56. if($userMerchant !== null){
  57. $userMerchant->setRoles($user->getRoles());
  58. //$entityManager->update($userMerchant);
  59. }
  60. }
  61. }