Fix mixed order of events with same time
This commit is contained in:
parent
027d94d41a
commit
6fdbe8923f
@ -1719,7 +1719,6 @@ function dol_color_minus($color, $minus, $minusunit = 16)
|
||||
return $newcolor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sort events by date
|
||||
*
|
||||
@ -1729,24 +1728,52 @@ function dol_color_minus($color, $minus, $minusunit = 16)
|
||||
*/
|
||||
function sort_events_by_date($a, $b)
|
||||
{
|
||||
if($a->datep != $b->datep)
|
||||
// datep => Event start time
|
||||
// datef => Event end time
|
||||
|
||||
// Events have different start time
|
||||
if ($a->datep !== $b->datep)
|
||||
{
|
||||
return $a->datep - $b->datep;
|
||||
}
|
||||
|
||||
// If both events have the same start time, longest first
|
||||
|
||||
if(! is_numeric($b->datef))
|
||||
// Events have same start time and no end time
|
||||
if ((! is_numeric($b->datef)) || (! is_numeric($a->datef)))
|
||||
{
|
||||
// when event B have no end timestamp, event B should sort be before event A (All day events on top)
|
||||
return 1;
|
||||
return sort_events_by_percentage($a, $b);
|
||||
}
|
||||
|
||||
if(! is_numeric($a->datef))
|
||||
// Events have the same start time and same end time
|
||||
if ($b->datef === $a->datef)
|
||||
{
|
||||
return sort_events_by_percentage($a, $b);
|
||||
}
|
||||
|
||||
// Events have the same start time, but have different end time -> longest event first
|
||||
return $b->datef - $a->datef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort events by percentage
|
||||
*
|
||||
* @param object $a Event A
|
||||
* @param object $b Event B
|
||||
* @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same percentage
|
||||
*/
|
||||
function sort_events_by_percentage($a, $b)
|
||||
{
|
||||
// Sort events with no percentage before each other
|
||||
// (usefull to sort holidays, sick days or similar on the top)
|
||||
|
||||
if ($a->percentage < 0)
|
||||
{
|
||||
// when event A have no end timestamp , event A should sort be before event B (All day events on top)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $b->datef - $a->datef;
|
||||
if ($b->percentage < 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $b->percentage - $a->percentage;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user