瀏覽代碼

[Backend] Optimistation de FieldDefinition #169

develop
Fabien Normand 1 年之前
父節點
當前提交
2faa94310a
共有 1 個文件被更改,包括 25 次插入9 次删除
  1. +25
    -9
      Definition/Field/Reduction/ReductionCatalogFieldDefinition.php

+ 25
- 9
Definition/Field/Reduction/ReductionCatalogFieldDefinition.php 查看文件

@@ -27,6 +27,11 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
protected ProductFamilyStore $productFamilyStore;
protected ProductCategoryStore $productCategoryStore;

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

public function __construct(
TranslatorAdmin $translatorAdmin,
GroupUserStore $groupUserStore,
@@ -81,10 +86,21 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition

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 [
'title' => TextField::new('title')->setSortable(true),
@@ -116,13 +132,13 @@ class ReductionCatalogFieldDefinition extends AbstractFieldDefinition
'groupUsersActive' => BooleanField::new('groupUsersActive')->setFormTypeOption('mapped', false),
'groupUsers' => AssociationField::new('groupUsers')
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig')
->setFormTypeOption('choices', $groupUserArray),
->setFormTypeOption('choices', $this->groupUserArray),

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

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


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

Loading…
取消
儲存