setProperty($propertyName) ->setLabel($label) ->setTemplateName('crud/field/association') ->setFormType(EntityType::class) ->addCssClass('field-association') ->setCustomOption(self::OPTION_AUTOCOMPLETE, false) ->setCustomOption(self::OPTION_CRUD_CONTROLLER, null) ->setCustomOption(self::OPTION_WIDGET, self::WIDGET_AUTOCOMPLETE) ->setCustomOption(self::OPTION_QUERY_BUILDER_CALLABLE, null) ->setCustomOption(self::OPTION_RELATED_URL, null) ->setCustomOption(self::OPTION_DOCTRINE_ASSOCIATION_TYPE, null); } public function setFilterOnSection(SectionInterface $section): self { $this->queryBuilderParameters['section'] = $section; return $this; } public function setFilterOnMerchant(MerchantInterface $merchant): self { $this->queryBuilderParameters['merchant'] = $merchant; return $this; } public function setFilterOnDevAlias(string $devAlias): self { $this->queryBuilderParameters['devAlias'] = $devAlias; return $this; } public function setFilterIsOnline(): self { $this->queryBuilderParameters['status'] = 1; return $this; } public function addOrderBy($field, $direction ='ASC') : self { $this->queryBuilderParameters['orderBy'][] = $field; $this->queryBuilderParameters['orderByDirection'][] = $direction; return $this; } public function initQueryBuilder(): self { $param = $this->queryBuilderParameters; $this->setFormTypeOption( 'query_builder', function (EntityRepository $er) use ($param) { $qb = $er->createQueryBuilder('e'); if (isset($param['section'])) { $qb->andWhereSection('e',$param['section']); } if (isset($param['merchant'])) { $qb->andWhereMerchant('e',$param['merchant']); } if (isset($param['status'])) { $qb->andWhere('e.status = :status')->setParameter('status', $param['status']); } if (isset($param['orderBy'])) { foreach ($param['orderBy'] as $i=>$field) { $qb->addOrderBy('e.'.$param['orderBy'][$i], $param['orderByDirection'][$i]); } } /*if (isset($param['devAlias'])) { $qb->andWhere('e.devAlias = :devAlias')->setParameter( 'devAlias', $param['devAlias'] ); }*/ return $qb; } ); return $this; } public function autocomplete(): self { $this->setCustomOption(self::OPTION_AUTOCOMPLETE, true); return $this; } public function renderAsNativeWidget(bool $asNative = true): self { $this->setCustomOption(self::OPTION_WIDGET, $asNative ? self::WIDGET_NATIVE : self::WIDGET_AUTOCOMPLETE); return $this; } public function setCrudController(string $crudControllerFqcn): self { $this->setCustomOption(self::OPTION_CRUD_CONTROLLER, $crudControllerFqcn); return $this; } }