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

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

/**
 * FormEntry Repository
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class FormEntryRepository extends FormEntryManager 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 == 'status' AND $value != '') {
                $qb->andWhere($qb->expr()->eq($this->getFullFieldName('status'), $qb->expr()->literal($value)));
            } elseif ($option == 'toegevoegd_gte' AND $value != '') {
                $qb->andWhere($qb->expr()->gte($this->getFullFieldName('toegevoegd'), $qb->expr()->literal($value)));
            } elseif ($option == 'toegevoegd_lte' AND $value != '') {
                $qb->andWhere($qb->expr()->lte($this->getFullFieldName('toegevoegd'), $qb->expr()->literal($value)));
            } elseif ($option == 'form_id' AND $value != '') {
                $qb->andWhere($qb->expr()->eq($this->getFullFieldName('form'), $qb->expr()->literal($value)));
            } elseif ($option == 'search' AND $value != '') {
                $qb->andWhere($qb->expr()->orX(
                    $qb->expr()->like($this->getFullFieldName('rawdata'), $qb->expr()->literal('%' . $value . '%')),
                    $qb->expr()->like($this->getFullFieldName('url'), $qb->expr()->literal('%' . $value . '%'))
                ));
            }
        }
    }

}
