Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

109 lines
4.1KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\User;
  3. use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  5. use Lc\CaracoleBundle\Controller\ControllerTrait;
  6. use Lc\SovBundle\Container\User\UserContainer;
  7. use Lc\SovBundle\Controller\User\UserAdminController as SovUserAdminController;
  8. use Lc\SovBundle\Definition\ActionDefinition;
  9. use Lc\SovBundle\Model\User\UserInterface;
  10. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  11. abstract class UserAdminController extends SovUserAdminController
  12. {
  13. use ControllerTrait;
  14. public function getRepositoryQuery(): RepositoryQueryInterface
  15. {
  16. return $this->container->get($this->getContainerFqcn())->getRepositoryQuery();
  17. }
  18. public function createEntity(string $entityFqcn)
  19. {
  20. return $this->getUserContainer()->getFactory()->create();
  21. }
  22. public function overrideEntitiesActions(?EntityCollection $entities, string $pageName): void
  23. {
  24. foreach ($entities as $entity) {
  25. foreach ($entity->getActions() as $action) {
  26. if ($action->getName() == ActionDefinition::SWITCH_USER) {
  27. $sectionDefault = $this->getSectionContainer()->getStore()->setMerchant($this->getMerchantCurrent())->getOneDefault();
  28. $url = $this->generateUrl($this->getParameter('lc_sov.homepage_route'), array('_switch_user' => $entity->getInstance()->getEmail(), 'section' => $sectionDefault->getSlug()));
  29. $action->setLinkUrl($url);
  30. }
  31. }
  32. }
  33. }
  34. public function getDeleteUserWarningMessageList(UserInterface $user): array
  35. {
  36. $warningMessages = parent::getDeleteUserWarningMessageList($user);
  37. foreach ($this->getUserMerchantContainer()->getStore()->getByUserOutOfContext($user) as $userMerchant) {
  38. if ($this->getUserMerchantContainer()->getSolver()->isCreditActive($userMerchant) && $userMerchant->getCredit() != 0) {
  39. $warningMessages['danger'][] = $this->getTranslatorAdmin()->transFlashMessage('error', 'deleteHasCredit', 'User', array('%merchant%' => $userMerchant->getMerchant()));
  40. }
  41. }
  42. foreach ($this->getReductionCatalogContainer()->getStore()->getByUserOutOfContext($user) as $reductionCatalog) {
  43. $warningMessages['danger'][] = $this->getTranslatorAdmin()->transFlashMessage(
  44. 'error',
  45. 'deleteHasReductionCatalog',
  46. 'User',
  47. array(
  48. '%merchant%' => $reductionCatalog->getMerchant(),
  49. '%id%' => $reductionCatalog->getId()
  50. )
  51. );
  52. }
  53. foreach ($this->getReductionCartContainer()->getStore()->getByUserOutOfContext($user) as $reductionCart) {
  54. $warningMessages['danger'][] = $this->getTranslatorAdmin()->transFlashMessage(
  55. 'error',
  56. 'deleteHasReductionCart',
  57. 'User',
  58. array(
  59. '%merchant%' => $reductionCart->getMerchant(),
  60. '%id%' => $reductionCart->getId()
  61. )
  62. );
  63. }
  64. foreach ($this->getReductionCreditContainer()->getStore()->getReductionCreditByUserOutOfContext($user) as $reductionCredit) {
  65. $warningMessages['warning'][] = $this->getTranslatorAdmin()->transFlashMessage(
  66. 'error',
  67. 'deleteHasReductionCredit',
  68. 'User',
  69. array(
  70. '%merchant%' => $reductionCredit->getMerchant(),
  71. '%id%' => $reductionCredit->getId()
  72. )
  73. );
  74. }
  75. foreach ($this->getReductionCreditContainer()->getStore()->getReductionGiftByUserOutOfContext($user) as $reductionGift) {
  76. $warningMessages['warning'][] = $this->getTranslatorAdmin()->transFlashMessage(
  77. 'error',
  78. 'deleteHasReductionGift',
  79. 'User',
  80. array(
  81. '%merchant%' => $reductionGift->getMerchant(),
  82. '%id%' => $reductionGift->getId()
  83. )
  84. );
  85. }
  86. return $warningMessages;
  87. }
  88. }