add homeless to addresses

This commit is contained in:
2020-05-01 15:49:18 +02:00
parent 5f282ecedb
commit fd9511e745
10 changed files with 163 additions and 18 deletions

View File

@@ -2,6 +2,8 @@
namespace Chill\MainBundle\Entity;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Address
*/
@@ -35,6 +37,13 @@ class Address
*/
private $validFrom;
/**
* True if the address is a "no address", aka homeless person, ...
*
* @var bool
*/
private $isNoAddress = false;
public function __construct()
{
$this->validFrom = new \DateTime();
@@ -142,7 +151,80 @@ class Address
$this->validFrom = $validFrom;
return $this;
}
/**
* get "isNoAddress"
*
* Indicate true if the address is a fake address (homeless, ...)
*
* @return bool
*/
public function getIsNoAddress(): bool
{
return $this->isNoAddress;
}
public function isNoAddress(): bool
{
return $this->getIsNoAddress();
}
/**
* set Is No Address
*
* Indicate true if the address is a fake address (homeless, ...)
*
* @param bool $isNoAddress
* @return $this
*/
public function setIsNoAddress(bool $isNoAddress)
{
$this->isNoAddress = $isNoAddress;
return $this;
}
/**
* Validate the address.
*
* Check that:
*
* * if the address is not home address:
* * the postal code is present
* * the valid from is not null
* * the address street 1 is greater than 2
*
* @param ExecutionContextInterface $context
* @param array $payload
*/
public function validate(ExecutionContextInterface $context, $payload)
{
if (!$this->getValidFrom() instanceof \DateTime) {
$context
->buildViolation("address.date-should-be-set")
->atPath('validFrom')
->addViolation();
}
if ($this->isNoAddress()) {
return;
}
if (empty($this->getStreetAddress1())) {
$context
->buildViolation("address.street1-should-be-set")
->atPath('streetAddress1')
->addViolation();
}
if (!$this->getPostcode() instanceof PostalCode) {
$context
->buildViolation("address.postcode-should-be-set")
->atPath('postCode')
->addViolation();
}
}
public static function createFromAddress(Address $original) : Address
{
return (new Address())