mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Documentation, format class, no modification. (#7629)
This commit is contained in:
@@ -6,23 +6,42 @@ class array_order {
|
||||
var $backwards = false;
|
||||
var $numeric = false;
|
||||
|
||||
/**
|
||||
* Sorts the provided array based on the specified fields.
|
||||
*
|
||||
* If no fields are provided, sorts in default order. If numeric sorting is enabled,
|
||||
* uses the numericCompare method for comparison; otherwise, uses the stringCompare method.
|
||||
*
|
||||
* @param array $array The array to be sorted
|
||||
*
|
||||
* @return array The sorted array
|
||||
*/
|
||||
function sort() {
|
||||
$args = func_get_args();
|
||||
$array = $args[0];
|
||||
if (!$array) return array();
|
||||
if (!$array) return [];
|
||||
$this->sort_fields = array_slice($args, 1);
|
||||
if (!$this->sort_fields) return $array();
|
||||
|
||||
if ($this->numeric) {
|
||||
usort($array, array($this, 'numericCompare'));
|
||||
usort($array, [$this, 'numericCompare']);
|
||||
} else {
|
||||
usort($array, array($this, 'stringCompare'));
|
||||
usort($array, [$this, 'stringCompare']);
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two values based on a specified set of sort fields.
|
||||
*
|
||||
* @param array $a The first value to compare.
|
||||
* @param array $b The second value to compare.
|
||||
*
|
||||
* @return int A negative integer if the first value is less than the second, a positive integer if the first value
|
||||
* is greater than the second, and zero if they are equal.
|
||||
*/
|
||||
function numericCompare($a, $b) {
|
||||
foreach($this->sort_fields as $sort_field) {
|
||||
foreach ($this->sort_fields as $sort_field) {
|
||||
if ($a[$sort_field] == $b[$sort_field]) {
|
||||
continue;
|
||||
}
|
||||
@@ -31,8 +50,17 @@ class array_order {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two strings according to the specified sort fields.
|
||||
*
|
||||
* @param string $a The first string to compare.
|
||||
* @param string $b The second string to compare.
|
||||
*
|
||||
* @return int A negative integer if $a is less than $b, a positive integer if $a is greater than $b,
|
||||
* and 0 if the strings are equal according to the specified sort fields.
|
||||
*/
|
||||
function stringCompare($a, $b) {
|
||||
foreach($this->sort_fields as $sort_field) {
|
||||
foreach ($this->sort_fields as $sort_field) {
|
||||
$cmp_result = strcasecmp($a[$sort_field], $b[$sort_field]);
|
||||
if ($cmp_result == 0) continue;
|
||||
return ($this->backwards ? -$cmp_result : $cmp_result);
|
||||
@@ -40,7 +68,6 @@ class array_order {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//$order = new array_order();
|
||||
//$registrations = $order->sort($registrations, 'domain', 'user');
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user