vendor\project-biz\database-bundle\src\Database\Criteria\CriteriaComposite.php line 49

Open in your IDE?
  1. <?php
  2. namespace ProjectBiz\DatabaseBundle\Database\Criteria;
  3. use Doctrine\DBAL\Query\QueryBuilder;
  4. use ProjectBiz\PortalBundle\Exceptions\PortalException;
  5. class CriteriaComposite implements CriteriaBuilderInterface\JsonSerializable
  6. {
  7.     const msgUnknownOperator 'Der Operator "%operator%" ist unbekannt.';
  8.     private $operator;
  9.     /** @var  CriteriaBuilderInterface[] */
  10.     private $params;
  11.     public function __construct($operator$params)
  12.     {
  13.         $this->operator strtoupper($operator);
  14.         $this->params   $params;
  15.     }
  16.     public function buildCriteria(QueryBuilder $builder, array $columnMap$processedView$mt_name 'mt')
  17.     {
  18.         $params array_map(
  19.             function (CriteriaBuilderInterface $param) use ($builder$columnMap$processedView$mt_name) {
  20.                 return $param->buildCriteria($builder$columnMap$processedView$mt_name);
  21.             },
  22.             $this->params
  23.         );
  24.         if ($this->operator == 'AND') {
  25.             return call_user_func_array([$builder->expr(), 'andX'], $params);
  26.         } else {
  27.             if ($this->operator == 'OR') {
  28.                 return call_user_func_array([$builder->expr(), 'orX'], $params);
  29.             } else {
  30.                 throw new PortalException(self::msgUnknownOperator, ['%operator%' => $this->operator]);
  31.             }
  32.         }
  33.     }
  34.     /**
  35.      * (PHP 5 &gt;= 5.4.0)<br/>
  36.      * Specify data which should be serialized to JSON
  37.      * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  38.      * @return mixed data which can be serialized by <b>json_encode</b>,
  39.      * which is a value of any type other than a resource.
  40.      */
  41.     public function jsonSerialize()
  42.     {
  43.         $params = [];
  44.         foreach ($this->params as $param) {
  45.             $params[] = $param->jsonSerialize();
  46.         }
  47.         return [
  48.             'type'     => 'composite',
  49.             'operator' => $this->operator,
  50.             'params'   => $params
  51.         ];
  52.     }
  53. }