mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
rewrite methods for participation
This commit is contained in:
parent
8002725c87
commit
f3a8552829
@ -384,9 +384,9 @@ class AccompanyingPeriod
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Person
|
||||
* Open a new participation for a person
|
||||
*/
|
||||
public function addPerson(Person $person = null): AccompanyingPeriodParticipation
|
||||
public function createParticipationFor(Person $person): AccompanyingPeriodParticipation
|
||||
{
|
||||
$participation = new AccompanyingPeriodParticipation($this, $person);
|
||||
$this->participations[] = $participation;
|
||||
@ -394,10 +394,24 @@ class AccompanyingPeriod
|
||||
return $participation;
|
||||
}
|
||||
|
||||
public function addPerson(Person $person = null): self
|
||||
{
|
||||
if (NULL !== $person) {
|
||||
$this->createParticipationFor($person);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Person
|
||||
* Close a participation for a person
|
||||
*
|
||||
* Search for the person's participation and set the end date at
|
||||
* 'now'.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removePerson(Person $person): ?AccompanyingPeriodParticipation
|
||||
public function closeParticipationFor($person): ?AccompanyingPeriodParticipation
|
||||
{
|
||||
$participation = $this->getOpenParticipationContainsPerson($person);
|
||||
|
||||
@ -407,6 +421,17 @@ class AccompanyingPeriod
|
||||
|
||||
return $participation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove Person
|
||||
*/
|
||||
public function removePerson(Person $person): self
|
||||
{
|
||||
$this->closeParticipationFor($person);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function getClosingMotive(): ?ClosingMotive
|
||||
|
@ -23,6 +23,7 @@
|
||||
namespace Chill\PersonBundle\Tests\Entity;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
||||
@ -83,10 +84,11 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
||||
$person3 = new Person();
|
||||
$period = new AccompanyingPeriod(new \DateTime());
|
||||
|
||||
$period->addPerson($person);
|
||||
$period->addPerson($person2);
|
||||
$period->addPerson($person3);
|
||||
$participation0 = $period->createParticipationFor($person);
|
||||
$period->createParticipationFor($person2);
|
||||
$period->createParticipationFor($person3);
|
||||
|
||||
$this->assertNotNull($participation0);
|
||||
$this->assertEquals(3, $period->getParticipations()->count());
|
||||
$this->assertTrue($period->containsPerson($person));
|
||||
$this->assertFalse($period->containsPerson(new Person()));
|
||||
@ -95,13 +97,27 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
||||
$participations = $period->getParticipationsContainsPerson($person);
|
||||
$this->assertNotNull($participation);
|
||||
$this->assertSame($person, $participation->getPerson());
|
||||
$this->assertSame($participation, $participation0);
|
||||
$this->assertEquals(1, $participations->count());
|
||||
|
||||
$participationL = $period->removePerson($person);
|
||||
$participationL = $period->closeParticipationFor($person);
|
||||
$this->assertSame($participationL, $participation);
|
||||
$this->assertTrue($participation->getEndDate() instanceof \DateTimeInterface);
|
||||
|
||||
$participation = $period->getOpenParticipationContainsPerson($person);
|
||||
$this->assertNull($participation);
|
||||
|
||||
$person4 = new Person();
|
||||
$participations4 = $period->getParticipationsContainsPerson($person4);
|
||||
$this->assertEquals(0, $participations4->count());
|
||||
$participation4 = $period->getOpenParticipationContainsPerson($person4);
|
||||
$this->assertNull($participation4);
|
||||
|
||||
$period->addPerson($person4);
|
||||
$this->assertInstanceOf(AccompanyingPeriodParticipation::class, $period->getOpenParticipationContainsPerson($person4));
|
||||
$this->assertEquals(1, $period->getParticipationsContainsPerson($person4)->count());
|
||||
$period->removePerson($person4);
|
||||
$this->assertNull($period->getOpenParticipationContainsPerson($person4));
|
||||
$this->assertEquals(1, $period->getParticipationsContainsPerson($person4)->count());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user