当前位置: 首页>>代码示例>>PHP>>正文


PHP SelectInterface::addExpression方法代码示例

本文整理汇总了PHP中Drupal\Core\Database\Query\SelectInterface::addExpression方法的典型用法代码示例。如果您正苦于以下问题:PHP SelectInterface::addExpression方法的具体用法?PHP SelectInterface::addExpression怎么用?PHP SelectInterface::addExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Database\Query\SelectInterface的用法示例。


在下文中一共展示了SelectInterface::addExpression方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addSort

 /**
  * Adds the sort to the build query.
  *
  * @return \Drupal\Core\Entity\Query\Sql\Query
  *   Returns the called object.
  */
 protected function addSort()
 {
     if ($this->count) {
         $this->sort = array();
     }
     // Gather the SQL field aliases first to make sure every field table
     // necessary is added. This might change whether the query is simple or
     // not. See below for more on simple queries.
     $sort = array();
     if ($this->sort) {
         foreach ($this->sort as $key => $data) {
             $sort[$key] = $this->getSqlField($data['field'], $data['langcode']);
         }
     }
     $simple_query = $this->isSimpleQuery();
     // If the query is set up for paging either via pager or by range or a
     // count is requested, then the correct amount of rows returned is
     // important. If the entity has a data table or multiple value fields are
     // involved then each revision might appear in several rows and this needs
     // a significantly more complex query.
     if (!$simple_query) {
         // First, GROUP BY revision id (if it has been added) and entity id.
         // Now each group contains a single revision of an entity.
         foreach ($this->sqlFields as $field) {
             $group_by = "{$field['0']}.{$field['1']}";
             $this->sqlGroupBy[$group_by] = $group_by;
         }
     }
     // Now we know whether this is a simple query or not, actually do the
     // sorting.
     foreach ($sort as $key => $sql_alias) {
         $direction = $this->sort[$key]['direction'];
         if ($simple_query || isset($this->sqlGroupBy[$sql_alias])) {
             // Simple queries, and the grouped columns of complicated queries
             // can be ordered normally, without the aggregation function.
             $this->sqlQuery->orderBy($sql_alias, $direction);
             if (!isset($this->sqlFields[$sql_alias])) {
                 $this->sqlFields[$sql_alias] = explode('.', $sql_alias);
             }
         } else {
             // Order based on the smallest element of each group if the
             // direction is ascending, or on the largest element of each group
             // if the direction is descending.
             $function = $direction == 'ASC' ? 'min' : 'max';
             $expression = "{$function}({$sql_alias})";
             $expression_alias = $this->sqlQuery->addExpression($expression);
             $this->sqlQuery->orderBy($expression_alias, $direction);
         }
     }
     return $this;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:57,代码来源:Query.php

示例2: compileFields

  /**
   * Adds fields to the query.
   *
   * @param \Drupal\Core\Database\Query\SelectInterface $query
   *   The drupal query object.
   */
  protected function compileFields($query) {
    foreach ($this->fields as $field) {
      $string = '';
      if (!empty($field['table'])) {
        $string .= $field['table'] . '.';
      }
      $string .= $field['field'];
      $fieldname = (!empty($field['alias']) ? $field['alias'] : $string);

      if (!empty($field['count'])) {
        // Retained for compatibility.
        $field['function'] = 'count';
      }

      if (!empty($field['function'])) {
        $info = $this->getAggregationInfo();
        if (!empty($info[$field['function']]['method']) && is_callable(array($this, $info[$field['function']]['method']))) {
          $string = $this::{$info[$field['function']]['method']}($field['function'], $string);
          $placeholders = !empty($field['placeholders']) ? $field['placeholders'] : array();
          $query->addExpression($string, $fieldname, $placeholders);
        }

        $this->hasAggregate = TRUE;
      }
      // This is a formula, using no tables.
      elseif (empty($field['table'])) {
        $placeholders = !empty($field['placeholders']) ? $field['placeholders'] : array();
        $query->addExpression($string, $fieldname, $placeholders);
      }
      elseif ($this->distinct && !in_array($fieldname, $this->groupby)) {
        $query->addField(!empty($field['table']) ? $field['table'] : $this->view->storage->get('base_table'), $field['field'], $fieldname);
      }
      elseif (empty($field['aggregate'])) {
        $query->addField(!empty($field['table']) ? $field['table'] : $this->view->storage->get('base_table'), $field['field'], $fieldname);
      }

      if ($this->getCountOptimized) {
        // We only want the first field in this case.
        break;
      }
    }
  }
开发者ID:jthoresen,项目名称:PladsenDrupal,代码行数:48,代码来源:Sql.php

示例3: addExpression

 public function addExpression($expression, $alias = NULL, $arguments = array())
 {
     return $this->query->addExpression($expression, $alias, $arguments);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:4,代码来源:SelectExtender.php


注:本文中的Drupal\Core\Database\Query\SelectInterface::addExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。