mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Fixed: filter social action to keep only currently activated
This commit is contained in:
@@ -15,6 +15,7 @@ use DateInterval;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ReadableCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
|
||||
@@ -295,6 +296,19 @@ class SocialAction
|
||||
return 0 < $this->getChildren()->count();
|
||||
}
|
||||
|
||||
public function isDesactivated(\DateTime $atDate): bool
|
||||
{
|
||||
if (null !== $this->desactivationDate && $this->desactivationDate < $atDate) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasParent()) {
|
||||
return $this->parent->isDesactivated($atDate);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasParent(): bool
|
||||
{
|
||||
return $this->getParent() instanceof self;
|
||||
@@ -401,4 +415,14 @@ class SocialAction
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function filterRemoveDeactivatedActions(ReadableCollection|array $actions, \DateTime $comparisonDate): ReadableCollection|array
|
||||
{
|
||||
$filterFn = fn (SocialAction $socialAction) => !$socialAction->isDesactivated($comparisonDate);
|
||||
|
||||
return match ($actions instanceof ReadableCollection) {
|
||||
true => $actions->filter($filterFn),
|
||||
false => array_filter($actions, $filterFn)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user