<?php
namespace ProjectBiz\DatabaseBundle\Database\Criteria;
use Doctrine\DBAL\Query\QueryBuilder;
use ProjectBiz\PortalBundle\Exceptions\PortalException;
class CriteriaComparison implements CriteriaBuilderInterface, \JsonSerializable
{
const msgNotSerializable = 'Die Operanden können nicht serialisiert werden.';
private $operator;
private $left;
private $right;
public function __construct($operator, CriteriaBuilderInterface $left, CriteriaBuilderInterface $right)
{
$this->operator = $operator;
$this->left = $left;
$this->right = $right;
}
public function buildCriteria(QueryBuilder $builder, array $columnMap, $processedView, $mt_name = 'mt')
{
return $builder->expr()->comparison(
$this->left->buildCriteria($builder, $columnMap, $processedView, $mt_name),
$this->operator,
$this->right->buildCriteria($builder, $columnMap, $processedView, $mt_name)
);
}
/**
* (PHP 5 >= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
public function jsonSerialize()
{
if (
($this->left instanceof \JsonSerializable) && ($this->right instanceof \JsonSerializable)
) {
return [
'type' => "comparison",
'operator' => $this->operator,
'left' => $this->left->jsonSerialize(),
'right' => $this->right->jsonSerialize()
];
} else {
throw new PortalException(self::msgNotSerializable);
}
}
}