Kaynağa Gözat

individualData definition

develop
Charly 3 yıl önce
ebeveyn
işleme
c88ed01969
3 değiştirilmiş dosya ile 119 ekleme ve 81 silme
  1. +12
    -3
      Container/IndividualData/IndividualDataContainer.php
  2. +3
    -78
      Controller/IndividualData/IndividualDataAdminController.php
  3. +104
    -0
      Definition/Field/IndividualData/IndividualDataFieldDefinition.php

+ 12
- 3
Container/IndividualData/IndividualDataContainer.php Dosyayı Görüntüle

@@ -2,6 +2,7 @@

namespace Lc\PietroBundle\Container\IndividualData;

use Lc\PietroBundle\Definition\Field\IndividualData\IndividualDataFieldDefinition;
use Lc\PietroBundle\Factory\IndividualData\IndividualDataFactory;
use Lc\PietroBundle\Repository\IndividualData\IndividualDataRepositoryQuery;
use Lc\PietroBundle\Repository\IndividualData\IndividualDataStore;
@@ -11,15 +12,18 @@ class IndividualDataContainer
protected IndividualDataFactory $factory;
protected IndividualDataRepositoryQuery $repositoryQuery;
protected IndividualDataStore $store;
protected IndividualDataFieldDefinition $fieldDefinition;

public function __construct(
IndividualDataFactory $factory,
IndividualDataRepositoryQuery $repositoryQuery,
IndividualDataStore $store
IndividualDataFactory $factory,
IndividualDataRepositoryQuery $repositoryQuery,
IndividualDataStore $store,
IndividualDataFieldDefinition $fieldDefinition
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->fieldDefinition = $fieldDefinition;
}

public function getFactory(): IndividualDataFactory
@@ -36,4 +40,9 @@ class IndividualDataContainer
{
return $this->store;
}

public function getFieldDefinition(): IndividualDataFieldDefinition
{
return $this->fieldDefinition;
}
}

+ 3
- 78
Controller/IndividualData/IndividualDataAdminController.php Dosyayı Görüntüle

@@ -2,14 +2,6 @@

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 EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
@@ -18,19 +10,12 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
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\ProjectBoost\ProjectBoostStore;
use Lc\PietroBundle\Repository\ProjectInspiring\ProjectInspiringStore;
use Lc\PietroBundle\Repository\Revolt\RevoltStore;
use Lc\PietroBundle\Controller\AbstractAdminController;
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;

abstract class IndividualDataAdminController extends AbstractAdminController
@@ -59,71 +44,11 @@ abstract class IndividualDataAdminController extends AbstractAdminController

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(
SearchDto $searchDto,
EntityDto $entityDto,

+ 104
- 0
Definition/Field/IndividualData/IndividualDataFieldDefinition.php Dosyayı Görüntüle

@@ -0,0 +1,104 @@
<?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;
}

}

Yükleniyor…
İptal
Kaydet