<?php
/**
* Base Menu Item Repository
*
* @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
*/
namespace VisualMedia\MenuBundle\Repository;
use Doctrine\ORM\QueryBuilder;
use VisualMedia\LisaBundle\Component\Interfaces\EntityInterface;
use VisualMedia\LisaBundle\Component\Manager;
/**
* Base Menu Item Repository
*/
abstract class BaseMenuItemRepository extends Manager
{
const OPTION_ID = 'id';
const OPTION_NOT_ID = 'not_id';
const OPTION_TITLE = 'title';
const OPTION_MENU = 'menu';
const OPTION_PARENT = 'parent';
const FIELD_MENU = 'menu';
const ALIAS_MENU = '_menu';
/**
* {@inheritdoc}
*/
public function processConditions(QueryBuilder &$qb, array $options) : void
{
foreach ($options as $option=>$value) {
if ($option == static::OPTION_ID) {
$qb->andWhere($qb->expr()->eq($this->getFullFieldName(static::OPTION_ID), $qb->expr()->literal((string) $value)));
}
else if ($option =="link"){
$qb->andWhere($qb->expr()->eq($this->getFullFieldName("link"),$qb->expr()->literal((string) $value)));
}
if ($option == static::OPTION_NOT_ID) {
$qb->andWhere($qb->expr()->neq($this->getFullFieldName(static::OPTION_ID), $qb->expr()->literal((string) $value)));
}
elseif ($option == static::OPTION_MENU) {
$qb->andWhere($qb->expr()->eq($this->getFullFieldName(static::OPTION_MENU), $qb->expr()->literal((string) $value)));
}
elseif ($option == static::OPTION_PARENT) {
$qb->andWhere($qb->expr()->eq($this->getFullFieldName(static::OPTION_PARENT), $qb->expr()->literal((string) $value)));
}
elseif ($option == static::OPTION_SEARCH) {
$qb->andWhere($qb->expr()->orX(
$qb->expr()->eq($this->getFullFieldName(static::OPTION_ID), $qb->expr()->literal((string) $value)),
$qb->expr()->like($this->getFullFieldName(static::OPTION_TITLE), $qb->expr()->literal((string) '%' . $value . '%'))
));
}
}
}
/**
* {@inheritdoc}
*/
public function getOrderingQueryBuilder(EntityInterface $entity = null): QueryBuilder
{
$qb = parent::getOrderingQueryBuilder($entity);
if ($entity->menu) {
$qb->andWhere(sprintf('e.menu = %d', $entity->menu->id));
}
return $qb;
}
}