本文整理汇总了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);
}
}
示例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);
}