Browse Source

[Backend] Optimistation de FieldDefinition #169

develop
Fabien Normand 2 years ago
parent
commit
2faa94310a
1 changed files with 25 additions and 9 deletions
  1. +25
    -9
      Definition/Field/Reduction/ReductionCatalogFieldDefinition.php

+ 25
- 9
Definition/Field/Reduction/ReductionCatalogFieldDefinition.php View File

protected ProductFamilyStore $productFamilyStore; protected ProductFamilyStore $productFamilyStore;
protected ProductCategoryStore $productCategoryStore; protected ProductCategoryStore $productCategoryStore;


protected ?array $groupUserArray = null;
protected ?array $usersArray= null;
protected ?array $productFamilyArray= null;
protected ?array $productCategoryArray= null;

public function __construct( public function __construct(
TranslatorAdmin $translatorAdmin, TranslatorAdmin $translatorAdmin,
GroupUserStore $groupUserStore, GroupUserStore $groupUserStore,


public function configureFields(): array public function configureFields(): array
{ {
$groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->get();
$usersArray = $this->userStore->setMerchant($this->merchant)->getJoinGroupUsers();
$productFamilyArray = $this->productFamilyStore->setMerchant($this->merchant)->get();
$productCategoryArray = $this->productCategoryStore->setMerchant($this->merchant)->get();
if(is_null($this->groupUserArray)) {
$this->groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->get();
}

if(is_null($this->usersArray)) {
$this->usersArray = $this->userStore->setMerchant($this->merchant)->getJoinGroupUsers();
}

if(is_null($this->productFamilyArray)) {
$this->productFamilyArray = $this->productFamilyStore->setMerchant($this->merchant)->get();
}

if(is_null($this->productCategoryArray)) {
$this->productCategoryArray = $this->productCategoryStore->setMerchant($this->merchant)->get();
}


return [ return [
'title' => TextField::new('title')->setSortable(true), 'title' => TextField::new('title')->setSortable(true),
'groupUsersActive' => BooleanField::new('groupUsersActive')->setFormTypeOption('mapped', false), 'groupUsersActive' => BooleanField::new('groupUsersActive')->setFormTypeOption('mapped', false),
'groupUsers' => AssociationField::new('groupUsers') 'groupUsers' => AssociationField::new('groupUsers')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $groupUserArray),
->setFormTypeOption('choices', $this->groupUserArray),


'usersActive' => BooleanField::new('usersActive')->setFormTypeOption('mapped', false), 'usersActive' => BooleanField::new('usersActive')->setFormTypeOption('mapped', false),


'users' => AssociationField::new('users') 'users' => AssociationField::new('users')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $usersArray)
->setFormTypeOption('choices', $this->usersArray)
->setFormTypeOption( ->setFormTypeOption(
'choice_attr', 'choice_attr',
function ($choice, $key, $value) { function ($choice, $key, $value) {
$section = ' [' . $category->getSection()->getTitle() . ']';; $section = ' [' . $category->getSection()->getTitle() . ']';;
return $category . $section . $isOffline; return $category . $section . $isOffline;
}) })
->setFormTypeOption('choices', $productCategoryArray),
->setFormTypeOption('choices', $this->productCategoryArray),




'productFamiliesActive' => BooleanField::new('productFamiliesActive')->setFormTypeOption('mapped', false), 'productFamiliesActive' => BooleanField::new('productFamiliesActive')->setFormTypeOption('mapped', false),
'productFamilies' => AssociationField::new('productFamilies') 'productFamilies' => AssociationField::new('productFamilies')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $productFamilyArray)
->setFormTypeOption('choices', $this->productFamilyArray)
->setFormTypeOption( ->setFormTypeOption(
'choice_attr', 'choice_attr',
function ($choice, $key, $value) { function ($choice, $key, $value) {
} }
), ),
'productFamily' => AssociationField::new('productFamily') 'productFamily' => AssociationField::new('productFamily')
->setFormTypeOption('choices', $productFamilyArray)
->setFormTypeOption('choices', $this->productFamilyArray)
]; ];
} }
} }

Loading…
Cancel
Save