You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
Hello, I have a specific problem with Lexik Form Filter Bundle in Symfony 3.4. I implemented a function in order to retrieve a list of objects. It exploits joining of entities as follows:
Please, note that $mediaContentsIds and $countryIds are passed by reference to $this->getMediaContentCountriesMaxReachPercent(). In this way, I retrieve a QueryBuilder object, which is subsequently passed to Lexif Form Filter Bundle inside a suitable Controller, as follows:
/** @var QueryBuilder $qbContents */ $qbContents = $repo->getQueryBuilderMediaContents($page, $limit, $orderBy, $orderType); $filterForm = $this->get('form.factory')->create(MediaContentsFilterType::class); if ($request->query->has($filterForm->getName())) { // manually bind values from the request $filterForm->submit($request->query->get($filterForm->getName())); // build the query from the given form object $qbUpdater = $this->get('lexik_form_filter.query_builder_updater'); $qbUpdater->addFilterConditions($filterForm, $qbNumContents); $qbUpdater->setParts(array( '__root__' => 'mc', 'mc.mediaContentCampaigns' => 'mcc', 'mc.mediaContentProducts' => 'mcp', 'mc.mediaContentCountries' => 'mco', )) // set the joins ->addFilterConditions($filterForm, $qbContents) // then add filter conditions ; }
Now, you see the way I used setParts, but I am not pretty sure about it, since the way I joined tables within getQueryBuilderMediaContents() function. On the other hand, I was forced to join tables in that way, since MediaContents entity is related to MediaContentsCampaigns, MediaContentsProducts and MediaContentsCountries entities by means of One-To-Many mappings.
Please, how to work with setParts function of Lexik FormFilter Bundle correctly, as per the case described? Am I correct, or should I change something? Thanks for your replies.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello, I have a specific problem with Lexik Form Filter Bundle in Symfony 3.4. I implemented a function in order to retrieve a list of objects. It exploits joining of entities as follows:
public function getQueryBuilderMediaContents($page, $limit = 20, $orderBy = 'id', $orderType = Criteria::ASC) { $offset = ($page - 1) * $limit; $qb = $this->createQueryBuilder('mc'); $mediaContentsIds = array(); $countryIds = array(); $this->getMediaContentCountriesMaxReachPercent($mediaContentsIds, $countryIds); return $qb->select('mc, mcc, mcp, mcco') ->join(MediaContentsCampaigns::REPOSITORY, 'mcc', Expr\Join::WITH, $qb->expr()->eq('mc', 'mcc.mediaContent')) ->join('mcc.campaign', 'c') ->join(MediaContentsProducts::REPOSITORY, 'mcp', Expr\Join::WITH, $qb->expr()->eq('mc', 'mcp.mediaContent')) ->join('mcp.productGroup', 'p') ->leftJoin(MediaContentsCountries::REPOSITORY, 'mcco', Expr\Join::WITH, $qb->expr()->eq('mc', 'mcco.mediaContent')) ->join('mcco.country', 'co') ->where($qb->expr()->andX( $qb->expr()->in('mcco.mediaContent', $mediaContentsIds), $qb->expr()->in('mcco.country', $countryIds) ) ) ->setFirstResult($offset) ->setMaxResults($limit) ->orderBy($orderBy, $orderType) ->groupBy('mc.id') ; }
Please, note that $mediaContentsIds and $countryIds are passed by reference to $this->getMediaContentCountriesMaxReachPercent(). In this way, I retrieve a QueryBuilder object, which is subsequently passed to Lexif Form Filter Bundle inside a suitable Controller, as follows:
/** @var QueryBuilder $qbContents */ $qbContents = $repo->getQueryBuilderMediaContents($page, $limit, $orderBy, $orderType); $filterForm = $this->get('form.factory')->create(MediaContentsFilterType::class); if ($request->query->has($filterForm->getName())) { // manually bind values from the request $filterForm->submit($request->query->get($filterForm->getName())); // build the query from the given form object $qbUpdater = $this->get('lexik_form_filter.query_builder_updater'); $qbUpdater->addFilterConditions($filterForm, $qbNumContents); $qbUpdater->setParts(array( '__root__' => 'mc', 'mc.mediaContentCampaigns' => 'mcc', 'mc.mediaContentProducts' => 'mcp', 'mc.mediaContentCountries' => 'mco', )) // set the joins ->addFilterConditions($filterForm, $qbContents) // then add filter conditions ; }
Now, you see the way I used setParts, but I am not pretty sure about it, since the way I joined tables within getQueryBuilderMediaContents() function. On the other hand, I was forced to join tables in that way, since MediaContents entity is related to MediaContentsCampaigns, MediaContentsProducts and MediaContentsCountries entities by means of One-To-Many mappings.
Please, how to work with setParts function of Lexik FormFilter Bundle correctly, as per the case described? Am I correct, or should I change something? Thanks for your replies.
The text was updated successfully, but these errors were encountered: