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.

124 lines
4.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Definition\Field\User;
  3. use App\Entity\User\GroupUser;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
  6. use Lc\CaracoleBundle\Context\MerchantContextTrait;
  7. use Lc\CaracoleBundle\Field\AssociationField;
  8. use Lc\CaracoleBundle\Repository\Newsletter\NewsletterStore;
  9. use Lc\CaracoleBundle\Repository\User\GroupUserStore;
  10. use Lc\CaracoleBundle\Solver\Ticket\TicketSolver;
  11. use Lc\SovBundle\Definition\Field\User\UserFieldDefinition as SovUserFieldDefinition;
  12. use Lc\SovBundle\Definition\RolesDefinition;
  13. use Lc\SovBundle\Field\BooleanField;
  14. use Lc\SovBundle\Translation\TranslatorAdmin;
  15. use function Clue\StreamFilter\fun;
  16. class UserFieldDefinition extends SovUserFieldDefinition
  17. {
  18. use MerchantContextTrait;
  19. protected ?array $newsletterArray = null;
  20. protected ?array $groupUserArray = null;
  21. protected GroupUserStore $groupUserStore;
  22. protected NewsletterStore $newsletterStore;
  23. public function __construct(
  24. TranslatorAdmin $translatorAdmin,
  25. RolesDefinition $rolesDefinition,
  26. GroupUserStore $groupUserStore,
  27. NewsletterStore $newsletterStore
  28. )
  29. {
  30. parent::__construct($translatorAdmin, $rolesDefinition);
  31. $this->groupUserStore = $groupUserStore;
  32. $this->newsletterStore = $newsletterStore;
  33. }
  34. public function configureIndex(): array
  35. {
  36. return [
  37. 'id',
  38. 'gender',
  39. 'lastname',
  40. 'firstname',
  41. 'email',
  42. 'groupUsers',
  43. 'birthdate',
  44. 'countOrder',
  45. 'totalSpent',
  46. 'isSaleAlwaysOpen',
  47. ];
  48. }
  49. public function configureForm(): array
  50. {
  51. return [
  52. 'gender',
  53. 'lastname',
  54. 'firstname',
  55. 'email',
  56. 'phone',
  57. 'birthdate',
  58. 'groupUsers',
  59. 'isSaleAlwaysOpen',
  60. 'newsletters',
  61. 'ticketTypesNotification',
  62. ];
  63. }
  64. public function configureFields(): array
  65. {
  66. if (is_null($this->newsletterArray)) {
  67. $this->newsletterArray = $this->newsletterStore->getAll();
  68. }
  69. if (is_null($this->groupUserArray)) {
  70. $this->groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->getAll();
  71. }
  72. return array_merge(parent::configureFields(), [
  73. 'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'),
  74. 'newsletters' => AssociationField::new('newsletters')
  75. ->setFormTypeOption('choices', $this->newsletterArray)
  76. ->setFormTypeOption('choice_label', function ($choice) {
  77. return $choice->getTitle() . '[' . $choice->getSection()->getMerchant() . ']';
  78. })
  79. ->setSortable(true),
  80. 'groupUsers' => AssociationField::new('groupUsers')
  81. ->setFormTypeOption('choices', $this->groupUserArray)
  82. ->setCustomOption('class', GroupUser::class)
  83. ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
  84. ->setFormTypeOption('choice_label', function ($choice) {
  85. return $choice->getTitle() . '[' . $choice->getMerchant() . ']';
  86. })
  87. ->setSortable(false),
  88. 'ticketTypesNotification' => ChoiceField::new('ticketTypesNotification')
  89. ->setSortable(true)
  90. ->setFormTypeOption('expanded', false)
  91. ->setFormTypeOption('multiple', true)
  92. ->setChoices(
  93. $this->translatorAdmin->transChoices(
  94. TicketSolver::getTypeChoices(),
  95. 'Ticket',
  96. 'type'
  97. )
  98. ),
  99. 'countOrder' => NumberField::new('countOrder')
  100. ->setFormTypeOption('mapped', false)
  101. ->setCustomOption('filter', false)
  102. ->setTemplatePath('@LcCaracole/admin/user/field/count_order.html.twig'),
  103. 'totalSpent' => NumberField::new('totalSpent')
  104. ->setFormTypeOption('mapped', false)
  105. ->setCustomOption('filter', false)
  106. ->setTemplatePath('@LcCaracole/admin/user/field/total_spent.html.twig'),
  107. ]);
  108. }
  109. }