2
0
forked from Wavyzz/dolibarr

NEW dol_sort_array can be used with 2 sorting criteria.

This commit is contained in:
ldestailleur
2025-09-15 19:28:38 +02:00
parent 761804ce55
commit e8d2095816
13 changed files with 30 additions and 18 deletions

View File

@@ -50,7 +50,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
// Load translation files required by the page
$langs->load("assets");
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force Asset[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Asset[] $linkedObjectBlock */

View File

@@ -45,7 +45,7 @@ $langs->load("bom");
'@phan-var-force BOM[] $linkedObjectBlock'; // Type before use
/** @var BOM[] $linkedObjectBlock */
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force BOM[] $linkedObjectBlock'; // Type after dol_sort_array which looses typing
/** @var BOM[] $linkedObjectBlock */

View File

@@ -47,7 +47,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
// Load translation files required by the page
$langs->load("propal");
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force Propal[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Propal[] $linkedObjectBlock */

View File

@@ -42,7 +42,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
// Load translation files required by the page
$langs->load("orders");
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force Commande[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Commande[] $linkedObjectBlock */

View File

@@ -39,7 +39,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
$langs->load("bills");
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force Facture[] $linkedObjectBlock';
/** @var Facture[] $linkedObjectBlock */

View File

@@ -11317,7 +11317,7 @@ function dol_htmloutput_errors($mesgstring = '', $mesgarray = array(), $keepembe
* @param array<string|int,mixed> $array Array to sort (array of array('key1'=>val1,'key2'=>val2,'key3'...) or array of objects)
* @phpstan-param T $array
* @phan-param T $array
* @param string $index Key in array to use for sorting criteria
* @param string $index Key in array to use for sorting criteria. We can have several keys separated by a comma but we can have only 1 sorting order.
* @param string $order Sort order ('asc' or 'desc')
* @param int<-1,1> $natsort If values are strings (I said value not type): 0=Use alphabetical order, 1=use "natural" sort (natsort), -1=Force alpha order
* If values are numeric (I said value not type): 0=Use numeric order (even if type is string) so use a "natural" sort, 1=use "natural" sort too (same than 0), -1=Force alphabetical order
@@ -11336,19 +11336,31 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen
if (is_array($array)) {
$sizearray = count($array);
if ($sizearray > 0) {
// Build a temp array with sorting key as value
$temp = array();
foreach (array_keys($array) as $key) {
$tmpmultikey = explode(',', $index);
$newindex = $tmpmultikey[0];
if (is_object($array[$key])) {
$temp[$key] = empty($array[$key]->$index) ? 0 : $array[$key]->$index;
$temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
// Add other keys
if (!empty($tmpmultikey[1])) {
$newindex = $tmpmultikey[1];
$temp[$key] .= '__'.(empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
}
} else {
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable,PhanTypeArraySuspicious,PhanTypeMismatchDimFetch
$temp[$key] = empty($array[$key][$index]) ? 0 : $array[$key][$index];
$temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
// Add other keys
if (!empty($tmpmultikey[1])) {
$newindex = $tmpmultikey[1];
$temp[$key] .= '__'.(empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
}
}
if ($natsort == -1) {
$temp[$key] = '___' . $temp[$key]; // We add a string at begin of value to force an alpha order when using asort.
$temp[$key] = '___'.$temp[$key]; // We add a string at begin of value to force an alpha order when using asort.
}
}
if (empty($natsort) || $natsort == -1) {
if ($order == 'asc') {
asort($temp);

View File

@@ -42,7 +42,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
// Load translation files required by the page
$langs->load('sendings');
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force CommonObject[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Delivery[] $linkedObjectBlock */

View File

@@ -41,7 +41,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
$langs->load("interventions");
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force Fichinter[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Fichinter[] $linkedObjectBlock */

View File

@@ -97,7 +97,7 @@ if ($object->element == 'mo') {
}
}
} else {
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force array<CommonObject> $linkedObjectBlock';
$total = 0;
$ilink = 0;

View File

@@ -47,7 +47,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
// Load translation files required by the page
$langs->load("tasks");
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force CommonObject[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Task[] $linkedObjectBlock */

View File

@@ -47,7 +47,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
// Load translation files required by the page
$langs->load("receptions");
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1);
'@phan-var-force Reception[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Reception[] $linkedObjectBlock */

View File

@@ -39,8 +39,8 @@ if (!defined('ISLOADEDBYSTEELSHEET')) {
width: 100%;
box-shadow: 1px 1px 20px rgba(192, 192, 192, 0.2);
border-radius: 2px;
/* border: 1px solid #e9e9e9; */
border: 1px solid var(--colorbacktitle1);
border: 1px solid #e9e9e9;
/* border: 1px solid var(--colorbacktitle1); */
margin-bottom: 15px;
}
.info-box.info-box-sm {

View File

@@ -42,7 +42,7 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
// Load translation files required by the page
$langs->load('ticket');
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'datec', 'desc', 0, 0, 1);
$linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'datec,ref', 'desc', 0, 0, 1);
'@phan-var-force Ticket[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array)
/** @var Ticket[] $linkedObjectBlock */