lib/composer/MenuBundle/src/VisualMedia/MenuBundle/Repository/BaseMenuItemRepository.php line 65

Open in your IDE?
  1. <?php
  2. /**
  3. * Base Menu Item Repository
  4. *
  5. * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
  6. */
  7. namespace VisualMedia\MenuBundle\Repository;
  8. use Doctrine\ORM\QueryBuilder;
  9. use VisualMedia\LisaBundle\Component\Interfaces\EntityInterface;
  10. use VisualMedia\LisaBundle\Component\Manager;
  11. /**
  12. * Base Menu Item Repository
  13. */
  14. abstract class BaseMenuItemRepository extends Manager
  15. {
  16. const OPTION_ID = 'id';
  17. const OPTION_NOT_ID = 'not_id';
  18. const OPTION_TITLE = 'title';
  19. const OPTION_MENU = 'menu';
  20. const OPTION_PARENT = 'parent';
  21. const FIELD_MENU = 'menu';
  22. const ALIAS_MENU = '_menu';
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function processConditions(QueryBuilder &$qb, array $options) : void
  27. {
  28. foreach ($options as $option=>$value) {
  29. if ($option == static::OPTION_ID) {
  30. $qb->andWhere($qb->expr()->eq($this->getFullFieldName(static::OPTION_ID), $qb->expr()->literal((string) $value)));
  31. }
  32. else if ($option =="link"){
  33. $qb->andWhere($qb->expr()->eq($this->getFullFieldName("link"),$qb->expr()->literal((string) $value)));
  34. }
  35. if ($option == static::OPTION_NOT_ID) {
  36. $qb->andWhere($qb->expr()->neq($this->getFullFieldName(static::OPTION_ID), $qb->expr()->literal((string) $value)));
  37. }
  38. elseif ($option == static::OPTION_MENU) {
  39. $qb->andWhere($qb->expr()->eq($this->getFullFieldName(static::OPTION_MENU), $qb->expr()->literal((string) $value)));
  40. }
  41. elseif ($option == static::OPTION_PARENT) {
  42. $qb->andWhere($qb->expr()->eq($this->getFullFieldName(static::OPTION_PARENT), $qb->expr()->literal((string) $value)));
  43. }
  44. elseif ($option == static::OPTION_SEARCH) {
  45. $qb->andWhere($qb->expr()->orX(
  46. $qb->expr()->eq($this->getFullFieldName(static::OPTION_ID), $qb->expr()->literal((string) $value)),
  47. $qb->expr()->like($this->getFullFieldName(static::OPTION_TITLE), $qb->expr()->literal((string) '%' . $value . '%'))
  48. ));
  49. }
  50. }
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function getOrderingQueryBuilder(EntityInterface $entity = null): QueryBuilder
  56. {
  57. $qb = parent::getOrderingQueryBuilder($entity);
  58. if ($entity->menu) {
  59. $qb->andWhere(sprintf('e.menu = %d', $entity->menu->id));
  60. }
  61. return $qb;
  62. }
  63. }