nextPlaceholder example

// Add the SQL query to the object before calling this method again.         $condition['field']->sqlQuery = $sql_query;
        $condition['field']->compile($sql_condition);
        $sql_query->condition($sql_condition);
      }
      else {
        $type = ((strtoupper($this->conjunction) == 'OR') || ($condition['operator'] == 'IS NULL')) ? 'LEFT' : 'INNER';
        $field = $tables->addField($condition['field']$type$condition['langcode']);
        $condition_class = QueryBase::getClass($this->namespaces, 'Condition');
        $condition_class::translateCondition($condition$sql_query$tables->isFieldCaseSensitive($condition['field']));
        $function = $condition['function'];
        $placeholder = ':db_placeholder_' . $conditionContainer->nextPlaceholder();
        $sql_field_escaped = '[' . str_replace('.', '].[', $field) . ']';
        $conditionContainer->having("$function($sql_field_escaped) {$condition['operator']} $placeholder", [$placeholder => $condition['value']]);
      }
    }
  }

  /** * {@inheritdoc} */
  public function exists($field$function$langcode = NULL) {
    return $this->condition($field$function, NULL, 'IS NOT NULL', $langcode);
  }
foreach ($condition['value'] as $value) {
            if ($value instanceof SelectInterface) {
              // Right hand part is a subquery. Compile, put brackets around it               // and collect any arguments.               $value->compile($connection$queryPlaceholder);
              $value_fragment[] = '(' . (string) $value . ')';
              $arguments += $value->arguments();
            }
            else {
              // Right hand part is a normal value. Replace the value with a               // placeholder and add the value as an argument.               $placeholder = ':db_condition_placeholder_' . $queryPlaceholder->nextPlaceholder();
              $value_fragment[] = $placeholder;
              $arguments[$placeholder] = $value;
            }
          }
          $value_fragment = $operator['prefix'] . implode($operator['delimiter']$value_fragment) . $operator['postfix'];
        }

        // Concatenate the left hand part, operator and right hand part.         $condition_fragments[] = trim(implode(' ', [$field_fragment$operator_fragment$value_fragment]));
      }

      
foreach ($this->extra as $info) {
          // Figure out the table name. Remember, only use aliases provided           // if at all possible.           $join_table = '';
          if (!array_key_exists('table', $info)) {
            $join_table = $table['alias'] . '.';
          }
          elseif (isset($info['table'])) {
            $join_table = $info['table'] . '.';
          }

          $placeholder = ':views_join_condition_' . $select_query->nextPlaceholder();

          if (is_array($info['value'])) {
            $operator = !empty($info['operator']) ? $info['operator'] : 'IN';
            // Transform from IN() notation to = notation if just one value.             if (count($info['value']) == 1) {
              $info['value'] = array_shift($info['value']);
              $operator = $operator == 'NOT IN' ? '!=' : '=';
            }
          }
          else {
            $operator = !empty($info['operator']) ? $info['operator'] : '=';
          }

  protected function addJoin($type$table$join_condition$langcode$delta = NULL) {
    $arguments = [];
    if ($langcode) {
      $entity_type_id = $this->sqlQuery->getMetaData('entity_type');
      $entity_type = $this->entityTypeManager->getActiveDefinition($entity_type_id);
      // Only the data table follows the entity language key, dedicated field       // tables have a hard-coded 'langcode' column.       $langcode_key = $entity_type->getDataTable() == $table ? $entity_type->getKey('langcode') : 'langcode';
      $placeholder = ':langcode' . $this->sqlQuery->nextPlaceholder();
      $join_condition .= ' AND [%alias].[' . $langcode_key . '] = ' . $placeholder;
      $arguments[$placeholder] = $langcode;
    }
    if (isset($delta)) {
      $placeholder = ':delta' . $this->sqlQuery->nextPlaceholder();
      $join_condition .= ' AND [%alias].[delta] = ' . $placeholder;
      $arguments[$placeholder] = $delta;
    }
    return $this->sqlQuery->addJoin($type$table, NULL, $join_condition$arguments);
  }

  
$connection = $this->prophesize(Connection::class);
    $connection->escapeField($field_name)->will(function D$args) {
      return preg_replace('/[^A-Za-z0-9_.]+/', '', $args[0]);
    });
    $connection->mapConditionOperator('=')->willReturn(['operator' => '=']);
    $connection->condition('AND')->willReturn(new Condition('AND'));
    $connection = $connection->reveal();

    $query_placeholder = $this->prophesize(PlaceholderInterface::class);

    $counter = 0;
    $query_placeholder->nextPlaceholder()->will(function D) use (&$counter) {
      return $counter++;
    });
    $query_placeholder->uniqueIdentifier()->willReturn(4);
    $query_placeholder = $query_placeholder->reveal();

    $condition = $connection->condition('AND');
    $condition->condition($field_name, 'value');
    $condition->compile($connection$query_placeholder);

    $this->assertEquals($expected$condition->__toString());
    $this->assertEquals([':db_condition_placeholder_0' => 'value']$condition->arguments());
  }
// Convert a single-valued array of values to the single-value case,     // and transform from IN() notation to = notation     if (is_array($info['value']) && count($info['value']) == 1) {
      $info['value'] = array_shift($info['value']);
    }
    if (is_array($info['value'])) {
      // We use an SA-CORE-2014-005 conformant placeholder for our array       // of values. Also, note that the 'IN' operator is implicit.       // @see https://www.drupal.org/node/2401615.       $operator = !empty($info['operator']) ? $info['operator'] : 'IN';
      $placeholder = ':views_join_condition_' . $select_query->nextPlaceholder() . '[]';
      $placeholder_sql = "( $placeholder )";
    }
    else {
      // With a single value, the '=' operator is implicit.       $operator = !empty($info['operator']) ? $info['operator'] : '=';
      $placeholder = $placeholder_sql = ':views_join_condition_' . $select_query->nextPlaceholder();
    }
    // Set 'field' as join table field if available or set 'left field' as     // join table field is not set.     if (isset($info['field'])) {
      $join_table_field = "$join_table$info[field]";
      
Home | Imprint | This part of the site doesn't use cookies.