mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 16:43:48 +00:00
add address and postal code
This commit is contained in:
22
Resources/config/doctrine/Address.orm.yml
Normal file
22
Resources/config/doctrine/Address.orm.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
Chill\MainBundle\Entity\Address:
|
||||
type: entity
|
||||
table: chill_main_address
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
id: true
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
streetAddress1:
|
||||
type: string
|
||||
length: 255
|
||||
streetAddress2:
|
||||
type: string
|
||||
length: 255
|
||||
validFrom:
|
||||
type: date
|
||||
manyToOne:
|
||||
postcode:
|
||||
targetEntity: Chill\MainBundle\Entity\PostalCode
|
||||
lifecycleCallbacks: { }
|
21
Resources/config/doctrine/PostalCode.orm.yml
Normal file
21
Resources/config/doctrine/PostalCode.orm.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
Chill\MainBundle\Entity\PostalCode:
|
||||
type: entity
|
||||
table: chill_main_postal_code
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
id: true
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
name:
|
||||
type: string
|
||||
length: 255
|
||||
column: label
|
||||
code:
|
||||
type: string
|
||||
length: 100
|
||||
manyToOne:
|
||||
country:
|
||||
targetEntity: Chill\MainBundle\Entity\Country
|
||||
lifecycleCallbacks: { }
|
66
Resources/migrations/Version20160310122322.php
Normal file
66
Resources/migrations/Version20160310122322.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Add postal code and addresses
|
||||
*/
|
||||
class Version20160310122322 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('CREATE SEQUENCE chill_main_address_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE SEQUENCE chill_main_postal_code_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
|
||||
$this->addSql('CREATE TABLE chill_main_address ('
|
||||
. 'id INT NOT NULL, '
|
||||
. 'postcode_id INT DEFAULT NULL, '
|
||||
. 'streetAddress1 VARCHAR(255) NOT NULL, '
|
||||
. 'streetAddress2 VARCHAR(255) NOT NULL, '
|
||||
. 'validFrom DATE NOT NULL, '
|
||||
. 'PRIMARY KEY(id))');
|
||||
$this->addSql('CREATE INDEX IDX_165051F6EECBFDF1 ON chill_main_address '
|
||||
. '(postcode_id)');
|
||||
$this->addSql('CREATE TABLE chill_main_postal_code ('
|
||||
. 'id INT NOT NULL, '
|
||||
. 'country_id INT DEFAULT NULL, '
|
||||
. 'label VARCHAR(255) NOT NULL, '
|
||||
. 'code VARCHAR(100) NOT NULL, '
|
||||
. 'PRIMARY KEY(id))');
|
||||
$this->addSql('CREATE INDEX IDX_6CA145FAF92F3E70 ON chill_main_postal_code '
|
||||
. '(country_id)');
|
||||
$this->addSql('ALTER TABLE chill_main_address ADD CONSTRAINT '
|
||||
. 'FK_165051F6EECBFDF1 '
|
||||
. 'FOREIGN KEY (postcode_id) '
|
||||
. 'REFERENCES chill_main_postal_code (id) '
|
||||
. 'NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('ALTER TABLE chill_main_postal_code ADD CONSTRAINT '
|
||||
. 'FK_6CA145FAF92F3E70 '
|
||||
. 'FOREIGN KEY (country_id) '
|
||||
. 'REFERENCES Country (id) '
|
||||
. 'NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE chill_main_address '
|
||||
. 'DROP CONSTRAINT FK_165051F6EECBFDF1');
|
||||
$this->addSql('DROP SEQUENCE chill_main_address_id_seq CASCADE');
|
||||
$this->addSql('DROP SEQUENCE chill_main_postal_code_id_seq CASCADE');
|
||||
$this->addSql('DROP TABLE chill_main_address');
|
||||
$this->addSql('DROP TABLE chill_main_postal_code');
|
||||
}
|
||||
}
|
7
Resources/views/Address/macro.html.twig
Normal file
7
Resources/views/Address/macro.html.twig
Normal file
@@ -0,0 +1,7 @@
|
||||
{%- macro _render(address) -%}
|
||||
{% if address.streetAddress1 is not empty %}<span class="street street1">{{ address.streetAddress1 }}</span><br/>{% endif %}
|
||||
{% if address.streetAddress2 is not empty %}<span class="street street2">{{ address.streetAddress2 }}</span><br/>{% endif %}
|
||||
<span class="postalCode"><span class="code">{{ address.postCode.code }}</span> <span class="name">{{ address.postCode.name }}</span></span><br/>
|
||||
<span class="country">{{ address.postCode.country.name|localize_translatable_string }}</span><br/>
|
||||
<span class="address_since">{{ 'Since %date%'|trans( { '%date%' : address.validFrom|localizeddate('long', 'none') } ) }}</span>
|
||||
{%- endmacro -%}
|
Reference in New Issue
Block a user