namespace Lc\PietroBundle\Container\IndividualData; | namespace Lc\PietroBundle\Container\IndividualData; | ||||
use Lc\PietroBundle\Definition\Field\IndividualData\IndividualDataFieldDefinition; | |||||
use Lc\PietroBundle\Factory\IndividualData\IndividualDataFactory; | use Lc\PietroBundle\Factory\IndividualData\IndividualDataFactory; | ||||
use Lc\PietroBundle\Repository\IndividualData\IndividualDataRepositoryQuery; | use Lc\PietroBundle\Repository\IndividualData\IndividualDataRepositoryQuery; | ||||
use Lc\PietroBundle\Repository\IndividualData\IndividualDataStore; | use Lc\PietroBundle\Repository\IndividualData\IndividualDataStore; | ||||
protected IndividualDataFactory $factory; | protected IndividualDataFactory $factory; | ||||
protected IndividualDataRepositoryQuery $repositoryQuery; | protected IndividualDataRepositoryQuery $repositoryQuery; | ||||
protected IndividualDataStore $store; | protected IndividualDataStore $store; | ||||
protected IndividualDataFieldDefinition $fieldDefinition; | |||||
public function __construct( | public function __construct( | ||||
IndividualDataFactory $factory, | |||||
IndividualDataRepositoryQuery $repositoryQuery, | |||||
IndividualDataStore $store | |||||
IndividualDataFactory $factory, | |||||
IndividualDataRepositoryQuery $repositoryQuery, | |||||
IndividualDataStore $store, | |||||
IndividualDataFieldDefinition $fieldDefinition | |||||
) { | ) { | ||||
$this->factory = $factory; | $this->factory = $factory; | ||||
$this->repositoryQuery = $repositoryQuery; | $this->repositoryQuery = $repositoryQuery; | ||||
$this->store = $store; | $this->store = $store; | ||||
$this->fieldDefinition = $fieldDefinition; | |||||
} | } | ||||
public function getFactory(): IndividualDataFactory | public function getFactory(): IndividualDataFactory | ||||
{ | { | ||||
return $this->store; | return $this->store; | ||||
} | } | ||||
public function getFieldDefinition(): IndividualDataFieldDefinition | |||||
{ | |||||
return $this->fieldDefinition; | |||||
} | |||||
} | } |
namespace Lc\PietroBundle\Controller\IndividualData; | namespace Lc\PietroBundle\Controller\IndividualData; | ||||
use App\Entity\Configuration; | |||||
use App\Entity\IndividualData; | |||||
use Lc\PietroBundle\Container\IndividualData\IndividualDataContainer; | |||||
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 Doctrine\ORM\EntityManagerInterface; | |||||
use Doctrine\ORM\QueryBuilder; | use Doctrine\ORM\QueryBuilder; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; | use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; | use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto; | use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; | |||||
use Lc\PietroBundle\Repository\Dream\DreamStore; | use Lc\PietroBundle\Repository\Dream\DreamStore; | ||||
use Lc\PietroBundle\Repository\ProjectBoost\ProjectBoostStore; | use Lc\PietroBundle\Repository\ProjectBoost\ProjectBoostStore; | ||||
use Lc\PietroBundle\Repository\ProjectInspiring\ProjectInspiringStore; | use Lc\PietroBundle\Repository\ProjectInspiring\ProjectInspiringStore; | ||||
use Lc\PietroBundle\Repository\Revolt\RevoltStore; | use Lc\PietroBundle\Repository\Revolt\RevoltStore; | ||||
use Lc\PietroBundle\Controller\AbstractAdminController; | use Lc\PietroBundle\Controller\AbstractAdminController; | ||||
use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | |||||
use Lc\SovBundle\Field\CollectionField; | |||||
use Lc\SovBundle\Field\StatusField; | |||||
use Lc\SovBundle\Generator\CsvGenerator; | use Lc\SovBundle\Generator\CsvGenerator; | ||||
abstract class IndividualDataAdminController extends AbstractAdminController | abstract class IndividualDataAdminController extends AbstractAdminController | ||||
public function configureFields(string $pageName): iterable | public function configureFields(string $pageName): iterable | ||||
{ | { | ||||
// TextField::new('firstname'), | |||||
// TextField::new('lastname'), | |||||
// EmailField::new('email'), | |||||
// TextField::new('introAnswer'), | |||||
$fields = array(); | |||||
$fields[] = AssociationField::new('territory') | |||||
->setTemplatePath('crud/field/association.html.twig'); | |||||
$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('data', 0) | |||||
->setFormTypeOption('choices', ['Validé' => 1, 'En attente' => 0]) | |||||
->setCustomOption('toggle_label', 'Valider') | |||||
->hideOnIndex(); | |||||
} else { | |||||
$fields[] = HiddenField::new('status') | |||||
->setFormTypeOption('data', 0) | |||||
->hideOnIndex(); | |||||
} | |||||
return $fields; | |||||
return $this->getIndividualDataContainer() | |||||
->getFieldDefinition() | |||||
->getFieldList($pageName); | |||||
} | } | ||||
// public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void | |||||
// { | |||||
// $configurationRepository = $this->getDoctrine()->getRepository(Configuration::class); | |||||
// | |||||
// $configuration = $configurationRepository->findOneByDevAlias('intro_question'); | |||||
// $entityInstance->setIntroQuestion($configuration->getValue()); | |||||
// $entityManager->persist($entityInstance); | |||||
// $entityManager->flush(); | |||||
// | |||||
// parent::persistEntity($entityManager, $entityInstance); | |||||
// } | |||||
public function createIndexQueryBuilder( | public function createIndexQueryBuilder( | ||||
SearchDto $searchDto, | SearchDto $searchDto, | ||||
EntityDto $entityDto, | EntityDto $entityDto, |
<?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\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; | |||||
public function __construct(TranslatorAdmin $translatorAdmin, AuthorizationCheckerInterface $authorizationChecker) | |||||
{ | |||||
$this->authorizationChecker = $authorizationChecker; | |||||
parent::__construct($translatorAdmin); | |||||
} | |||||
public function configureFieldsIndex(): array | |||||
{ | |||||
return [ | |||||
'firstname', | |||||
'lastname', | |||||
'territory', | |||||
'nbDream', | |||||
'nbRevolt', | |||||
'nbProjectBoost', | |||||
'nbProjectInspiring', | |||||
]; | |||||
} | |||||
public function configurePanels(): array | |||||
{ | |||||
return []; | |||||
} | |||||
public function configureFields(): array | |||||
{ | |||||
$fields = array(); | |||||
$fields['firstname'] = TextField::new('firstname'); | |||||
$fields['lastname'] = TextField::new('lastname'); | |||||
$fields['email'] = EmailField::new('email'); | |||||
$fields['territory'] = AssociationField::new('territory') | |||||
->setTemplatePath('crud/field/association.html.twig'); | |||||
$fields['nbDream'] = TextField::new('nbDream') | |||||
->onlyOnIndex(); | |||||
$fields['nbRevolt'] = TextField::new('nbRevolt') | |||||
->onlyOnIndex(); | |||||
$fields['nbProjectBoost'] = TextField::new('nbProjectBoost') | |||||
->onlyOnIndex(); | |||||
$fields['nbProjectInspiring'] = TextField::new('nbProjectInspiring') | |||||
->onlyOnIndex(); | |||||
$fields['revolt'] = CollectionField::new('revolt') | |||||
->setFormTypeOption('entry_type', RevoltType::class) | |||||
->setFormTypeOption('by_reference', false) | |||||
->setRequired(false) | |||||
->hideOnIndex(); | |||||
$fields['dream'] = CollectionField::new('dream') | |||||
->setFormTypeOption('entry_type', DreamType::class) | |||||
->setFormTypeOption('by_reference', false) | |||||
->setRequired(false) | |||||
->hideOnIndex(); | |||||
$fields['projectBoost'] = CollectionField::new('projectBoost') | |||||
->setFormTypeOption('entry_type', ProjectBoostType::class) | |||||
->setFormTypeOption('by_reference', false) | |||||
->setRequired(false) | |||||
->hideOnIndex(); | |||||
$fields['projectinspiring'] = CollectionField::new('projectinspiring') | |||||
->setFormTypeOption('entry_type', ProjectInspiringType::class) | |||||
->setFormTypeOption('by_reference', false) | |||||
->setRequired(false) | |||||
->hideOnIndex(); | |||||
$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') | |||||
->hideOnIndex(); | |||||
} else { | |||||
$fields['status'] = HiddenField::new('status') | |||||
->setFormTypeOption('data', 0) | |||||
->hideOnIndex(); | |||||
} | |||||
return $fields; | |||||
} | |||||
} |