Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /**
  2. * @param array $parameters
  3. * @param array $queryParams
  4. * @return mixed
  5. */
  6. public function findOneTypeCompaniesInCityBySlug(array $parameters, array $queryParams = [])
  7. {
  8. $qb = $this->createQueryBuilder('company')
  9. ->join('company.city', 'city')
  10. ->join('company.types', 'type')
  11. ->andWhere('city.slug = :citySlug')
  12. ->setParameter('citySlug', $parameters['citySlug'])
  13. ->andWhere('type.slug = :typeSlug')
  14. ->setParameter('typeSlug', $parameters['typeSlug'])
  15. ->andWhere('company.status = :statusEnabled')
  16. ->setParameter('statusEnabled', Company::STATUS_ENABLED);
  17.  
  18. $this->addFilterByPostCode($qb, $queryParams);
  19. $this->addFilterByTags($qb, $queryParams);
  20. $this->addLimitsToQueryBuilder($qb, $queryParams);
  21.  
  22. return $qb->getQuery()->getResult();
  23. }
  24.  
  25. /**
  26. * @param QueryBuilder $qb
  27. * @param array $queryParams
  28. * @return QueryBuilder
  29. */
  30. private function addFilterByTags(QueryBuilder $qb, array $queryParams)
  31. {
  32. if (isset($queryParams['tags']) && !empty($queryParams['tags'])) {
  33.  
  34. /** @var ArrayCollection $queryParams['tags'] */
  35. foreach ($queryParams['tags'] as $key => $tag) {
  36. $qb->andWhere(':tag' . $key . ' MEMBER OF company.tags')
  37. ->setParameter('tag' . $key, $tag);
  38. }
  39.  
  40. }
  41.  
  42. return $qb;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement