fix bugs in accompanying periods

ref #11
This commit is contained in:
2016-05-17 10:02:45 +02:00
parent 8b98e8a4b6
commit ce7c149c35
12 changed files with 355 additions and 77 deletions

View File

@@ -186,11 +186,36 @@ class AccompanyingPeriod
return $this->closingMotive;
}
public function setClosingMotive(AccompanyingPeriod\ClosingMotive $closingMotive)
public function setClosingMotive(AccompanyingPeriod\ClosingMotive $closingMotive = null)
{
$this->closingMotive = $closingMotive;
return $this;
}
/**
* 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
*/
public function canBeReOpened()
{
if ($this->isOpen() === true) {
return false;
}
$periods = $this->getPerson()->getAccompanyingPeriodsOrdered();
return end($periods) === $this;
}
public function reOpen()
{
$this->setClosingDate(null);
$this->setClosingMotive(null);
}
/// VALIDATION function
public function isDateConsistent(ExecutionContextInterface $context) {

View File

@@ -95,6 +95,7 @@ class Person implements HasCenterInterface {
/**
* @var boolean
* @deprecated
*/
private $proxyAccompanyingPeriodOpenState = false; //TO-DELETE ?
@@ -168,11 +169,12 @@ class Person implements HasCenterInterface {
}
/**
* Return the opened accompanying period.
*
* @return null|AccompanyingPeriod
* @return AccompanyingPeriod
*/
public function getCurrentAccompanyingPeriod() {
if ($this->proxyAccompanyingPeriodOpenState === false) {
public function getOpenedAccompanyingPeriod() {
if ($this->isOpen() === false) {
return null;
}
@@ -183,6 +185,17 @@ class Person implements HasCenterInterface {
}
}
/**
* Returns the opened accompanying period.
*
* @return AccompanyingPeriod
* @deprecated since 1.1 use `getOpenedAccompanyingPeriod instead
*/
public function getCurrentAccompanyingPeriod()
{
return $this->getOpenedAccompanyingPeriod();
}
/**
*
* @return \Doctrine\Common\Collections\ArrayCollection
@@ -230,8 +243,20 @@ class Person implements HasCenterInterface {
return $periods;
}
public function isOpen() {
return $this->proxyAccompanyingPeriodOpenState;
/**
* check if the person is opened
*
* @return boolean
*/
public function isOpen()
{
foreach ($this->getAccompanyingPeriods() as $period) {
if ($period->isOpen()) {
return true;
}
}
return false;
}
/**