Order By [Function]: Updated to support natural sorting.
This commit is contained in:
parent
82f82bd87c
commit
0de8570dd3
|
|
@ -2003,13 +2003,17 @@ function number_pad($number,$n) {
|
||||||
|
|
||||||
//validate and format order by clause of select statement
|
//validate and format order by clause of select statement
|
||||||
if (!function_exists('order_by')) {
|
if (!function_exists('order_by')) {
|
||||||
function order_by($col, $dir, $col_default = '', $dir_default = 'asc') {
|
function order_by($col, $dir, $col_default = '', $dir_default = 'asc', $sort = '') {
|
||||||
$order_by = ' order by ';
|
$order_by = ' order by ';
|
||||||
$col = preg_replace('#[^a-zA-Z0-9-_.]#', '', $col ?? '');
|
$col = preg_replace('#[^a-zA-Z0-9-_.]#', '', $col ?? '');
|
||||||
if(!empty($dir))
|
$dir = !empty($dir) && strtolower($dir) == 'desc' ? 'desc' : 'asc';
|
||||||
$dir = strtolower($dir) == 'desc' ? 'desc' : 'asc';
|
|
||||||
if (!empty($col)) {
|
if (!empty($col)) {
|
||||||
return $order_by.$col.' '.$dir.' ';
|
if ($sort == 'natural') {
|
||||||
|
return $order_by.'natural_sort('.$col.') '.$dir.' ';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $order_by.$col.' '.$dir.' ';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!empty($col_default)) {
|
else if (!empty($col_default)) {
|
||||||
if (is_array($col_default) && @sizeof($col_default) != 0) {
|
if (is_array($col_default) && @sizeof($col_default) != 0) {
|
||||||
|
|
@ -2022,7 +2026,12 @@ function number_pad($number,$n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return $order_by.$col_default.' '.$dir_default.' ';
|
if ($sort == 'natural') {
|
||||||
|
return $order_by.'natural_sort('.$col_default.') '.$dir_default.' ';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $order_by.$col_default.' '.$dir_default.' ';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue