addWhere example

$subselect->condition('c.uid', $this->argument);

      $entity_id = $this->definition['entity_id'];
      $entity_type = $this->definition['entity_type'];
      $subselect->where("[c].[entity_id] = [$this->tableAlias].[$entity_id]");
      $subselect->condition('c.entity_type', $entity_type);

      $condition = ($this->view->query->getConnection()->condition('OR'))
        ->condition("$this->tableAlias.uid", $this->argument, '=')
        ->exists($subselect);

      $this->query->addWhere(0, $condition);
    }
  }

  /** * {@inheritdoc} */
  public function getSortName() {
    return $this->t('Numerical', []['context' => 'Sort order']);
  }

}


  /** * Add this filter to the query. * * Due to the nature of fapi, the value and the operator have an unintended * level of indirection. You will find them in $this->operator * and $this->value respectively. */
  public function query() {
    $this->ensureMyTable();
    $this->query->addWhere($this->options['group'], "$this->tableAlias.$this->realField", $this->value, $this->operator);
  }

  /** * Can this filter be used in OR groups? * * Some filters have complicated where clauses that cannot be easily used * with OR groups. Some filters must also use HAVING which also makes * them not groupable. These filters will end up in a special group * if OR grouping is in use. * * @return bool */
'field' => $keys['id'],
      'left_table' => $query_base_table,
      'left_field' => $keys['id'],
      'extra' => [
        ['left_field' => $keys['revision'], 'field' => $keys['revision'], 'operator' => '>'],
      ],
    ];

    $join = $this->joinHandler->createInstance('standard', $definition);

    $join_table_alias = $query->addTable($query_base_table$this->relationship, $join);
    $query->addWhere($this->options['group'], "$join_table_alias.{$keys['id']}", NULL, 'IS NULL');
  }

}


  /** * Filters by operator between. * * @param object $field * The views field. */
  protected function opBetween($field) {
    if (is_numeric($this->value['min']) && is_numeric($this->value['max'])) {
      $operator = $this->operator == 'between' ? 'BETWEEN' : 'NOT BETWEEN';
      $this->query->addWhere($this->options['group']$field[$this->value['min']$this->value['max']]$operator);
    }
    elseif (is_numeric($this->value['min'])) {
      $operator = $this->operator == 'between' ? '>=' : '<';
      $this->query->addWhere($this->options['group']$field$this->value['min']$operator);
    }
    elseif (is_numeric($this->value['max'])) {
      $operator = $this->operator == 'between' ? '<=' : '>';
      $this->query->addWhere($this->options['group']$field$this->value['max']$operator);
    }
  }

  
$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.

class UserUid extends CommentUserUid {

  /** * {@inheritdoc} */
  public function query($group_by = FALSE) {
    // Because this handler thinks it's an argument for a field on the {node}     // table, we need to make sure {tracker_user} is JOINed and use its alias     // for the WHERE clause.     $tracker_user_alias = $this->query->ensureTable('tracker_user');
    $this->query->addWhere(0, "$tracker_user_alias.uid", $this->argument);
  }

}

  }

  protected function opSimple() {
    if (empty($this->value)) {
      return;
    }
    $this->ensureMyTable();

    // We use array_values() because the checkboxes keep keys and that can cause     // array addition problems.     $this->query->addWhere($this->options['group'], "$this->tableAlias.$this->realField", array_values($this->value)$this->operator);
  }

  protected function opEmpty() {
    $this->ensureMyTable();
    if ($this->operator == 'empty') {
      $operator = "IS NULL";
    }
    else {
      $operator = "IS NOT NULL";
    }

    
if (!empty($field_id)) {
          // Get the table and field names for the checked field.           $field_handler = $this->view->field[$field_id];
          $table_alias = $this->view->query->ensureTable($field_handler->table, $field_handler->relationship);
          $field_alias = $this->view->query->addField($table_alias$field_handler->realField);
          $field = $this->view->query->fields[$field_alias];
          // Add an OR condition for the field.           $conditions->condition($field['table'] . '.' . $field['field']$value, 'LIKE');
        }
      }

      $this->view->query->addWhere(0, $conditions);
    }

    // Add an IN condition for validation.     if (!empty($options['ids'])) {
      $this->view->query->addWhere(0, $id_table . '.' . $id_field$options['ids'], 'IN');
    }

    $this->view->setItemsPerPage($options['limit']);
  }

  /** * {@inheritdoc} */
