mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
fix social action consistency
This commit is contained in:
@@ -230,45 +230,39 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
|
||||
|
||||
public function addSocialAction(SocialAction $socialAction): self
|
||||
{
|
||||
$descendants = $socialAction->getDescendantsWithThis();
|
||||
$parent = $socialAction->getParent();
|
||||
|
||||
$parentKey = array_search($parent, $this->socialActions->toArray());
|
||||
|
||||
if (false !== $parentKey) {
|
||||
$this->socialActions[$parentKey] = $socialAction;
|
||||
// return $this;
|
||||
if (!$this->socialActions->contains($socialAction)) {
|
||||
$this->socialActions[] = $socialAction;
|
||||
$this->ensureSocialActionConsistency();
|
||||
}
|
||||
|
||||
if (count($descendants) > 0) {
|
||||
foreach ($descendants as $d) {
|
||||
$inCollection = $this->socialActions->contains($d);
|
||||
if ($inCollection) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->socialActions[] = $socialAction;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function ensureSocialActionConsistency(): void
|
||||
{
|
||||
$ancestors = SocialAction::findAncestorSocialActions($this->getSocialActions());
|
||||
|
||||
foreach ($ancestors as $ancestor) {
|
||||
$this->removeSocialAction($ancestor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a social issue
|
||||
*
|
||||
* Note: the social issue consistency (the fact that only yougest social issues
|
||||
* are kept) is processed by an entity listener:
|
||||
* @see{\Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodSocialIssueConsistencyEntityListener}
|
||||
*
|
||||
* @param SocialIssue $socialIssue
|
||||
* @return $this
|
||||
*/
|
||||
public function addSocialIssue(SocialIssue $socialIssue): self
|
||||
{
|
||||
$descendants = $socialIssue->getDescendantsWithThis();
|
||||
|
||||
if (count($descendants) > 0) {
|
||||
foreach ($descendants as $d) {
|
||||
$inCollection = $this->socialIssues->contains($d);
|
||||
if ($inCollection) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
if (!$this->socialIssues->contains($socialIssue)) {
|
||||
$this->socialIssues[] = $socialIssue;
|
||||
}
|
||||
|
||||
$this->socialIssues[] = $socialIssue;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user