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.

112 lines
3.9KB

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