if (empty($this->argument)) {
        $empty = TRUE;
      }
    }
    else {
      if (!isset($this->argument)) {
        $empty = TRUE;
      }
    }
    if ($empty) {
      parent::ensureMyTable();
      $this->query->addWhere(0, "$this->tableAlias.$this->realField", NULL, 'IS NULL');
      return;
    }

    if (!empty($this->options['break_phrase'])) {
      $force_int = !empty($this->definition['numeric']);
      $this->unpackArgumentValue($force_int);
    }
    else {
      $this->value = [$this->argument];
      $this->operator = 'or';
    }

    
$or = $this->view->query->getConnection()->condition('OR');

    if (empty($this->value)) {
      $or->condition($field, '***CURRENT_USER***', '<>');
      if ($this->accept_null) {
        $or->isNull($field);
      }
    }
    else {
      $or->condition($field, '***CURRENT_USER***', '=');
    }
    $this->query->addWhere($this->options['group']$or);
  }

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    $contexts = parent::getCacheContexts();

    // This filter depends on the current user.     $contexts[] = 'user';

    
$parsed = $this->parse($query->getQuery()$definition$context$root);

            foreach ($parsed->getWheres() as $where) {
                if ($query->getScoreField()) {
                    $field = $this->queryHelper->getFieldAccessor(
                        $query->getScoreField(),
                        $definition,
                        $root,
                        $context
                    );

                    $result->addWhere(
                        sprintf('IF(%s , %s * %s, 0)', $where(string) $this->connection->quote($query->getScore())$field)
                    );

                    continue;
                }

                $result->addWhere(
                    sprintf('IF(%s , %s, 0)', $where(string) $this->connection->quote($query->getScore()))
                );
            }

            
$and = $this->view->query->getConnection()->condition('AND');
      $and
        ->condition("$this->tableAlias.workflow", $workflow_id, '=')
        ->condition("$this->tableAlias.$this->realField", $state_id$operator);

      $field->condition($and);
    }

    if ($bundle_condition) {
      // The query must match the bundle AND the workflow/state conditions.       $bundle_condition->condition($field);
      $this->query->addWhere($this->options['group']$bundle_condition);
    }
    else {
      $this->query->addWhere($this->options['group']$field);
    }
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    
/** * Build the query based upon the formula. */
  public function query($group_by = FALSE) {
    $this->ensureMyTable();
    // Now that our table is secure, get our formula.     $placeholder = $this->placeholder();
    $formula = $this->getFormula() . ' = ' . $placeholder;
    $placeholders = [
      $placeholder => $this->argument,
    ];
    $this->query->addWhere(0, $formula$placeholders, 'formula');
  }

}
$field .= " IN($placeholder)";
      }
      else {
        $field .= ' = ' . $placeholder;
      }
      $placeholders = [
        $placeholder => $argument,
      ];
      $this->query->addWhereExpression(0, $field$placeholders);
    }
    else {
      $this->query->addWhere(0, $field$argument$operator);
    }
  }

  public function summaryArgument($data) {
    $value = $this->caseTransform($data->{$this->base_alias}$this->options['path_case']);
    if (!empty($this->options['transform_dash'])) {
      $value = strtr($value, ' ', '-');
    }
    return $value;
  }

  

    return $value;
  }

  /** * Set up the query for this argument. * * The argument sent may be found at $this->argument. */
  public function query($group_by = FALSE) {
    $this->ensureMyTable();
    $this->query->addWhere(0, "$this->tableAlias.$this->realField", $this->argument);
  }

  /** * Get the title this argument will assign the view, given the argument. * * This usually needs to be overridden to provide a proper title. */
  public function title() {
    return $this->argument;
  }

  
Home | Imprint | This part of the site doesn't use cookies.