groupUserStore = $groupUserStore; $this->userStore = $userStore; $this->productFamilyStore = $productFamilyStore; $this->productCategoryStore = $productCategoryStore; } public function configureIndex(): array { return [ 'id', 'title', 'value', 'status', 'isDisplayed' ]; } public function configureForm(): array { return [ 'title', 'behaviorTaxRate', 'unit', 'value', 'permanent', 'dateStart', 'dateEnd', 'usersActive', 'users', 'groupUsersActive', 'groupUsers', 'productCategoriesActive', 'productCategories', 'productFamiliesActive', 'productFamilies', 'status', 'isDisplayed' ]; } public function configureFields(): array { 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), 'behaviorTaxRate' => ChoiceField::new('behaviorTaxRate') ->setFormTypeOption('required', true) ->setFormTypeOption('empty_data', TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED) ->setChoices( $this->translatorAdmin->transChoices( TaxRateModel::getBehaviorTaxRateChoices(), 'TaxRate', 'behaviorTaxRate' ) ), 'unit' => ChoiceField::new('unit') ->setFormTypeOption('expanded', true) ->setFormTypeOption('required', true) ->setChoices( $this->translatorAdmin->transChoices( UnitModel::getUnitAmountChoices(), 'Unit', 'unit' ) ), 'value' => NumberField::new('value')->setTemplatePath('@LcCaracole/admin/reduction/field/amount.html.twig'), 'permanent' => BooleanField::new('permanent'), 'dateStart' => DateTimeField::new('dateStart'), 'dateEnd' => DateTimeField::new('dateEnd'), 'isDisplayed'=> BooleanField::new('isDisplayed'), 'groupUsersActive' => BooleanField::new('groupUsersActive')->setFormTypeOption('mapped', false), 'groupUsers' => AssociationField::new('groupUsers') ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') ->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', $this->usersArray) ->setFormTypeOption( 'choice_attr', function ($choice, $key, $value) { $data = array(); foreach ($choice->getGroupUsers() as $groupUser) { $data[] = '_' . $groupUser->getId() . '_'; } return ['data-group-users' => json_encode($data)]; }, ), 'productCategoriesActive' => BooleanField::new('productCategoriesActive')->setFormTypeOption('mapped', false), 'productCategories' => AssociationField::new('productCategories') ->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') ->setFormTypeOption('choice_label', // @TODO : attention, code dupliqué de ProductCategoriesFilter function ($category) { $isOffline = ''; if ($category->getStatus() != 1) { $isOffline = " [Hors ligne]"; } $section = ' [' . $category->getSection()->getTitle() . ']';; return $category . $section . $isOffline; }) ->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', $this->productFamilyArray) ->setFormTypeOption( 'choice_attr', function ($choice, $key, $value) { $data = array(); foreach ($choice->getProductCategories() as $category) { $data[] = '_' . $category->getId() . '_'; } return [ 'data-product-categories' => json_encode($data), 'data-supplier' => $choice->getSupplier()->getId() ]; } ), 'productFamily' => AssociationField::new('productFamily') ->setFormTypeOption('choices', $this->productFamilyArray) ]; } }