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.

65 lines
2.4KB

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