Commit 05f969f8 authored by okhin's avatar okhin 🚴
Browse files

Merge branch '59-edition-d-une-adresse' into 'preprod'

Resolve "Edition d'une adresse"

Closes #59

See merge request !43
parents 8e0c6d91 f0d18089
......@@ -16,3 +16,8 @@ __MAC
tests/_data
tests/_output
tests/_support/_generated
tests/_output/*
/var/log/*
!/var/log/.gitkeep
/.php_cs.cache
tests/*/_generated/*
......@@ -72,8 +72,8 @@ class Perso extends Controller
foreach ($result->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$pdfs[$row['pdf']] = $row;
}
$addresses = $f3->get('container')['address_finder']->findByUserId((int) $data['id']);
$f3->set('adresses', $addresses);
$addresse = $f3->get('container')['address_finder']->findByUserId((int) $data['id']);
$f3->set('adresse', $addresse);
$f3->set('pdfs', $pdfs);
}
......@@ -292,7 +292,6 @@ class Perso extends Controller
$f3->error('401');
}
// Let's get the email adress of the user
switch ($f3->get('action')) {
case 'ADD':
try {
......@@ -300,14 +299,12 @@ class Perso extends Controller
new AddressCreateCommand(
\Utils::asl($f3->get('SESSION.id')),
\Utils::asl($f3->get('nom')),
\Utils::asl($f3->get('alias')),
\Utils::asl($f3->get('adresse')),
\Utils::asl($f3->get('adresse2')),
\Utils::asl($f3->get('codepostal')),
\Utils::asl($f3->get('ville')),
\Utils::asl($f3->get('pays')),
\Utils::asl($f3->get('state')),
$f3->exists('defaut')
\Utils::asl($f3->get('state'))
)
);
} catch (AddressAlreadyExistsException $e) {
......@@ -315,22 +312,6 @@ class Perso extends Controller
$f3->error('403');
}
break;
case 'UPDATE':
$f3->get('container')['command_handler']->handle(
new AddressUpdateCommand(
\Utils::asl($f3->get('id')),
\Utils::asl($f3->get('SESSION.id')),
\Utils::asl($f3->get('alias')),
\Utils::asl($f3->get('adresse')),
\Utils::asl($f3->get('adresse2')),
\Utils::asl($f3->get('codepostal')),
\Utils::asl($f3->get('ville')),
\Utils::asl($f3->get('pays')),
\Utils::asl($f3->get('state')),
$f3->exists('defaut')
)
);
break;
case 'DELETE':
try {
$f3->get('container')['command_handler']->handle(
......@@ -340,7 +321,7 @@ class Perso extends Controller
)
);
} catch (AddressUsedException $e) {
$f3->set("error", _("Cette adresse est utilisée et il vous n'avez pas définit d'adresse par défault."));
$f3->set("error", _("Cette adresse est utilisée pour une de vos contreparties"));
$f3->error('403');
};
break;
......@@ -430,7 +411,7 @@ class Perso extends Controller
FROM dons
INNER JOIN users ON users.id = dons.user_id
LEFT OUTER JOIN adresses ON adresses.user_id = users.id
WHERE users.id=".$f3->get('SESSION.id')." AND adresses.defaut IS true AND dons.id=".\Utils::asl($id).";";
WHERE users.id=".$f3->get('SESSION.id')." AND dons.id=".\Utils::asl($id).";";
$result = $db->query($query);
$logger->write($query);
$don = $result->fetch(\PDO::FETCH_ASSOC);
......
......@@ -32,7 +32,13 @@
<td>
{{ @contrepartie.nom }}<br />
{{ @contrepartie.adresse }}<br />
<check if="{{ @@contrepartie.adresse2 }}">
{{ @contrepartie.adresse2 }}<br />
</check>
{{ @contrepartie.codepostal }} {{ @contrepartie.ville }}<br />
<check if="{{ @@contrepartie.state }}">
{{ @contrepartie.state }}<br />
<check if="{{ @@contrepartie.adresse2 }}">
{{ @contrepartie.pays }}
</td>
<td>
......
......@@ -20,65 +20,36 @@
<!-- Gestion des adresses pour livrer les contreparties -->
<section id="adresses">
<h2>{{ _("Vos adresses :) }}</h2>
<repeat group="{{ @adresses }}" value="{{ @adresse }}" counter="{{ @ctr }}">
<h2>{{ _("Votre adresse postale :) }}</h2>
<form method="post" action="{{ @ALIASES.adresses}}" name="{{ adr.@ctr }}" id="{{ adr.@ctr }}">
<input type="hidden" name="action" id="action" value="UPDATE">
<p><label for="alias">{{ _("Nom de l'adresse (livraison, principale, etc) :") }}</label>
<input name="alias" id="alias" class="{{ Utils::badfield(array(6)) }}" value="{{ @adresse.alias }}" ></p>
<input type="hidden" name="action" id="action" value="ADD">
<p><label for="nom">{{ _("Nom, Prénom, Pseudo (pensez au facteur) :") }}</label>
<input name="nom" id="nom" class="{{ Utils::badfield(array(6)) }}" value="{{ @adresse.nom }}" ></p>
<input name="nom" id="nom" class="{{ Utils::badfield(array(6)) }}" value="{{ @@adresse.nom }}" ></p>
<p><label for="adresse">{{ _("Adresse postale :") }}</label>
<textarea name="adresse" id="adresse" class="{{ Utils::badfield(array(6)) }}">{{ @adresse.adresse }}</textarea></p>
<textarea name="adresse" id="adresse" class="{{ Utils::badfield(array(6)) }}">{{ @@adresse.adresse }}</textarea></p>
<p><label for="adresse2">{{ _("Complément d'adresse :") }}</label>
<textarea name="adresse2" id="adresse2" class="{{ Utils::badfield(array(6)) }}">{{ @adresse.adresse2 }}</textarea></p>
<textarea name="adresse2" id="adresse2" class="{{ Utils::badfield(array(6)) }}">{{ @@adresse.adresse2 }}</textarea></p>
<p><label for="ville">{{ _("Ville :") }}</label>
<input name="ville" id="ville" class="{{ Utils::badfield(array(6)) }}" value="{{ @adresse.ville }}" ></p>
<input name="ville" id="ville" class="{{ Utils::badfield(array(6)) }}" value="{{ @@adresse.ville }}" ></p>
<p><label for="state">{{ _("Province / État :") }}</label>
<input name="state" id="state" class="{{ Utils::badfield(array(6)) }}" value="{{ @@adresse.state }}" ></p>
<p><label for="codepostal">{{ _("Code Postal :") }}</label>
<input name="codepostal" id="codepostal" class="{{ Utils::badfield(array(6)) }}" value="{{ @adresse.codepostal }}" ></p>
<input name="codepostal" id="codepostal" class="{{ Utils::badfield(array(6)) }}" value="{{ @@adresse.codepostal }}" ></p>
<p><label for="pays">{{ _("Pays :") }}</label>
<input name="pays" id="pays" class="{{ Utils::badfield(array(6)) }}" value="{{ @adresse.pays }}" ></p>
<input name="pays" id="pays" class="{{ Utils::badfield(array(6)) }}" value="{{ @@adresse.pays }}" ></p>
<p><input type="submit" class="big_button" value="{{ _('Valider les modifications') }} &gt;&gt;" ></p>
</form>
<form method="post" action="{{ @ALIASES.adresses }}" name="{{ del.@ctr }}" id="{{ del.@ctr }}">
<input type="hidden" name="action" id="action" value="DELETE">
<input type="hidden" name="alias" id="alias" value="{{ @adresse.alias }}">
<p><input type="submit" class="big_button" value="{{ _('Supprimer cette adresse') }}" ></p>
</form>
</repeat>
<form method="post" action="{{ @ALIASES.adresses}}" name="{{ add_adr }}" id="{{ add_adr }}">
<input type="hidden" name="action" id="action" value="ADD">
<p><label for="alias">{{ _("Nom de l'adresse (livraison, principale, etc) :") }}</label>
<input name="alias" id="alias" class="{{ Utils::badfield(array(6)) }}"></p>
<p><label for="nom">{{ _("Nom, Prénom, Pseudo (pensez au facteur) :") }}</label>
<input name="nom" id="nom" class="{{ Utils::badfield(array(6)) }}"></p>
<p><label for="adresse">{{ _("Adresse postale :") }}</label>
<textarea name="adresse" id="adresse" class="{{ Utils::badfield(array(6)) }}"></textarea></p>
<p><label for="adresse2">{{ _("Complément d'adresse :") }}</label>
<textarea name="adresse2" id="adresse2" class="{{ Utils::badfield(array(6)) }}"></textarea></p>
<p><label for="ville">{{ _("Ville :") }}</label>
<input name="ville" id="ville" class="{{ Utils::badfield(array(6)) }}"></p>
<p><label for="codepostal">{{ _("Code Postal :") }}</label>
<input name="codepostal" id="codepostal" class="{{ Utils::badfield(array(6)) }}" ></p>
<p><label for="pays">{{ _("Pays :") }}</label>
<input name="pays" id="pays" class="{{ Utils::badfield(array(6)) }}" ></p>
<p><input type="submit" class="big_button" value="{{ _('Ajouter une adresse postale.') }} &gt;&gt;" /></p>
<p><input type="submit" class="big_button" value="{{ _('Supprimer votre adresse') }}" ></p>
</form>
</section>
<!-- Gestion des demandes de contreparties -->
......@@ -173,13 +144,10 @@
<p id="admin_taille_h"><label for="taille_h">{{ _("Coupe et taille du hoodie:") }}</label>
<select name="taille_h" id="taille_h">{{ Utils::eoption(@atailles, @taille_h) }}</select></p>
<p id="admin_adresses"><label for="alias">{{ _("Adresse de livraison:") }}</label>
<select name="adresse_id" id="adresse_id">
<repeat group="{{ @adresses }}" value="{{ @adresse }}">
<option value="{{ @adresse.id }}">{{@adresse.alias}}</option>
</repeat>
<input type="hidden" name="adresse_id" id="adresse_id" value="{{ @adresse.id }}">
Expédier à&nbsp;: {{@adresse.nom}} {{@adresse.adresse}}
</select></p>
<input type="submit" class="big_button" value="Valider" />
<input type="submit" class="big_button" value="Valider" <check if="{{ @adresse }}"><false>disabled</false>/</check>/>
</div>
<check if="{{ @error!='' }}">
<p class="error">{{ @error }}</p>
......
......@@ -69,68 +69,54 @@
<input id="adresses" type="checkbox">
<label for="adresses" class="panel-heading" role="tab" id="headingInfos">
<div class="panel-title col-xs text-left">
{{ _("Adresses")}}
{{ _("Adresse")}}
<div class="panel-title col-xs-2 text-right">
</div>
</div>
</label>
<div id="collapseAdresses" class="panel-collapse collapse" href="#collapseAdresses" aria-expanded="false" aria-controls="collapseAdresses">
<div class="panel-body text-left">
<check if="{{ count(@adresses) > 0 }}">
<h3>{{ _("Modifier une adresse")}}</h3>
<form>
<div class="form-group">
<label for="">{{ _("Modifier une adresse")}}</label>
<select class="form-control">
<repeat group="{{ @adresses }}" value="{{ @adresse }}">
<option value="{{ @adresse.id }}">{{ @adresse.alias }}</option>
</repeat>
</select>
</div>
</form>
<h3>{{ _("Ajouter une nouvelle adresse.")}}</h3>
<h3>{{ _("Renseigner votre adresse.")}}</h3>
<form method="POST" action="{{ 'adresses' | alias }}" id="create-adress-form">
<input type="hidden" name="csrf" value="{{ @CSRF }}" />
<input type="hidden" name="action" value="ADD" />
<input type="hidden" name="id" value="" />
<div class="form-group">
<label for="alias">{{ _("Nom de l'adresse")}}</label>
<input type="text" class="form-control" name="alias" value="">
</div>
<input type="hidden" name="id" value="{{ @@adresse.id }}" />
<div class="form-group">
<label for="nom">{{ _("Destinataire") }}</label>
<input type="text" class="form-control" name="nom" value="">
<input type="text" class="form-control" name="nom" value="{{ @@adresse.nom }}">
</div>
<div class="form-group">
<label for="adresse">{{ _("Adresse")}}</label>
<input type="text" class="form-control" name="adresse" value="">
<input type="text" class="form-control" name="adresse" value="{{ @@adresse.adresse }}">
</div>
<div class="form-group">
<label for="adresse2">{{ _("Complément d'adresse")}}</label>
<input type="text" class="form-control" name="adresse2" value="">
<input type="text" class="form-control" name="adresse2" value=" {{ @@adresse.adresse2 }}">
</div>
<div class="form-group">
<label for="codepostal">{{ _("Code Postal")}}</label>
<input type="text" class="form-control" name="codepostal" value="">
<input type="text" class="form-control" name="codepostal" value="{{ @@adresse.codepostal }}">
</div>
<div class="form-group">
<label for="ville">{{ _("Ville")}}</label>
<input type="text" class="form-control" name="ville" value="">
<input type="text" class="form-control" name="ville" value="{{ @@adresse.ville }}">
</div>
<div class="form-group">
<label for="state">{{ _("Province / État")}}</label>
<input type="text" class="form-control" name="state" value="">
<input type="text" class="form-control" name="state" value="{{ @@adresse.state }}">
</div>
<div class="form-group">
<label for="pays">{{ _("Pays")}}</label>
<input type="text" class="form-control" name="pays" value="">
</div>
<div class="form-group">
<label for="default">
<input type="checkbox" name="defaut" value="true" >{{ _("Utiliser comme adresse par défaut.") }}
</label>
<input type="text" class="form-control" name="pays" value="{{ @@adresse.pays }}">
</div>
<check if="{{ @adresse }}">
<true>
<input type="submit" class="btn btn-lg c-boutonslongs" value="{{ _("Modifier cette adresse")}}">
</true>
<false>
<input type="submit" class="btn btn-lg c-boutonslongs" value="{{ _("Créer cette adresse")}}">
</false>
</check>
</form>
</div>
</div>
......@@ -370,26 +356,21 @@
</div>
</div><!-- / Hoopi -->
</check>
<check if="{{ count(@adresses) < 1 }}">
<check if="{{ @adresse }}">
<true>
<div class="col-md-8 col-md-offset-2">
<h3>Veuillez ajouter une adresse postale <a href="#headingInfos" for="adresses">ici</a></h3>
</div>
</true>
<false>
<div class="col-md-8 col-md-offset-2">
<h3>Veuillez ajouter une adresse postale <a href="#headingInfos" for="adresses">ici</a></h3>
</div>
</false>
</check>
<check if="{{ count(@adresses) > 0 }}">
<div class="col-md-8 col-md-offset-2"><!-- Adresse -->
<div class="form-group form-inline">
<label for="adresses">{{ _("Envoyer à l'adresse :")}}</label>
<select class="form-control" name="adresse_id">
<repeat group="{{ @adresses }}" value="{{ @adresse }}">
<option value="{{ @adresse.id }}" <check if="{{ @adresse.defaut != 0 }}">selected</check>>{{ @adresse.alias }} - {{ @adresse.adresse }} {{@adresse.adresse2 }}</option>
</repeat>
</select>
</div>
</div><!-- / Adresse -->
<div class="col-md-8 col-md-offset-2"><!-- Bouton -->
<input type="submit" class="btn btn-lg btn-primary c-boutonscourts" value="{{ _('Envoyer')}}">
<input type="submit" class="btn btn-lg btn-primary c-boutonscourts" value="{{ _('Envoyer')}}" <check if="{{ @adresse }}"><false>disabled</false></check>>
</div><!-- / bouton -->
</check>
</form>
</div>
</div>
......@@ -405,11 +386,25 @@
<div class="modal-body">
<h3>{{ _("Envoyer à l'adresse&nbsp;:") }}</h3>
<p class="addressmodal">
<<<<<<< HEAD
{{ @adresse.nom }}<br>
{{ @adresse.adresse }}<br>
<check if="{{ @@adresse.adresse2 }}">
{{ @adresse.adresse2 }}<br>
</check>
{{ @adresse.codepostal }}&nbsp;
{{ @adresse.ville }}
<check if="{{ @@adresse.state }}">
{{ @adresse.state }}&nbsp;
</check>
{{ @adresse.pays }}
=======
{{ @adresses[@GET['adresse_id']].nom }}<br>
{{ @adresses[@GET['adresse_id']].adresse }}<br>
{{ @adresses[@GET['adresse_id']].adresse2 }}<br>
{{ @adresses[@GET['adresse_id']].codepostal }}&nbsp;
{{ @adresses[@GET['adresse_id']].ville }}
>>>>>>> 79b1a677cd3183f3c04a575e24f8c3957afe708c
</p>
<h3>{{ _("Récapitulatif&nbsp;:") }}</h3>
<ul class="list-unstyled">
......@@ -437,9 +432,25 @@
<li class="media">
<div class="media-left">
<img class="media-object" src="/static/img/pishirt2.svg" alt="">
<<<<<<< HEAD
</div>
<div class="media-body">
{{ _("Un pi-shirt") }} ({{@atailles[@GET['taille']]}})
</div>
</li>
</check>
<check if="{{ in_array(@GET['quoi'], array('hoopie')) }}">
<li class="media">
<div class="media-left">
<img class="media-object" src="/static/img/hoopie2.svg" alt="">
</div>
<div class="media-body">
{{ _("Un hoopie") }} ({{@atailles[@GET['taille_h']]}})
=======
</div>
<div class="media-body">
{{ _("Un pi-shirt") }}
>>>>>>> 79b1a677cd3183f3c04a575e24f8c3957afe708c
</div>
</li>
</check>
......@@ -450,6 +461,30 @@
</div>
<div class="media-body">
{{ _("Un hoopie") }}
<<<<<<< HEAD
</div>
</li>
</check>
</ul>
</div>
<div class="form-group text-left">
<label for="commentaire"><h3>{{ _("Un commentaire&nbsp;? Si il y a un objet du pack que vous ne voulez pas indiquez-le nous :)") }}</h3></label>
<textarea class="form-control" id="commentaire" name="commentaire" placeholder="" row="3"></textarea>
<div class="modal-footer">
<input type="hidden" name="csrf" value="{{ @CSRF }}">
<repeat group="{{@GET}}" key="{{ @key }}" value="{{ @value }}">
<input type="hidden" name="{{ @key }}" value="{{ @value }}">
</repeat>
<a href="{{ 'perso' | alias }}" type="button" class="btn btn-default" data-dismiss="modal">Close</a>
<input type="submit" class="btn btn-primary" value="{{ _('Valider') }}">
</div>
</div>
</div>
</form>
</div>
</check>
=======
>>>>>>> 79b1a677cd3183f3c04a575e24f8c3957afe708c
</div>
</li>
</check>
......
<?php
use Phinx\Migration\AbstractMigration;
class UneSeuleAdresse extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function up()
{
// Removing the alias <> user_id index
$table = $this->table('adresses');
$table->removeIndex(['alias', 'user_id'])
->save();
// Deleting all addresses, to be sure we don't have doubles
$this->execute('TRUNCATE TABLE adresses;');
// Add a unique index on user_id
$table->addIndex(['user_id'], ['unique' => true])
->removeColumn('alias')
->save();
}
public function down() {
$table = $this->table('adresses');
$table->addColumn('alias', 'string')
->removeIndex(['user_id'])
->save();
$table->addIndex(['alias', 'user_id'], ['unique' => true])
->save();
}
}
<?php
use Phinx\Migration\AbstractMigration;
class RemoveAddressDefaut extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* addCustomColumn
* renameColumn
* addIndex
* addForeignKey
*
* Any other destructive changes will result in an error when trying to
* rollback the migration.
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function up()
{
$table = $this->table('adresses');
$table->removeColumn('defaut')
->save();
}
public function down()
{
$table = $this->table('adresses');
$table->addColumn('defaut', 'boolean')
->save();
}
}
......@@ -24,38 +24,10 @@ class AddressSeeder extends AbstractSeed
'ville' => 'Paris',
'etat' => null,
'pays' => 'France',
'alias' => 'Main',
'user_id' => 1,
'defaut' => true,
),
array(
'id' => 2,
'nom' => 'Second address',
'adresse' => '2 rue Ménars',
'adresse2' => null,
'codepostal' => 75002,
'ville' => 'Paris',
'etat' => null,
'pays' => 'France',
'alias' => 'Second address',
'user_id' => 1,
'defaut' => false,
),
array(
'id' => 4,
'nom' => 'Third address',
'adresse' => '3 rue Ménars',
'adresse2' => null,
'codepostal' => 75003,
'ville' => 'Paris',
'etat' => null,
'pays' => 'France',
'alias' => 'Third address',
'user_id' => 1,
'defaut' => false,
),
array(
'id' => 5,
'nom' => 'Bob address',
'adresse' => '4 rue Ménars',
'adresse2' => null,
......@@ -63,9 +35,7 @@ class AddressSeeder extends AbstractSeed
'ville' => 'Paris',
'etat' => null,
'pays' => 'France',
'alias' => 'Third address',
'user_id' => 2,
'defaut' => false,
),
);
......
......@@ -17,7 +17,7 @@ environments:
development:
adapter: mysql
host: localhost
name: soutien
name: don
user: soutien
pass: 'soutien'
port: 3306
......
......@@ -7,27 +7,23 @@ class AddressCreateCommand
private $addressId;
private $userId;
private $name;
private $alias;
private $address;
private $address2;
private $postalCode;
private $city;
private $country;
private $state;
private $isDefault;
public function __construct($userId, $name, $alias, $address, $address2, $postalCode, $city, $country, $state, $isDefault)
public function __construct($userId, $name, $address, $address2, $postalCode, $city, $country, $state)
{
$this->userId = $userId;
$this->name = $name;
$this->alias = $alias;
$this->address = $address;
$this->address2 = $address2;
$this->postalCode = $postalCode;
$this->city = $city;
$this->country = $country;
$this->state = $state;
$this->isDefault = $isDefault;
}
public function getUserId()
......@@ -40,11 +36,6 @@ class AddressCreateCommand
return $this->name;
}
public function getAlias()
{
return $this->alias;
}
public function getAddress()
{
return $this->address;
......@@ -74,9 +65,4 @@ class AddressCreateCommand
{
return $this->state;
}