|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
-
- namespace Lc\CaracoleBundle\Definition\Field\User;
-
- use App\Entity\User\GroupUser;
- use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
- use Lc\CaracoleBundle\Context\MerchantContextTrait;
- use Lc\CaracoleBundle\Field\AssociationField;
- use Lc\CaracoleBundle\Repository\Newsletter\NewsletterStore;
- use Lc\CaracoleBundle\Repository\User\GroupUserStore;
- use Lc\CaracoleBundle\Solver\Ticket\TicketSolver;
- use Lc\SovBundle\Definition\Field\User\UserFieldDefinition as SovUserFieldDefinition;
- use Lc\SovBundle\Definition\RolesDefinition;
- use Lc\SovBundle\Field\BooleanField;
- use Lc\SovBundle\Translation\TranslatorAdmin;
-
- use function Clue\StreamFilter\fun;
-
- class UserFieldDefinition extends SovUserFieldDefinition
- {
- use MerchantContextTrait;
-
- protected ?array $newsletterArray = null;
- protected ?array $groupUserArray = null;
-
- protected GroupUserStore $groupUserStore;
- protected NewsletterStore $newsletterStore;
-
- public function __construct(
- TranslatorAdmin $translatorAdmin,
- RolesDefinition $rolesDefinition,
- GroupUserStore $groupUserStore,
- NewsletterStore $newsletterStore
- )
- {
- parent::__construct($translatorAdmin, $rolesDefinition);
-
- $this->groupUserStore = $groupUserStore;
- $this->newsletterStore = $newsletterStore;
- }
-
- public function configureIndex(): array
- {
- return [
- 'id',
- 'gender',
- 'lastname',
- 'firstname',
- 'email',
- 'groupUsers',
- 'birthdate',
- 'countOrder',
- 'totalSpent',
- 'isSaleAlwaysOpen',
- ];
- }
-
- public function configureForm(): array
- {
- return [
- 'gender',
- 'lastname',
- 'firstname',
- 'email',
- 'phone',
- 'birthdate',
- 'groupUsers',
- 'isSaleAlwaysOpen',
- 'newsletters',
- 'ticketTypesNotification',
- ];
- }
-
- public function configureFields(): array
- {
- if (is_null($this->newsletterArray)) {
- $this->newsletterArray = $this->newsletterStore->getAll();
- }
-
- if (is_null($this->groupUserArray)) {
- $this->groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->getAll();
- }
-
- return array_merge(parent::configureFields(), [
- 'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'),
- 'newsletters' => AssociationField::new('newsletters')
- ->setFormTypeOption('choices', $this->newsletterArray)
- ->setFormTypeOption('choice_label', function ($choice) {
- return $choice->getTitle() . '[' . $choice->getSection()->getMerchant() . ']';
- })
- ->setSortable(true),
- 'groupUsers' => AssociationField::new('groupUsers')
- ->setFormTypeOption('choices', $this->groupUserArray)
- ->setCustomOption('class', GroupUser::class)
- ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
- ->setFormTypeOption('choice_label', function ($choice) {
- return $choice->getTitle() . '[' . $choice->getMerchant() . ']';
- })
- ->setSortable(false),
- 'ticketTypesNotification' => ChoiceField::new('ticketTypesNotification')
- ->setSortable(true)
- ->setFormTypeOption('expanded', false)
- ->setFormTypeOption('multiple', true)
- ->setChoices(
- $this->translatorAdmin->transChoices(
- TicketSolver::getTypeChoices(),
- 'Ticket',
- 'type'
- )
- ),
- 'countOrder' => NumberField::new('countOrder')
- ->setFormTypeOption('mapped', false)
- ->setCustomOption('filter', false)
- ->setTemplatePath('@LcCaracole/admin/user/field/count_order.html.twig'),
- 'totalSpent' => NumberField::new('totalSpent')
- ->setFormTypeOption('mapped', false)
- ->setCustomOption('filter', false)
- ->setTemplatePath('@LcCaracole/admin/user/field/total_spent.html.twig'),
- ]);
- }
-
- }
|