public function chooseAction(Request $request) { $filter = new BannerPositionChoiceFilter(); $pagination = $filter->getPagination()->enable(); $filter->loadFromRequest($request); $filterForm = $this->createForm(BannerPositionChoiceFilterType::class, $filter); $filter->load($request, $filterForm); $repo = $this->get('wucdbm_banner.repo.banner_positions'); $positions = $repo->filterForChoose($filter); $forms = []; /** @var BannerPosition $position */ foreach ($positions as $position) { $forms[$position->getId()] = $this->createForm(BannerPositionChooseType::class, $position, ['attr' => ['class' => 'position-form'], 'action' => $this->generateUrl('wucdbm_banner_choice_update_banner', ['id' => $position->getId()])])->createView(); } $data = ['filter' => $filter, 'pagination' => $pagination, 'filterForm' => $filterForm->createView(), 'forms' => $forms]; return $this->render('@WucdbmBanner/BannerChoice/choose.html.twig', $data); }
/** * @param BannerPositionChoiceFilter $filter * @return BannerPosition[] */ public function filterForChoose(BannerPositionChoiceFilter $filter) { $builder = $this->createQueryBuilder('p')->addSelect('b')->leftJoin('p.banner', 'b'); if (null !== $filter->getBannerStatus()) { switch ($filter->getBannerStatus()) { case BannerPositionChoiceFilter::BANNER_STATUS_HAS_BANNER: $builder->andWhere('p.banner IS NOT NULL'); break; case BannerPositionChoiceFilter::BANNER_STATUS_DOES_NOT_HAVE_BANNER: $builder->andWhere('p.banner IS NULL'); break; } } if ($filter->getId()) { $builder->andWhere('p.id = :id')->setParameter('id', $filter->getId()); } return $this->returnFilteredEntities($builder, $filter, 'p.id'); }