<?php
/**
 * Form Repository
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
namespace VisualM\FormBundle\Entity;

use VisualM\FormBundle\Model\FormManager;
use Doctrine\ORM\QueryBuilder;
use VisualM\ModelManagementBundle\Definition\ModelManagerInterface;

/**
 * Form Repository
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class FormRepository extends FormManager implements ModelManagerInterface
{
    /**
     * {@inheritdoc}
     */
    protected function processConditions(array $options, QueryBuilder &$qb)
    {
        foreach($options as $option => $value) {
            if ($option == 'id') {
                $qb->andWhere($qb->expr()->eq($this->getFullFieldName('id'), $qb->expr()->literal($value)));
            } elseif ($option == 'n_id') {
                $qb->andWhere($qb->expr()->neq($this->getFullFieldName('id'), $qb->expr()->literal($value)));
            } elseif ($option == 'referentie') {
                $qb->andWhere($qb->expr()->eq($this->getFullFieldName('referentie'), $qb->expr()->literal($value)));
            } elseif ($option == 'search' AND $value != '') {
                $qb->andWhere($qb->expr()->orX(
                    $qb->expr()->like($this->getFullFieldName('titel'), $qb->expr()->literal('%' . $value . '%')),
                    $qb->expr()->like($this->getFullFieldName('referentie'), $qb->expr()->literal('%' . $value . '%'))
                ));
            }
        }
    }

}
