mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add homeless to addresses
This commit is contained in:
parent
5f282ecedb
commit
fd9511e745
@ -125,3 +125,9 @@ Version 1.5.18
|
||||
|
||||
- [webpack] add namespace for import sass ;
|
||||
- [activity] move activity.scss to own bundle ;
|
||||
|
||||
Master branch
|
||||
=============
|
||||
|
||||
- [address] add a "homeless" characteristic to addresses ;
|
||||
|
||||
|
@ -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())
|
||||
|
@ -60,6 +60,9 @@ class AddressDataMapper implements DataMapperInterface
|
||||
case 'validFrom':
|
||||
$form->setData($address->getValidFrom());
|
||||
break;
|
||||
case 'isNoAddress':
|
||||
$form->setData($address->isNoAddress());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -77,18 +80,25 @@ class AddressDataMapper implements DataMapperInterface
|
||||
$address = new Address();
|
||||
}
|
||||
|
||||
$isNoAddress = false;
|
||||
foreach ($forms as $key => $form) {
|
||||
if ($key === 'isNoAddress') {
|
||||
$isNoAddress = $form->get('isNoAddress')->getData();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($forms as $key => $form) {
|
||||
/** @var FormInterface $form */
|
||||
switch($key) {
|
||||
case 'postCode':
|
||||
if (!$form->getData() instanceof PostalCode) {
|
||||
if (!$form->getData() instanceof PostalCode && !$isNoAddress) {
|
||||
$address = null;
|
||||
return;
|
||||
}
|
||||
$address->setPostcode($form->getData());
|
||||
break;
|
||||
case 'streetAddress1':
|
||||
if (empty($form->getData())) {
|
||||
if (empty($form->getData()) && !$isNoAddress) {
|
||||
$address = null;
|
||||
return;
|
||||
}
|
||||
@ -100,6 +110,9 @@ class AddressDataMapper implements DataMapperInterface
|
||||
case 'validFrom':
|
||||
$address->setValidFrom($form->getData());
|
||||
break;
|
||||
case 'isNoAddress':
|
||||
$address->setIsNoAddress($form->getData());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Form\Type\PostalCodeType;
|
||||
use Chill\MainBundle\Form\DataMapper\AddressDataMapper;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
|
||||
/**
|
||||
* A type to create/update Address entity
|
||||
@ -45,7 +46,7 @@ class AddressType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('streetAddress1', TextType::class, array(
|
||||
'required' => true
|
||||
'required' => !$options['has_no_address'] // true if has no address is false
|
||||
))
|
||||
->add('streetAddress2', TextType::class, array(
|
||||
'required' => false
|
||||
@ -53,7 +54,7 @@ class AddressType extends AbstractType
|
||||
->add('postCode', PostalCodeType::class, array(
|
||||
'label' => 'Postal code',
|
||||
'placeholder' => 'Choose a postal code',
|
||||
'required' => true
|
||||
'required' => !$options['has_no_address'] // true if has no address is false
|
||||
))
|
||||
;
|
||||
|
||||
@ -67,7 +68,19 @@ class AddressType extends AbstractType
|
||||
);
|
||||
}
|
||||
|
||||
if ($options['null_if_emtpy'] === TRUE) {
|
||||
if ($options['has_no_address']) {
|
||||
$builder
|
||||
->add('isNoAddress', ChoiceType::class, [
|
||||
'required' => true,
|
||||
'choices' => [
|
||||
'address.consider homeless' => true,
|
||||
'address.real address' => false
|
||||
],
|
||||
'label' => 'address.address_homeless'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($options['null_if_empty'] === TRUE) {
|
||||
$builder->setDataMapper(new AddressDataMapper());
|
||||
}
|
||||
}
|
||||
@ -79,6 +92,9 @@ class AddressType extends AbstractType
|
||||
->setDefined('has_valid_from')
|
||||
->setAllowedTypes('has_valid_from', 'bool')
|
||||
->setDefault('has_valid_from', true)
|
||||
->setDefined('has_no_address')
|
||||
->setDefault('has_no_address', false)
|
||||
->setAllowedTypes('has_no_address', 'bool')
|
||||
->setDefined('null_if_empty')
|
||||
->setDefault('null_if_empty', false)
|
||||
->setAllowedTypes('null_if_empty', 'bool')
|
||||
|
@ -16,6 +16,9 @@ Chill\MainBundle\Entity\Address:
|
||||
length: 255
|
||||
validFrom:
|
||||
type: date
|
||||
isNoAddress:
|
||||
type: boolean
|
||||
default: false
|
||||
manyToOne:
|
||||
postcode:
|
||||
targetEntity: Chill\MainBundle\Entity\PostalCode
|
||||
|
@ -36,18 +36,8 @@ Chill\MainBundle\Entity\Center:
|
||||
min: 2
|
||||
|
||||
Chill\MainBundle\Entity\Address:
|
||||
properties:
|
||||
streetAddress1:
|
||||
- Length:
|
||||
min: 2
|
||||
max: 250
|
||||
- NotNull: ~
|
||||
- NotBlank: ~
|
||||
postcode:
|
||||
- NotNull: ~
|
||||
validFrom:
|
||||
- NotNull: ~
|
||||
- Date: ~
|
||||
constraints:
|
||||
- Callback: validate
|
||||
|
||||
Chill\MainBundle\Entity\PostalCode:
|
||||
properties:
|
||||
|
22
Resources/migrations/Version20200422122715.php
Normal file
22
Resources/migrations/Version20200422122715.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Add a field "isNoAddress" on addresses
|
||||
*/
|
||||
final class Version20200422122715 extends AbstractMigration
|
||||
{
|
||||
public function up(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD isNoAddress BOOLEAN NOT NULL DEFAULT FALSE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema) : void
|
||||
{
|
||||
$this->addSql('ALTER TABLE chill_main_address DROP isNoAddress');
|
||||
}
|
||||
}
|
@ -59,6 +59,10 @@ Street address2: Adresse ligne 2
|
||||
Postal code: Code postal
|
||||
Valid from: Valide à partir du
|
||||
Choose a postal code: Choisir un code postal
|
||||
address:
|
||||
address_homeless: L'adresse est-elle celle d'un domicile fixe ?
|
||||
real address: Adresse d'un domicile
|
||||
consider homeless: N'est pas l'adresse d'un domicile (SDF)
|
||||
|
||||
#serach
|
||||
Your search is empty. Please provide search terms.: La recherche est vide. Merci de fournir des termes de recherche.
|
||||
|
@ -18,3 +18,8 @@ This username or email does not exists: Cet utilisateur ou email n'est pas prés
|
||||
This is not a landline phonenumber: Ce numéro n'est pas une ligne fixe valide
|
||||
This is not a mobile phonenumber: Ce numéro n'est pas un numéro de portable valide
|
||||
This is not a valid phonenumber: Ce numéro de téléphone n'est pas valide
|
||||
|
||||
address:
|
||||
street1-should-be-set: Une ligne d'adresse doit être présente
|
||||
date-should-be-set: La date de début de validité doit être présente
|
||||
postcode-should-be-set: Le code postal doit être renseigné
|
||||
|
@ -1,6 +1,10 @@
|
||||
{%- macro _render(address, options) -%}
|
||||
{%- set options = { 'with_valid_from' : true }|merge(options|default({})) -%}
|
||||
{%- set options = { 'with_valid_from' : true }|merge(options|default({})) -%}
|
||||
{%- set options = { 'has_no_address' : false }|merge(options|default({})) -%}
|
||||
<div class="chill_address">
|
||||
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
||||
<div class="chill_address_is_noaddress">{{ 'address.consider homeless'|trans }}</div>
|
||||
{% endif %}
|
||||
<div class="chill_address_address">
|
||||
{% if address.streetAddress1 is not empty %}<p class="street street1">{{ address.streetAddress1 }}</p>{% endif %}
|
||||
{% if address.streetAddress2 is not empty %}<p class="street street2">{{ address.streetAddress2 }}</p>{% endif %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user