operator example

/** * Prefixes all fields in an EntityConditionGroup. */
  protected static function addConditionFieldPrefix(EntityConditionGroup $group$field_prefix) {
    $prefixed = [];
    foreach ($group->members() as $member) {
      if ($member instanceof EntityConditionGroup) {
        $prefixed[] = static::addConditionFieldPrefix($member$field_prefix);
      }
      else {
        $field = !empty($field_prefix) ? "{$field_prefix}." . $member->field() : $member->field();
        $prefixed[] = new EntityCondition($field$member->value()$member->operator());
      }
    }
    return new EntityConditionGroup($group->conjunction()$prefixed);
  }

  /** * Gets an EntityConditionGroup that filters out inaccessible entities. * * @param string $entity_type_id * The entity type ID for which to get an EntityConditionGroup. * @param \Drupal\Core\Cache\CacheableMetadata $cacheability * Collects cacheability for the query. * * @return \Drupal\jsonapi\Query\EntityConditionGroup|null * An EntityConditionGroup or NULL if no conditions need to be applied to * secure an entity query. */
$info = $this->operators();
    if (!empty($info[$this->operator]['method'])) {
      $this->{$info[$this->operator]['method']}($field);
    }
  }

  /** * Adds a where clause for the operation, 'equals'. */
  public function opEqual($field) {
    $this->query->addWhere($this->options['group']$field$this->value, $this->operator());
  }

  protected function opContains($field) {
    $operator = $this->getConditionOperator('LIKE');
    $this->query->addWhere($this->options['group']$field, '%' . $this->connection->escapeLike($this->value) . '%', $operator);
  }

  protected function opContainsWord($field) {
    $where = $this->operator == 'word' ? $this->query->getConnection()->condition('OR') : $this->query->getConnection()->condition('AND');

    // Don't filter on empty strings.
case 'OR':
        $group = $query->orConditionGroup();
        break;
    }

    // Get all children of the group.     $members = $condition_group->members();

    foreach ($members as $member) {
      // If the child is simply a condition, add it to the new group.       if ($member instanceof EntityCondition) {
        if ($member->operator() == 'IS NULL') {
          $group->notExists($member->field());
        }
        elseif ($member->operator() == 'IS NOT NULL') {
          $group->exists($member->field());
        }
        else {
          $group->condition($member->field()$member->value()$member->operator());
        }
      }
      // If the child is a group, then recursively construct a sub group.       elseif ($member instanceof EntityConditionGroup) {
        


  /** * @covers ::createFromQueryParameter * @dataProvider queryParameterProvider */
  public function testCreateFromQueryParameter($case) {
    $condition = EntityCondition::createFromQueryParameter($case);
    $this->assertEquals($case['path']$condition->field());
    $this->assertEquals($case['value']$condition->value());
    if (isset($case['operator'])) {
      $this->assertEquals($case['operator']$condition->operator());
    }
  }

  /** * Data provider for testDenormalize. */
  public function queryParameterProvider() {
    return [
      [['path' => 'some_field', 'value' => NULL, 'operator' => '=']],
      [['path' => 'some_field', 'operator' => '=', 'value' => 'some_string']],
      [['path' => 'some_field', 'operator' => '<>', 'value' => 'some_string']],
      [

        parent::__construct(['left' => $left, 'right' => $right][]$lineno);
    }

    public function compile(Compiler $compiler): void
    {
        $compiler
            ->raw('(')
            ->subcompile($this->getNode('left'))
            ->raw(' ')
        ;
        $this->operator($compiler);
        $compiler
            ->raw(' ')
            ->subcompile($this->getNode('right'))
            ->raw(')')
        ;
    }

    abstract public function operator(Compiler $compiler): Compiler;
}

    return $errors;
  }

  /** * {@inheritdoc} */
  public function opEqual($expression) {
    // By default, things like opEqual uses add_where, that doesn't support     // complex expressions, so override opEqual (and all operators below).     $placeholder = $this->placeholder();
    $operator = $this->getConditionOperator($this->operator());
    $this->query->addWhereExpression($this->options['group'], "$expression $operator $placeholder", [$placeholder => $this->value]);
  }

  protected function opContains($expression) {
    $placeholder = $this->placeholder();
    $operator = $this->getConditionOperator('LIKE');
    $this->query->addWhereExpression($this->options['group'], "$expression $operator $placeholder", [$placeholder => '%' . $this->connection->escapeLike($this->value) . '%']);
  }

  /** * Filters by one or more words. * * By default opContainsWord uses add_where, that doesn't support complex * expressions. * * @param string $expression * The expression to add to the query. */
abstract class AbstractUnary extends AbstractExpression
{
    public function __construct(Node $node, int $lineno)
    {
        parent::__construct(['node' => $node][]$lineno);
    }

    public function compile(Compiler $compiler): void
    {
        $compiler->raw(' ');
        $this->operator($compiler);
        $compiler->subcompile($this->getNode('node'));
    }

    abstract public function operator(Compiler $compiler): Compiler;
}
/** * @covers ::createFromQueryParameter * @dataProvider parameterProvider */
  public function testCreateFromQueryParameter($case$expected) {
    $resource_type = new ResourceType('foo', 'bar', NULL);
    $actual = Filter::createFromQueryParameter($case$resource_type$this->getFieldResolverMock($resource_type));
    $conditions = $actual->root()->members();
    for ($i = 0; $i < count($case)$i++) {
      $this->assertEquals($expected[$i]['path']$conditions[$i]->field());
      $this->assertEquals($expected[$i]['value']$conditions[$i]->value());
      $this->assertEquals($expected[$i]['operator']$conditions[$i]->operator());
    }
  }

  /** * Data provider for testCreateFromQueryParameter. */
  public function parameterProvider() {
    return [
      'shorthand' => [
        ['uid' => ['value' => 1]],
        [['path' => 'uid', 'value' => 1, 'operator' => '=']],
      ],
Home | Imprint | This part of the site doesn't use cookies.