Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beneficiaire : rendre les champs adresse optionnels dans la DB #1093

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/DoctrineMigrations/Version20231215075218.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231215075218 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE address CHANGE street1 street1 VARCHAR(255) DEFAULT NULL, CHANGE zipcode zipcode VARCHAR(255) DEFAULT NULL, CHANGE city city VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE address CHANGE street1 street1 VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE zipcode zipcode VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE city city VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
}
}
8 changes: 8 additions & 0 deletions app/Resources/views/beneficiary/_partial/address.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ address.street1 }}
{% if address.street2 %}
{{ address.street2 }}
{% endif %}
{% if address.zipCode %}
{{ "%d"|format(address.zipCode) }}
{% endif %}
{{ address.city }}
7 changes: 1 addition & 6 deletions app/Resources/views/beneficiary/_partial/info.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@
{% if beneficiary.address %}
<div class="col s12">
<i class="material-icons tiny">location_on</i>
{{ beneficiary.address.street1 }}
{% if beneficiary.address.street2 %}
{{ beneficiary.address.street2 }}
{% endif %}
{{ "%d"|format(beneficiary.address.zipCode) }}
{{ beneficiary.address.city }}
{% include "beneficiary/_partial/address.html.twig" with { address: beneficiary.address } %}
</div>
{% endif %}
{% endif %}
Expand Down
11 changes: 4 additions & 7 deletions src/AppBundle/Entity/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class Address
/**
* @var string
*
* @ORM\Column(name="street1", type="string", length=255)
* @Assert\NotBlank(message="L'adresse est requise")
* @ORM\Column(name="street1", type="string", length=255, nullable=true)
*/
private $street1;

Expand All @@ -40,8 +39,7 @@ class Address
/**
* @var string
*
* @ORM\Column(name="zipcode", type="string", length=255)
* @Assert\NotNull(message="Le code postal est requis")
* @ORM\Column(name="zipcode", type="string", length=255, nullable=true)
* @Assert\Regex(pattern="/^[0-9]+$/", message="Le code postal doit comporter uniquement des chiffres")
 * @Assert\Length(min="4", max="10", exactMessage="Le code postal doit comporter entre 4 et 10 chiffres")
*/
Expand All @@ -50,13 +48,12 @@ class Address
/**
* @var string
*
* @ORM\Column(name="city", type="string", length=255)
* @Assert\NotBlank(message="La ville est requise")
* @ORM\Column(name="city", type="string", length=255, nullable=true)
*/
private $city;

/**
* One Address has Beneficiary.
* One Address per Beneficiary.
* @ORM\OneToOne(targetEntity="Beneficiary", mappedBy="address")
*/
private $beneficiary;
Expand Down
12 changes: 5 additions & 7 deletions src/AppBundle/Form/AddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class AddressType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('street1',TextType::class,array('label'=>'Rue'))
->add('street2',TextType::class,array('label'=>'Rue 2','required'=>false))
->add('zipcode',TextType::class,array('label'=>'Code postal'))
->add('city',TextType::class,array('label'=>'Ville'));
->add('street1', TextType::class, array('label' => 'Rue'))
->add('street2', TextType::class, array('label' => 'Rue 2', 'required' => false))
->add('zipcode', TextType::class, array('label' => 'Code postal'))
->add('city', TextType::class, array('label' => 'Ville'));
}

/**
* {@inheritdoc}
*/
Expand All @@ -40,6 +40,4 @@ public function getBlockPrefix()
{
return 'appbundle_address';
}


}
2 changes: 1 addition & 1 deletion src/AppBundle/Form/UserType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ public function configureOptions(OptionsResolver $resolver)
'data_class' => User::class
));
}
}
}