mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
make new relation many-to-many between Person and AccompagnyingPeriod
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* Copyright (C) 2014-2021, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
namespace Chill\PersonBundle\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
@@ -65,14 +67,13 @@ class AccompanyingPeriod
|
||||
private $remark = '';
|
||||
|
||||
/**
|
||||
* @var Person
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\ManyToOne(
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Chill\PersonBundle\Entity\Person",
|
||||
* inversedBy="accompanyingPeriods",
|
||||
* cascade={"refresh"})
|
||||
* mappedBy="accompanyingPeriods")
|
||||
*/
|
||||
private $person;
|
||||
private $persons;
|
||||
|
||||
/**
|
||||
* @var AccompanyingPeriod\ClosingMotive
|
||||
@@ -101,12 +102,13 @@ class AccompanyingPeriod
|
||||
*/
|
||||
public function __construct(\DateTime $dateOpening) {
|
||||
$this->setOpeningDate($dateOpening);
|
||||
$this->persons = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
@@ -129,7 +131,7 @@ class AccompanyingPeriod
|
||||
/**
|
||||
* Get openingDate
|
||||
*
|
||||
* @return \DateTime
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getOpeningDate()
|
||||
{
|
||||
@@ -138,12 +140,12 @@ class AccompanyingPeriod
|
||||
|
||||
/**
|
||||
* Set closingDate
|
||||
*
|
||||
*
|
||||
* For closing a Person file, you should use Person::setClosed instead.
|
||||
*
|
||||
* @param \DateTime $dateClosing
|
||||
* @return AccompanyingPeriod
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function setClosingDate($closingDate)
|
||||
{
|
||||
@@ -155,7 +157,7 @@ class AccompanyingPeriod
|
||||
/**
|
||||
* Get closingDate
|
||||
*
|
||||
* @return \DateTime
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getClosingDate()
|
||||
{
|
||||
@@ -165,7 +167,7 @@ class AccompanyingPeriod
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isOpen(): bool
|
||||
public function isOpen(): bool
|
||||
{
|
||||
if ($this->getOpeningDate() > new \DateTime('now')) {
|
||||
return false;
|
||||
@@ -198,7 +200,7 @@ class AccompanyingPeriod
|
||||
/**
|
||||
* Get remark
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getRemark()
|
||||
{
|
||||
@@ -206,29 +208,53 @@ class AccompanyingPeriod
|
||||
}
|
||||
|
||||
/**
|
||||
* Set person.
|
||||
* Set persons
|
||||
*/
|
||||
public function setPersons($persons) : AccompanyingPeriod
|
||||
{
|
||||
$this->persons = $persons;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Persons
|
||||
*/
|
||||
public function getPersons() : Collection
|
||||
{
|
||||
return $this->persons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if a given Person is associated
|
||||
*/
|
||||
public function containsPerson(Person $person) : bool
|
||||
{
|
||||
foreach ($this->persons as $p) {
|
||||
if ($p === $person) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add person.
|
||||
*
|
||||
* For consistency, you should use Person::addAccompanyingPeriod instead.
|
||||
*
|
||||
* @param Person $person
|
||||
* @return AccompanyingPeriod
|
||||
* @see Person::addAccompanyingPeriod
|
||||
*/
|
||||
public function setPerson(Person $person = null)
|
||||
public function addPerson(Person $person = null) : AccompanyingPeriod
|
||||
{
|
||||
$this->person = $person;
|
||||
$this->persons[] = $person;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get person
|
||||
*
|
||||
* @return Person
|
||||
* Remove person.
|
||||
*/
|
||||
public function getPerson()
|
||||
public function removePerson(Person $person) : void
|
||||
{
|
||||
return $this->person;
|
||||
$this->persons->removeElement($person);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,21 +277,24 @@ class AccompanyingPeriod
|
||||
|
||||
/**
|
||||
* If the period can be reopened.
|
||||
*
|
||||
* This function test if the period is closed and if the period is the last
|
||||
* for the associated person
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* This function test if the period is closed and if the period is the last
|
||||
* for the given person
|
||||
*/
|
||||
public function canBeReOpened()
|
||||
public function canBeReOpened(Person $person) : bool
|
||||
{
|
||||
if ($this->isOpen() === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$periods = $this->getPerson()->getAccompanyingPeriodsOrdered();
|
||||
dump('parcours fermé: '. $this->getId());
|
||||
|
||||
return end($periods) === $this;
|
||||
foreach ($this->getPersons() as $p) {
|
||||
if ($p === $person) {
|
||||
$periods = $p->getAccompanyingPeriodsOrdered();
|
||||
return end($periods) === $this; // retourne TRUE si cette période est la dernière
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,7 +323,7 @@ class AccompanyingPeriod
|
||||
|
||||
/**
|
||||
* Returns true if the closing date is after the opening date.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isClosingAfterOpening()
|
||||
|
Reference in New Issue
Block a user