|
- <?php
-
- namespace Lc\PietroBundle\Definition\Field\IndividualData;
-
- use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
- use Lc\PietroBundle\Controller\IndividualData\IndividualDataAdminController;
- use Lc\PietroBundle\Form\Dream\DreamType;
- use Lc\PietroBundle\Form\ProjectBoost\ProjectBoostType;
- use Lc\PietroBundle\Form\ProjectInspiring\ProjectInspiringType;
- use Lc\PietroBundle\Form\Revolt\RevoltType;
- use Lc\PietroBundle\Repository\Territory\TerritoryStore;
- use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
- use Lc\SovBundle\Field\CollectionField;
- use Lc\SovBundle\Field\StatusField;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
-
- class IndividualDataFieldDefinition extends AbstractFieldDefinition
- {
-
- protected AuthorizationCheckerInterface $authorizationChecker;
- protected TerritoryStore $territoryStore;
-
- public function __construct(TranslatorAdmin $translatorAdmin, AuthorizationCheckerInterface $authorizationChecker, TerritoryStore $territoryStore)
- {
- $this->authorizationChecker = $authorizationChecker;
- $this->territoryStore = $territoryStore;
-
- parent::__construct($translatorAdmin);
- }
-
- public function configureIndex(): array
- {
- return [
- 'firstname',
- 'lastname',
- 'territory',
- 'nbDream',
- 'nbRevolt',
- 'nbProjectBoost',
- 'nbProjectInspiring',
- ];
- }
-
- public function configureFields(): array
- {
- $fields = array();
-
- $territoryArray = $this->territoryStore->get();
-
- $fields['firstname'] = TextField::new('firstname');
- $fields['lastname'] = TextField::new('lastname');
- $fields['email'] = EmailField::new('email');
- $fields['territory'] = AssociationField::new('territory')->setFormTypeOption('choices', $territoryArray);
- $fields['nbDream'] = TextField::new('nbDream');
- $fields['nbRevolt'] = TextField::new('nbRevolt');
- $fields['nbProjectBoost'] = TextField::new('nbProjectBoost');
- $fields['nbProjectInspiring'] = TextField::new('nbProjectInspiring');
- $fields['revolt'] = CollectionField::new('revolt')
- ->setFormTypeOption('entry_type', RevoltType::class)
- ->setFormTypeOption('by_reference', false)
- ->setRequired(false);
- $fields['dream'] = CollectionField::new('dream')
- ->setFormTypeOption('entry_type', DreamType::class)
- ->setFormTypeOption('by_reference', false)
- ->setRequired(false);
- $fields['projectBoost'] = CollectionField::new('projectBoost')
- ->setFormTypeOption('entry_type', ProjectBoostType::class)
- ->setFormTypeOption('by_reference', false)
- ->setRequired(false);
- $fields['projectInspiring'] = CollectionField::new('projectinspiring')
- ->setFormTypeOption('entry_type', ProjectInspiringType::class)
- ->setFormTypeOption('by_reference', false)
- ->setRequired(false);
- $hasAccess = $this->authorizationChecker->isGranted('ROLE_ADMIN');
- if ($hasAccess) {
- $fields['status'] = StatusField::new('status')
- ->setFormTypeOption('data', 0)
- ->setFormTypeOption('choices', ['Validé' => 1, 'En attente' => 0])
- ->setCustomOption('toggle_label', 'Valider');
- } else {
- $fields['status'] = HiddenField::new('status')
- ->setFormTypeOption('data', 0);
- }
-
-
- return $fields;
- }
-
- }
|