mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
Adding validation on address validFrom date (unique by person)
This commit is contained in:
@@ -669,6 +669,44 @@ class Person implements HasCenterInterface {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the person has two addresses with the
|
||||
* same validFrom date (in format 'Y-m-d')
|
||||
*/
|
||||
public function hasTwoAdressWithSameValidFromDate()
|
||||
{
|
||||
$validYMDDates = array();
|
||||
|
||||
foreach ($this->addresses as $ad) {
|
||||
$validDate = $ad->getValidFrom()->format('Y-m-d');
|
||||
|
||||
if (in_array($validDate, $validYMDDates)) {
|
||||
return true;
|
||||
}
|
||||
$validYMDDates[] = $validDate;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation callback that checks if the addresses are valid (do not have
|
||||
* two addresses with the same validFrom date)
|
||||
*
|
||||
* This method add violation errors.
|
||||
*/
|
||||
public function isAddressesValid(ExecutionContextInterface $context)
|
||||
{
|
||||
if ($this->hasTwoAdressWithSameValidFromDate()) {
|
||||
$context->addViolationAt(
|
||||
'addresses',
|
||||
'Two addresses has the same validFrom date',
|
||||
array()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ERROR_PERIODS_ARE_COLLAPSING = 1; // when two different periods
|
||||
// have days in commun
|
||||
const ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD = 2; // where there exist
|
||||
@@ -713,4 +751,4 @@ class Person implements HasCenterInterface {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user