From a2f6773f5a3d2606155b1159f807a8753841796f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 18 Mar 2021 13:14:37 +0100 Subject: [PATCH] import changes on address from chill main --- src/Bundle/ChillMain/CHANGELOG.md | 10 ++++++ src/Bundle/ChillMain/Entity/Address.php | 32 +++++++++++++++++-- .../Resources/views/Form/fields.html.twig | 10 ++++++ .../migrations/Version20210308111926.php | 32 +++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/Bundle/ChillMain/migrations/Version20210308111926.php diff --git a/src/Bundle/ChillMain/CHANGELOG.md b/src/Bundle/ChillMain/CHANGELOG.md index 2b89172e8..9cda80ae4 100644 --- a/src/Bundle/ChillMain/CHANGELOG.md +++ b/src/Bundle/ChillMain/CHANGELOG.md @@ -146,3 +146,13 @@ Version 1.5.21 - [CRUD] Forward query parameters when pushing button "save and new" in "create" page; - [Show/hide] Take selects input into account; +Version 1.5.23 +============== + +- [address] allow to add custom fields to addresses + +Version 1.5.24 +============== + +- [bugfix] add missing migration files + diff --git a/src/Bundle/ChillMain/Entity/Address.php b/src/Bundle/ChillMain/Entity/Address.php index 15c5c28e5..69c39c7b6 100644 --- a/src/Bundle/ChillMain/Entity/Address.php +++ b/src/Bundle/ChillMain/Entity/Address.php @@ -58,19 +58,22 @@ class Address * True if the address is a "no address", aka homeless person, ... * * @var bool - * @ORM\Column(type="boolean") */ private $isNoAddress = false; - /** - * Address constructor. + * A list of metadata, added by customizable fields + * + * @var array */ + private $customs = []; + public function __construct() { $this->validFrom = new \DateTime(); } + /** * Get id * @@ -205,6 +208,29 @@ class Address return $this; } + /** + * Get customs informations in the address + * + * @return array + */ + public function getCustoms(): array + { + return $this->customs; + } + + /** + * Store custom informations in the address + * + * @param array $customs + * @return $this + */ + public function setCustoms(array $customs): self + { + $this->customs = $customs; + + return $this; + } + /** * Validate the address. * diff --git a/src/Bundle/ChillMain/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMain/Resources/views/Form/fields.html.twig index a7851f7b5..e678932f0 100644 --- a/src/Bundle/ChillMain/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMain/Resources/views/Form/fields.html.twig @@ -187,3 +187,13 @@ {% endif %} {% endblock %} + +{% block address_widget %} + {% for entry in form %} + {% if entry.vars.name != 'customs' %} + {{ form_row(entry) }} + {% else %} + {{ form_widget(entry) }} + {% endif %} + {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/src/Bundle/ChillMain/migrations/Version20210308111926.php b/src/Bundle/ChillMain/migrations/Version20210308111926.php new file mode 100644 index 000000000..368a3dec8 --- /dev/null +++ b/src/Bundle/ChillMain/migrations/Version20210308111926.php @@ -0,0 +1,32 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE chill_main_address ADD customs JSONB DEFAULT \'[]\''); + + } + + public function down(Schema $schema) : void + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE chill_main_address DROP customs'); + } + + public function getDescription(): string + { + return "Add custom data in addresses"; + } +}