improve histories order since User entity

This commit is contained in:
2023-10-04 12:47:23 +02:00
parent c526973475
commit 0b6b25fd95
3 changed files with 45 additions and 11 deletions

View File

@@ -283,6 +283,22 @@ class User implements UserInterface, \Stringable
return $this->scopeHistories;
}
/**
* @return ArrayCollection|UserScopeHistory[]
*/
public function getMainScopeHistoriesOrdered(): ArrayCollection
{
$scopeHistories = $this->getMainScopeHistories();
$sortedScopeHistories = $scopeHistories->toArray();
usort($sortedScopeHistories, function ($a, $b) {
return $a->getStartDate() < $b->getStartDate() ? 1 : -1;
});
return new ArrayCollection($sortedScopeHistories);
}
/**
* @return string
*/
@@ -321,6 +337,22 @@ class User implements UserInterface, \Stringable
return $this->jobHistories;
}
/**
* @return ArrayCollection|UserJobHistory[]
*/
public function getUserJobHistoriesOrdered(): ArrayCollection
{
$jobHistories = $this->getUserJobHistories();
$sortedJobHistories = $jobHistories->toArray();
usort($sortedJobHistories, function ($a, $b) {
return $a->getStartDate() < $b->getStartDate() ? 1 : -1;
});
return new ArrayCollection($sortedJobHistories);
}
/**
* @return string
*/