Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

105 lines
3.8KB

  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\SovBundle\Definition\Field\AbstractFieldDefinition;
  13. use Lc\SovBundle\Field\CollectionField;
  14. use Lc\SovBundle\Field\StatusField;
  15. use Lc\SovBundle\Translation\TranslatorAdmin;
  16. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  17. class IndividualDataFieldDefinition extends AbstractFieldDefinition
  18. {
  19. protected AuthorizationCheckerInterface $authorizationChecker;
  20. public function __construct(TranslatorAdmin $translatorAdmin, AuthorizationCheckerInterface $authorizationChecker)
  21. {
  22. $this->authorizationChecker = $authorizationChecker;
  23. parent::__construct($translatorAdmin);
  24. }
  25. public function configureFieldsIndex(): array
  26. {
  27. return [
  28. 'firstname',
  29. 'lastname',
  30. 'territory',
  31. 'nbDream',
  32. 'nbRevolt',
  33. 'nbProjectBoost',
  34. 'nbProjectInspiring',
  35. ];
  36. }
  37. public function configurePanels(): array
  38. {
  39. return [];
  40. }
  41. public function configureFields(): array
  42. {
  43. $fields = array();
  44. $fields['firstname'] = TextField::new('firstname');
  45. $fields['lastname'] = TextField::new('lastname');
  46. $fields['email'] = EmailField::new('email');
  47. $fields['territory'] = AssociationField::new('territory')
  48. ->setTemplatePath('crud/field/association.html.twig');
  49. $fields['nbDream'] = TextField::new('nbDream')
  50. ->onlyOnIndex();
  51. $fields['nbRevolt'] = TextField::new('nbRevolt')
  52. ->onlyOnIndex();
  53. $fields['nbProjectBoost'] = TextField::new('nbProjectBoost')
  54. ->onlyOnIndex();
  55. $fields['nbProjectInspiring'] = TextField::new('nbProjectInspiring')
  56. ->onlyOnIndex();
  57. $fields['revolt'] = CollectionField::new('revolt')
  58. ->setFormTypeOption('entry_type', RevoltType::class)
  59. ->setFormTypeOption('by_reference', false)
  60. ->setRequired(false)
  61. ->hideOnIndex();
  62. $fields['dream'] = CollectionField::new('dream')
  63. ->setFormTypeOption('entry_type', DreamType::class)
  64. ->setFormTypeOption('by_reference', false)
  65. ->setRequired(false)
  66. ->hideOnIndex();
  67. $fields['projectBoost'] = CollectionField::new('projectBoost')
  68. ->setFormTypeOption('entry_type', ProjectBoostType::class)
  69. ->setFormTypeOption('by_reference', false)
  70. ->setRequired(false)
  71. ->hideOnIndex();
  72. $fields['projectinspiring'] = CollectionField::new('projectinspiring')
  73. ->setFormTypeOption('entry_type', ProjectInspiringType::class)
  74. ->setFormTypeOption('by_reference', false)
  75. ->setRequired(false)
  76. ->hideOnIndex();
  77. $hasAccess = $this->authorizationChecker->isGranted('ROLE_ADMIN');
  78. if ($hasAccess) {
  79. $fields['status'] = StatusField::new('status')
  80. ->setFormTypeOption('data', 0)
  81. ->setFormTypeOption('choices', ['Validé' => 1, 'En attente' => 0])
  82. ->setCustomOption('toggle_label', 'Valider')
  83. ->hideOnIndex();
  84. } else {
  85. $fields['status'] = HiddenField::new('status')
  86. ->setFormTypeOption('data', 0)
  87. ->hideOnIndex();
  88. }
  89. return $fields;
  90. }
  91. }