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.

113 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. 'isSaleAlwaysOpen',
  43. ];
  44. }
  45. public function configureForm(): array
  46. {
  47. return [
  48. 'gender',
  49. 'lastname',
  50. 'firstname',
  51. 'email',
  52. 'phone',
  53. 'birthdate',
  54. 'groupUsers',
  55. 'isSaleAlwaysOpen',
  56. 'newsletters',
  57. 'ticketTypesNotification',
  58. ];
  59. }
  60. public function configureFields(): array
  61. {
  62. $groupUsers = $this->groupUserStore->setMerchant($this->merchant)->getAll();
  63. $newsletters = $this->newsletterStore->getAll();
  64. return array_merge(parent::configureFields(), [
  65. 'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'),
  66. 'newsletters' => AssociationField::new('newsletters')
  67. ->setFormTypeOption('choices', $newsletters)
  68. ->setFormTypeOption('choice_label', function ($choice) {
  69. return $choice->getTitle() . '[' . $choice->getSection()->getMerchant() . ']';
  70. })
  71. ->setSortable(true),
  72. 'groupUsers' => AssociationField::new('groupUsers')
  73. ->setFormTypeOption('choices', $groupUsers)
  74. ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
  75. ->setFormTypeOption('choice_label', function ($choice) {
  76. return $choice->getTitle() . '[' . $choice->getMerchant() . ']';
  77. })
  78. ->setSortable(false),
  79. 'ticketTypesNotification' => ChoiceField::new('ticketTypesNotification')
  80. ->setSortable(true)
  81. ->setFormTypeOption('expanded', false)
  82. ->setFormTypeOption('multiple', true)
  83. ->setChoices(
  84. $this->translatorAdmin->transChoices(
  85. TicketSolver::getTypeChoices(),
  86. 'Ticket',
  87. 'type'
  88. )
  89. ),
  90. 'countOrder' => NumberField::new('countOrder')
  91. ->setFormTypeOption('mapped', false)
  92. ->setCustomOption('filter', false)
  93. ->setTemplatePath('@LcCaracole/admin/user/field/count_order.html.twig'),
  94. 'totalSpent' => NumberField::new('totalSpent')
  95. ->setFormTypeOption('mapped', false)
  96. ->setCustomOption('filter', false)
  97. ->setTemplatePath('@LcCaracole/admin/user/field/total_spent.html.twig'),
  98. ]);
  99. }
  100. }