mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into features/create-social-action
This commit is contained in:
@@ -30,7 +30,7 @@ class Household
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue
|
||||
* @ORM\Column(type="integer")
|
||||
* @Serializer\Groups({"write"})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
@@ -196,6 +196,11 @@ class Household
|
||||
}
|
||||
|
||||
public function getCurrentMembers(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getMembers()->matching($this->buildCriteriaCurrentMembers($now));
|
||||
}
|
||||
|
||||
private function buildCriteriaCurrentMembers(?\DateTimeImmutable $now = null): Criteria
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
@@ -211,7 +216,53 @@ class Household
|
||||
$expr->gte('endDate', $date)
|
||||
));
|
||||
|
||||
return $this->getMembers()->matching($criteria);
|
||||
return $criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HouseholdMember[]
|
||||
*/
|
||||
public function getCurrentMembersOrdered(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
$members = $this->getCurrentMembers($now);
|
||||
|
||||
$members->getIterator()
|
||||
->uasort(
|
||||
function (HouseholdMember $a, HouseholdMember $b) {
|
||||
if ($a->getPosition()->getOrdering() < $b->getPosition()->getOrdering()) {
|
||||
return -1;
|
||||
}
|
||||
if ($a->getPosition()->getOrdering() > $b->getPosition()->getOrdering()) {
|
||||
return 1;
|
||||
}
|
||||
if ($a->isHolder() && !$b->isHolder()) {
|
||||
return 1;
|
||||
}
|
||||
if (!$a->isHolder() && $b->isHolder()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
return $members;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current members ids
|
||||
*
|
||||
* Used in serialization
|
||||
*
|
||||
* @Serializer\Groups({"read"})
|
||||
* @Serializer\SerializedName("current_members_id")
|
||||
*
|
||||
*/
|
||||
public function getCurrentMembersIds(?\DateTimeImmutable $now = null): Collection
|
||||
{
|
||||
return $this->getCurrentMembers($now)->map(
|
||||
fn (HouseholdMember $m) => $m->getId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1264,15 +1264,24 @@ class Person implements HasCenterInterface
|
||||
}
|
||||
|
||||
public function getCurrentHousehold(?\DateTimeImmutable $at = null): ?Household
|
||||
{
|
||||
$participation = $this->getCurrentHouseholdParticipationShareHousehold($at);
|
||||
|
||||
return $participation instanceof HouseholdMember ?
|
||||
$participation->getHousehold()
|
||||
: null;
|
||||
}
|
||||
|
||||
public function getCurrentHouseholdParticipationShareHousehold(?\DateTimeImmutable $at = null): ?HouseholdMember
|
||||
{
|
||||
$criteria = new Criteria();
|
||||
$expr = Criteria::expr();
|
||||
$date = NULL === $at ? new \DateTimeImmutable('now') : $at;
|
||||
$date = NULL === $at ? new \DateTimeImmutable('today') : $at;
|
||||
$datef = $date->format('Y-m-d');
|
||||
|
||||
if (
|
||||
NULL !== ($this->currentHouseholdAt[$datef] ?? NULL)) {
|
||||
return $this->currentHouseholdAt[$datef];
|
||||
NULL !== ($this->currentHouseholdParticipationAt[$datef] ?? NULL)) {
|
||||
return $this->currentHouseholdParticipationAt[$datef];
|
||||
}
|
||||
|
||||
$criteria
|
||||
@@ -1281,7 +1290,7 @@ class Person implements HasCenterInterface
|
||||
$expr->lte('startDate', $date),
|
||||
$expr->orX(
|
||||
$expr->isNull('endDate'),
|
||||
$expr->gte('endDate', $date)
|
||||
$expr->gt('endDate', $date)
|
||||
),
|
||||
$expr->eq('shareHousehold', true)
|
||||
)
|
||||
@@ -1292,8 +1301,7 @@ class Person implements HasCenterInterface
|
||||
;
|
||||
|
||||
return $participations->count() > 0 ?
|
||||
$this->currentHouseholdAt[$datef] = $participations->first()
|
||||
->getHousehold()
|
||||
$this->currentHouseholdParticipationAt[$datef] = $participations->first()
|
||||
: null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user