vendor/ibexa/core/src/lib/Search/Legacy/Content/Common/Gateway/CriterionHandler.php line 43

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace Ibexa\Core\Search\Legacy\Content\Common\Gateway;
  7. use Doctrine\DBAL\Connection;
  8. use Doctrine\DBAL\Query\QueryBuilder;
  9. use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
  10. use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Operator;
  11. abstract class CriterionHandler
  12. {
  13.     /**
  14.      * Map of criterion operators to the respective function names in the zeta
  15.      * Database abstraction layer.
  16.      *
  17.      * @var array
  18.      */
  19.     protected $comparatorMap = [
  20.         Operator::EQ => 'eq',
  21.         Operator::GT => 'gt',
  22.         Operator::GTE => 'gte',
  23.         Operator::LT => 'lt',
  24.         Operator::LTE => 'lte',
  25.         Operator::LIKE => 'like',
  26.     ];
  27.     /** @var \Doctrine\DBAL\Connection */
  28.     protected $connection;
  29.     /** @var \Doctrine\DBAL\Platforms\AbstractPlatform|null */
  30.     protected $dbPlatform;
  31.     /**
  32.      * @throws \Doctrine\DBAL\DBALException
  33.      */
  34.     public function __construct(Connection $connection)
  35.     {
  36.         $this->connection $connection;
  37.         $this->dbPlatform $connection->getDatabasePlatform();
  38.     }
  39.     /**
  40.      * Check if this criterion handler accepts to handle the given criterion.
  41.      *
  42.      * @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion $criterion
  43.      *
  44.      * @return bool
  45.      */
  46.     abstract public function accept(Criterion $criterion);
  47.     /**
  48.      * Generate query expression for a Criterion this handler accepts.
  49.      *
  50.      * accept() must be called before calling this method.
  51.      *
  52.      * @param array $languageSettings
  53.      *
  54.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException
  55.      * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
  56.      *
  57.      * @return \Doctrine\DBAL\Query\Expression\CompositeExpression|string
  58.      */
  59.     abstract public function handle(
  60.         CriteriaConverter $converter,
  61.         QueryBuilder $queryBuilder,
  62.         Criterion $criterion,
  63.         array $languageSettings
  64.     );
  65.     protected function hasJoinedTableAs(QueryBuilder $queryBuilderstring $tableAlias): bool
  66.     {
  67.         // find table name in a structure: ['fromAlias' => [['joinTable' => '<table_name>'], ...]]
  68.         $joinedParts $queryBuilder->getQueryPart('join');
  69.         foreach ($joinedParts as $joinedTables) {
  70.             foreach ($joinedTables as $join) {
  71.                 if ($join['joinAlias'] === $tableAlias) {
  72.                     return true;
  73.                 }
  74.             }
  75.         }
  76.         return false;
  77.     }
  78. }
  79. class_alias(CriterionHandler::class, 'eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler');