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


PHP SQLSelect::getOrderBy方法代码示例

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


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

示例1: ensureSelectContainsOrderbyColumns

 /**
  * Ensure that if a query has an order by clause, those columns are present in the select.
  *
  * @param SQLSelect $query
  * @return null
  */
 protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = array())
 {
     $tableClasses = ClassInfo::dataClassesFor($this->dataClass);
     $baseClass = array_shift($tableClasses);
     if ($orderby = $query->getOrderBy()) {
         $newOrderby = array();
         foreach ($orderby as $k => $dir) {
             $newOrderby[$k] = $dir;
             // don't touch functions in the ORDER BY or public function calls
             // selected as fields
             if (strpos($k, '(') !== false) {
                 continue;
             }
             $col = str_replace('"', '', trim($k));
             $parts = explode('.', $col);
             // Pull through SortColumn references from the originalSelect variables
             if (preg_match('/_SortColumn/', $col)) {
                 if (isset($originalSelect[$col])) {
                     $query->selectField($originalSelect[$col], $col);
                 }
                 continue;
             }
             if (count($parts) == 1) {
                 if (DataObject::has_own_table_database_field($baseClass, $parts[0])) {
                     $qualCol = "\"{$baseClass}\".\"{$parts[0]}\"";
                 } else {
                     $qualCol = "\"{$parts['0']}\"";
                 }
                 // remove original sort
                 unset($newOrderby[$k]);
                 // add new columns sort
                 $newOrderby[$qualCol] = $dir;
                 // To-do: Remove this if block once SQLSelect::$select has been refactored to store getSelect()
                 // format internally; then this check can be part of selectField()
                 $selects = $query->getSelect();
                 if (!isset($selects[$col]) && !in_array($qualCol, $selects)) {
                     $query->selectField($qualCol);
                 }
             } else {
                 $qualCol = '"' . implode('"."', $parts) . '"';
                 // To-do: Remove this if block once SQLSelect::$select has been refactored to store getSelect()
                 // format internally; then this check can be part of selectField()
                 if (!in_array($qualCol, $query->getSelect())) {
                     $query->selectField($qualCol);
                 }
             }
         }
         $query->setOrderBy($newOrderby);
     }
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:56,代码来源:DataQuery.php

示例2: buildOrderByFragment

 /**
  * Returns the ORDER BY clauses ready for inserting into a query.
  *
  * @param SQLSelect $query The expression object to build from
  * @param array $parameters Out parameter for the resulting query parameters
  * @return string Completed order by part of statement
  */
 public function buildOrderByFragment(SQLSelect $query, array &$parameters)
 {
     $orderBy = $query->getOrderBy();
     if (empty($orderBy)) {
         return '';
     }
     // Build orders, each with direction considered
     $statements = array();
     foreach ($orderBy as $clause => $dir) {
         $statements[] = trim("{$clause} {$dir}");
     }
     $nl = $this->getSeparator();
     return "{$nl}ORDER BY " . implode(', ', $statements);
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:21,代码来源:DBQueryBuilder.php


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