@@ -2,6 +2,7 @@ | |||
namespace App\Container\CollectifData; | |||
use App\Definition\Field\CollectifData\CollectifDataFieldDefinition; | |||
use App\Factory\CollectifData\CollectifDataFactory; | |||
use App\Repository\CollectifData\CollectifDataRepositoryQuery; | |||
use App\Repository\CollectifData\CollectifDataStore; | |||
@@ -11,15 +12,18 @@ class CollectifDataContainer | |||
protected CollectifDataFactory $factory; | |||
protected CollectifDataRepositoryQuery $repositoryQuery; | |||
protected CollectifDataStore $store; | |||
protected CollectifDataFieldDefinition $fieldDefinition; | |||
public function __construct( | |||
CollectifDataFactory $factory, | |||
CollectifDataRepositoryQuery $repositoryQuery, | |||
CollectifDataStore $store | |||
CollectifDataFactory $factory, | |||
CollectifDataRepositoryQuery $repositoryQuery, | |||
CollectifDataStore $store, | |||
CollectifDataFieldDefinition $fieldDefinition | |||
) { | |||
$this->factory = $factory; | |||
$this->repositoryQuery = $repositoryQuery; | |||
$this->store = $store; | |||
$this->fieldDefinition = $fieldDefinition; | |||
} | |||
public function getFactory(): CollectifDataFactory | |||
@@ -37,4 +41,8 @@ class CollectifDataContainer | |||
return $this->store; | |||
} | |||
public function getFieldDefinition(): CollectifDataFieldDefinition | |||
{ | |||
return $this->fieldDefinition; | |||
} | |||
} |
@@ -29,61 +29,21 @@ class CollectifDataCrudController extends AbstractAdminController | |||
return CollectifData::class; | |||
} | |||
public function getRepositoryQuery(): RepositoryQueryInterface | |||
public function createEntity(string $entityFqcn) | |||
{ | |||
return $this->getCollectifDataContainer()->getRepositoryQuery(); | |||
return $this->getCollectifDataContainer()->getFactory()->create(); | |||
} | |||
public function configureFields(string $pageName): iterable | |||
{ | |||
$fields = array(); | |||
$fields[] = TextField::new('name'); | |||
$fields[] = AssociationField::new('territory') | |||
->setTemplatePath('crud/field/association.html.twig'); | |||
$fields[] = IntegerField::new('nbParticipant'); | |||
$fields[] = TextField::new('nbDream') | |||
->onlyOnIndex(); | |||
$fields[] = TextField::new('nbRevolt') | |||
->onlyOnIndex(); | |||
$fields[] = TextField::new('nbProjectBoost') | |||
->onlyOnIndex(); | |||
$fields[] = TextField::new('nbProjectInspiring') | |||
->onlyOnIndex(); | |||
$fields[] = CollectionField::new('revolt') | |||
->setFormTypeOption('entry_type', RevoltType::class) | |||
->setFormTypeOption('by_reference', false) | |||
->setRequired(false) | |||
->hideOnIndex(); | |||
$fields[] = CollectionField::new('dream') | |||
->setFormTypeOption('entry_type', DreamType::class) | |||
->setFormTypeOption('by_reference', false) | |||
->setRequired(false) | |||
->hideOnIndex(); | |||
$fields[] = CollectionField::new('projectBoost') | |||
->setFormTypeOption('entry_type', ProjectBoostType::class) | |||
->setFormTypeOption('by_reference', false) | |||
->setRequired(false) | |||
->hideOnIndex(); | |||
$fields[] = CollectionField::new('projectinspiring') | |||
->setFormTypeOption('entry_type', ProjectInspiringType::class) | |||
->setFormTypeOption('by_reference', false) | |||
->setRequired(false) | |||
->hideOnIndex(); | |||
$hasAccess = $this->isGranted('ROLE_ADMIN'); | |||
if ($hasAccess) { | |||
$fields[] = StatusField::new('status') | |||
->setFormTypeOption('choices', ['Validé' => 1, 'En attente' => 0]) | |||
->setCustomOption('toggle_label', 'Valider') | |||
->hideOnIndex(); | |||
} else { | |||
$fields[] = HiddenField::new('status') | |||
->setFormTypeOption('data', 0) | |||
->hideOnIndex(); | |||
} | |||
return $this->getCollectifDataContainer() | |||
->getFieldDefinition() | |||
->getFields($pageName); | |||
} | |||
return $fields; | |||
public function getRepositoryQuery(): RepositoryQueryInterface | |||
{ | |||
return $this->getCollectifDataContainer()->getRepositoryQuery(); | |||
} | |||
public function createIndexRepositoryQuery( | |||
@@ -92,15 +52,9 @@ class CollectifDataCrudController extends AbstractAdminController | |||
FieldCollection $fields, | |||
FilterCollection $filters | |||
): RepositoryQueryInterface { | |||
return parent::createIndexRepositoryQuery( | |||
$searchDto, | |||
$entityDto, | |||
$fields, | |||
$filters | |||
); | |||
$repositoryQuery = parent::createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters); | |||
if ($searchDto->getRequest()->get('status')) { | |||
$status = $searchDto->getRequest()->get('status'); | |||
if ($status || $status == 0) { | |||
$repositoryQuery->filterByStatus($searchDto->getRequest()->get('status')); | |||
} | |||
return $repositoryQuery; |
@@ -16,7 +16,6 @@ class PageController extends AbstractController | |||
return $this->render( | |||
'page/page.html.twig', | |||
[ | |||
'controller_name' => 'IndexController', | |||
'page' => $pageRepository->findOneByDevAlias('legal-mention') | |||
] | |||
); | |||
@@ -29,7 +28,6 @@ class PageController extends AbstractController | |||
return $this->render( | |||
'page/page.html.twig', | |||
[ | |||
'controller_name' => 'IndexController', | |||
'page' => $pageRepository->findOneByDevAlias('politique') | |||
] | |||
); |
@@ -0,0 +1,97 @@ | |||
<?php | |||
namespace App\Definition\Field\CollectifData; | |||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; | |||
use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField; | |||
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; | |||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | |||
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\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 CollectifDataFieldDefinition extends AbstractFieldDefinition | |||
{ | |||
protected AuthorizationCheckerInterface $authorizationChecker; | |||
public function __construct(TranslatorAdmin $translatorAdmin, AuthorizationCheckerInterface $authorizationChecker) | |||
{ | |||
$this->authorizationChecker = $authorizationChecker; | |||
parent::__construct($translatorAdmin); | |||
} | |||
public function configureIndex(): array | |||
{ | |||
return [ | |||
'name', | |||
'territory', | |||
'nbParticipant', | |||
'nbDream', | |||
'nbRevolt', | |||
'nbProjectBoost', | |||
'nbProjectInspiring', | |||
]; | |||
} | |||
public function configureForm(): array | |||
{ | |||
return [ | |||
'name', | |||
'territory', | |||
'nbParticipant', | |||
'dream', | |||
'revolt', | |||
'projectBoost', | |||
'projectInspiring', | |||
'status', | |||
]; | |||
} | |||
public function configureFields(): array | |||
{ | |||
$fields = array(); | |||
$fields['name'] = TextField::new('name'); | |||
$fields['territory'] = AssociationField::new('territory') | |||
->setTemplatePath('crud/field/association.html.twig'); | |||
$fields['nbParticipant'] = IntegerField::new('nbParticipant'); | |||
$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('choices', ['Validé' => 1, 'En attente' => 0]) | |||
->setCustomOption('toggle_label', 'Valider'); | |||
} else { | |||
$fields['status'] = HiddenField::new('status') | |||
->setFormTypeOption('data', 0); | |||
} | |||
return $fields; | |||
} | |||
} |