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.

94 lines
3.7KB

  1. <?php
  2. namespace Lc\PietroBundle\Definition\Field\IndividualData;
  3. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField;
  6. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  7. use Lc\PietroBundle\Controller\IndividualData\IndividualDataAdminController;
  8. use Lc\PietroBundle\Form\Dream\DreamType;
  9. use Lc\PietroBundle\Form\ProjectBoost\ProjectBoostType;
  10. use Lc\PietroBundle\Form\ProjectInspiring\ProjectInspiringType;
  11. use Lc\PietroBundle\Form\Revolt\RevoltType;
  12. use Lc\PietroBundle\Repository\Territory\TerritoryStore;
  13. use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
  14. use Lc\SovBundle\Field\CollectionField;
  15. use Lc\SovBundle\Field\StatusField;
  16. use Lc\SovBundle\Translation\TranslatorAdmin;
  17. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  18. class IndividualDataFieldDefinition extends AbstractFieldDefinition
  19. {
  20. protected AuthorizationCheckerInterface $authorizationChecker;
  21. protected TerritoryStore $territoryStore;
  22. public function __construct(TranslatorAdmin $translatorAdmin, AuthorizationCheckerInterface $authorizationChecker, TerritoryStore $territoryStore)
  23. {
  24. $this->authorizationChecker = $authorizationChecker;
  25. $this->territoryStore = $territoryStore;
  26. parent::__construct($translatorAdmin);
  27. }
  28. public function configureIndex(): array
  29. {
  30. return [
  31. 'firstname',
  32. 'lastname',
  33. 'territory',
  34. 'nbDream',
  35. 'nbRevolt',
  36. 'nbProjectBoost',
  37. 'nbProjectInspiring',
  38. ];
  39. }
  40. public function configureFields(): array
  41. {
  42. $fields = array();
  43. $territoryArray = $this->territoryStore->get();
  44. $fields['firstname'] = TextField::new('firstname');
  45. $fields['lastname'] = TextField::new('lastname');
  46. $fields['email'] = EmailField::new('email');
  47. $fields['territory'] = AssociationField::new('territory')->setFormTypeOption('choices', $territoryArray);
  48. $fields['nbDream'] = TextField::new('nbDream');
  49. $fields['nbRevolt'] = TextField::new('nbRevolt');
  50. $fields['nbProjectBoost'] = TextField::new('nbProjectBoost');
  51. $fields['nbProjectInspiring'] = TextField::new('nbProjectInspiring');
  52. $fields['revolt'] = CollectionField::new('revolt')
  53. ->setFormTypeOption('entry_type', RevoltType::class)
  54. ->setFormTypeOption('by_reference', false)
  55. ->setRequired(false);
  56. $fields['dream'] = CollectionField::new('dream')
  57. ->setFormTypeOption('entry_type', DreamType::class)
  58. ->setFormTypeOption('by_reference', false)
  59. ->setRequired(false);
  60. $fields['projectBoost'] = CollectionField::new('projectBoost')
  61. ->setFormTypeOption('entry_type', ProjectBoostType::class)
  62. ->setFormTypeOption('by_reference', false)
  63. ->setRequired(false);
  64. $fields['projectInspiring'] = CollectionField::new('projectinspiring')
  65. ->setFormTypeOption('entry_type', ProjectInspiringType::class)
  66. ->setFormTypeOption('by_reference', false)
  67. ->setRequired(false);
  68. $hasAccess = $this->authorizationChecker->isGranted('ROLE_ADMIN');
  69. if ($hasAccess) {
  70. $fields['status'] = StatusField::new('status')
  71. ->setFormTypeOption('data', 0)
  72. ->setFormTypeOption('choices', ['Validé' => 1, 'En attente' => 0])
  73. ->setCustomOption('toggle_label', 'Valider');
  74. } else {
  75. $fields['status'] = HiddenField::new('status')
  76. ->setFormTypeOption('data', 0);
  77. }
  78. return $fields;
  79. }
  80. }