diff --git a/app/controller/admin.php b/app/controller/admin.php index e8bfd0d46f074c67ced2af44ce71c3b72660fd91..6148e228b24650c69f6f91558ca6ca44363c6372 100644 --- a/app/controller/admin.php +++ b/app/controller/admin.php @@ -209,6 +209,7 @@ class Admin extends Controller if ($f3->exists('PARAMS.id')) { $id = $f3->get('PARAMS.id'); } + $f3->set('block_content', 'backend/don.html'); } else { $id = $f3->get('POST.id'); $pseudo = $f3->get('POST.pseudo'); @@ -267,11 +268,6 @@ class Admin extends Controller 1)"); // Récupération de l'id pour passage en mode édition $id = $db->lastInsertId(); - if ($adresse_id != '') { - $db->query("UPDATE dons - SET adresse_id = $adresse_id - WHERE id = $id"); - } } else { // We will get the ids associated to the gift first $result = $db->query("SELECT adresse_id, @@ -280,26 +276,6 @@ class Admin extends Controller WHERE id = ".\Utils::asl($f3->get('POST.id'))); $result = $result->fetch(\PDO::FETCH_ASSOC); // Let's update the adresse first or create the adress - if ($result['adresse_id'] == '0') { - $db->query("INSERT INTO adresses - (nom, adresse, adresse2, codepostal, ville, pays) - VALUES ('".\Utils::asl($nom)."', - '".\Utils::asl($adresse)."', - '".\Utils::asl($adresse2)."', - '".\Utils::asl($codepostal)."', - '".\Utils::asl($ville)."', - '".\Utils::asl($pays)."')"); - $result['adresse_id'] = $db->lastInsertId(); - } else { - $db->query("UPDATE adresses - SET nom='".\Utils::asl($nom)."', - adresse='".\Utils::asl($adresse)."', - adresse2='".\Utils::asl($adresse2)."', - codepostal='".\Utils::asl($codepostal)."', - ville='".\Utils::asl($ville)."', - pays='".\Utils::asl($pays)."' - WHERE id={$result['adresse_id']}"); - } $db->query("UPDATE users SET email='".\Utils::asl($email)."', pseudo='".\Utils::asl($pseudo)."' @@ -663,17 +639,17 @@ class Admin extends Controller ville='".\Utils::asl($ville)."', pays='".\Utils::asl($pays)."')"); $adresse_id = $db->lastInsertId(); - } - - // Updating the adresses first - $db->query("UPDATE adresses - SET nom='".\Utils::asl($nom)."', - adresse='".\Utils::asl($adresse)."', - adresse2='".\Utils::asl($adresse2)."', - codepostal='".\Utils::asl($codepostal)."', - ville='".\Utils::asl($ville)."', - pays='".\Utils::asl($pays)."' - WHERE id = $adresse_id"); + } else { + // Updating the adresses first + $db->query("UPDATE adresses + SET nom='".\Utils::asl($nom)."', + adresse='".\Utils::asl($adresse)."', + adresse2='".\Utils::asl($adresse2)."', + codepostal='".\Utils::asl($codepostal)."', + ville='".\Utils::asl($ville)."', + pays='".\Utils::asl($pays)."' + WHERE id = $adresse_id"); + }; $db->query("UPDATE contreparties SET quoi='".\Utils::asl($quoi)."', taille='".\Utils::asl($taille)."', @@ -684,27 +660,8 @@ class Admin extends Controller } } - $contrepartie = array(); if ($id!='') { - // Récupération de la contrepartie - $result = $db->query("SELECT c.id AS id, - c.user_id AS user_id, - c.quoi AS quoi, - c.taille AS taille, - c.status AS status, - a.nom AS nom, - a.adresse AS adresse, - a.codepostal AS codepostal, - a.ville AS ville, - a.pays AS pays, - u.commentaire AS commentaire - FROM contreparties c - JOIN users u ON c.user_id = u.id - LEFT JOIN adresses a ON c.adresse_id = a.id - WHERE c.id=".$id); - if ($result->fetch(\PDO::FETCH_ASSOC)) { - $contrepartie = $result->fetch(\PDO::FETCH_ASSOC); - } + $contrepartie = $f3->get('container')['counterpart_finder']->findById((int) $id); } else { $contrepartie = array( 'id'=>$id, @@ -815,7 +772,7 @@ class Admin extends Controller // Let's get everything we have related to our user $user = $f3->get('container')['user_finder']->findById($id); - $user['adresses'] = $f3->get('container')['address_finder']->findByUserId($user['id']); + $user['adresse'] = $f3->get('container')['address_finder']->findByUserId($user['id']); $user['dons'] = $f3->get('container')['donation_finder']->findByUserId($user['id']); $user['contreparties'] = $f3->get('container')['counterpart_finder']->findByUserId($user['id']); diff --git a/app/view/backend/base.html b/app/view/backend/base.html index b42b86d67a423a5f0fe4156eafc3c62ca0100c0c..3ea0abd0cff409f9b02bc296878480544470b053 100644 --- a/app/view/backend/base.html +++ b/app/view/backend/base.html @@ -1,4 +1,4 @@ <include href="backend/header.html" /> <include href="backend/toolbar.html" /> <include href="{{ @block_content }}" /> -<include href="backend/footer.html" /> +<!-- <include href="backend/footer.html" /> <!-- No need for scripts right now --> diff --git a/app/view/backend/contrepartie.html b/app/view/backend/contrepartie.html index 2742f99b1334bb921c0b0240946a15749e20a506..eed4b98d101e4264ca170b66daefe1f3ded8d24d 100644 --- a/app/view/backend/contrepartie.html +++ b/app/view/backend/contrepartie.html @@ -7,13 +7,13 @@ <h2>Ajout d'une contrepartie</h2> </false> </check> - <form name="f" method="POST" action="{{ 'edit_counterpart', 'id='+@id | alias }}"> + <form name="f" method="POST" action="{{ 'edit_counterpart', 'id='.@id | alias }}"> <input type="hidden" name="taille" id="taille" value="{{ @contrepartie.taille }}" /> <input type="hidden" name="user_id" id="user_id" value="{{ @contrepartie.user_id }}" /> <input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" /> <label for="quoi">Quoi</label> - <select id="quoi" name="quoi" onchange="select_span()"> + <select id="quoi" name="quoi"> <option value="piplome" <check if="{{ @contrepartie.quoi=='piplome' }}">selected</check> >piplome</option> <option value="pishirt" <check if="{{ @contrepartie.quoi=='pishirt' }}">selected</check> >pishirt</option> <option value="hoodie" <check if="{{ @contrepartie.quoi=='hoodie' }}">selected</check> >hoodie</option> @@ -22,15 +22,15 @@ <span id="quoi_taille"> <label for="size">Taille</label> - <select id="size" name="size" onchange="select_taille()"> - <repeat group="{{ @TAILLES }}" key="{{ @key }}" value="{{ @value }}"> + <select id="size" name="size"> + <repeat group="{{ @atailles }}" key="{{ @key }}" value="{{ @value }}"> <option value="{{ @key }}" <check if="{{ @contrepartie.taille==@key }}">selected</check> >{{ @value }}</option> </repeat> </select> </span> <span id="quoi_pdf"> <label for="url">Pdf</label> - <select id="url" name="url" onchange="select_taille()"> + <select id="url" name="url"> <repeat group="{{ @pdfs }}" value="{{ @pdf }}"> <option value="{{ @pdf.id }}" <check if="{{ @contrepartie.taille==@pdf.id }}">selected</check> >{{ @pdf.pdf }} / {{ @pdf.nom }}</option> </repeat> @@ -43,7 +43,11 @@ <br /> <label for="adresse">Adresse</label> - <textarea id="adresse" name="adresse" cols="30" rows="2">{{ @contrepartie.adresse }}</textarea> + <input type="text" id="adresse" name="adresse" size="60" value="{{ @contrepartie.adresse }}"> + <br /> + + <label for="adresse">Complément d'adresse</label> + <input type="text" id="adresse2" name="adresse2" size="60" value="{{ @contrepartie.adresse2 }}"> <br /> <label for="codepostal">Code postal</label> @@ -65,7 +69,7 @@ </select> <br /> - <label for=commentaire">Commentaire</label> + <label for="commentaire">Commentaire</label> <textarea type="textarea" id="commentaire" name="commentaire" cols="30" rows="2">{{ @contrepartie.commentaire }}</textarea> <br /> diff --git a/app/view/backend/contreparties.html b/app/view/backend/contreparties.html index b82fbff3fcb10d71971fe0537dc811b8ec09c7d4..8f71fd0a135c033e4c6298644861d0b31befe959 100644 --- a/app/view/backend/contreparties.html +++ b/app/view/backend/contreparties.html @@ -71,14 +71,14 @@ </true> <false> - {{ @TAILLES[@row.taille] }} + {{ @atailles[@row.taille] }} </false> </check> </false> </check> </td> <td> - {{ @row.nom }}<br /> + {{ @row.pseudo }}<br /> {{ @row.adresse }}<br /> {{ @row.adresse2 }}<br /> {{ @row.codepostal }} {{ @row.ville }}<br /> diff --git a/app/view/backend/dons.html b/app/view/backend/dons.html index 742a767ac9668225c77e574914373adc7dd3bde3..418656652bf9bc268f79c5ccde2496c5b260031c 100644 --- a/app/view/backend/dons.html +++ b/app/view/backend/dons.html @@ -55,8 +55,8 @@ <tr> <td>{{ @row.id }}</td> <td class="inline">{{ @row.datec }}</td> - <td>{{ @row.nom }}</td> - <td><a href="{{ 'user_info','id='.@row.user_id | alias }}">{{ @row.email }}</a></td> + <td>{{ @row.pseudo }}</td> + <td><a href="{{ 'user_info','id='.@row.user_id | alias }}">{{ @row.email }}</a></td> <td>{{ @row.somme }}</td> <td> {{ @row.adresse }}<br /> @@ -71,12 +71,12 @@ - <check if="{{ @row.status==0 || @row.status==100 }}" > <true> - <span class="lien" onclick="valid({{ @row.id }})">Valider</span> + <a href="{{ 'validate_support', 'id='.@row.id | alias }}">Valider</a> </true> <false> - <span class="lien" onclick="invalid({{ @row.id }})">Invalider</span> + <a href="{{ 'invalidate_support', 'id='.@row.id | alias }}">Invalider</a> - - <span class="lien" onclick="pdf({{ @row.id }})">PDF</span> + <a href="{{ 'validate_support', 'id='.@row.id | alias }}">PDF</a> </false> </check> </td> diff --git a/app/view/backend/user.html b/app/view/backend/user.html index 09d7a6fb8a91d7f607ed12a0d732032f348527f0..654759a317211bcdb8c9a7c16ceafbe052ff1eea 100644 --- a/app/view/backend/user.html +++ b/app/view/backend/user.html @@ -35,52 +35,50 @@ <br /> </section> <section id="adresses"> - <h2>Adresses associées à cet utilisateur</h2> - <repeat group="{{ @user.adresses }}" value="{{ @adresse }}" counter="{{ @i }}"> - <h3>{{ @i }} :{{ @adresse.alias }}</h3> - <form name="addr_{{@id }}" method="POST" action="{{ 'adresse' |alias }}"> - <input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" /> - <input type="hidden" name="id" id="id" value="{{ @adresse.id }}" /> - <input type="hidden" name="action" id="action" value="modify" /> - - <label for="nom">Nom</label> - <input type="text" id="nom" name="nom" size="30" value="{{ @adresse.nom }}" /> - <br /> - - <label for="adresse">Adresse</label> - <input type="text" id="adresse" name="adresse" size="100" value="{{ @adresse.adresse }}" /> - <br /> - - <label for="adresse2">Adresse (compl.)</label> - <input type="text" id="adresse2" name="adresse2" size="100" value="{{ @adresse.adresse2 }}" /> - <br /> - - <label for="codepostal">Code Postal</label> - <input type="text" id="codepostal" name="codepostal" size="10" value="{{ @adresse.codepostal }}" /> - <br /> - - <label for="ville">Ville</label> - <input type="text" id="ville" name="ville" size="50" value="{{ @adresse.ville }}" /> - <br /> - - <label for="etat">Etat / Province / Comté</label> - <input type="text" id="etat" name="etat" size="50" value="{{ @adresse.etat }}" /> - <br /> - - <label for="pays">Pays</label> - <input type="text" id="pays" name="pays" size="30" value="{{ @adresse.pays }}" /> - <br /> - - <input type="submit" value="Modifier l'adresse" /> - </form> - <form name="del_addr_{{@id}}" method="POST" action="{{ 'adresse' | alias }}"> - <input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" /> - <input type="hidden" name="id" id="id" value="{{ @adresse.id }}" /> - <input type="hidden" name="action" id="action" value="delete" /> - <input type="submit" value="Effacer l'adresse" /> - </form> - - </repeat> + <h2>Adresse postale de cet utilisateur</h2> + <check if="@@user.adresse"> + <form name="addr_{{@id }}" method="POST" action="{{ 'adresse' |alias }}"> + <input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" /> + <input type="hidden" name="id" id="id" value="{{ @@user.adresse.id }}" /> + <input type="hidden" name="action" id="action" value="modify" /> + + <label for="nom">Nom</label> + <input type="text" id="nom" name="nom" size="30" value="{{ @@user.adresse.nom }}" /> + <br /> + + <label for="adresse">Adresse</label> + <input type="text" id="adresse" name="adresse" size="100" value="{{ @@user.adresse.adresse }}" /> + <br /> + + <label for="adresse2">Adresse (compl.)</label> + <input type="text" id="adresse2" name="adresse2" size="100" value="{{ @@user.adresse.adresse2 }}" /> + <br /> + + <label for="codepostal">Code Postal</label> + <input type="text" id="codepostal" name="codepostal" size="10" value="{{ @@user.adresse.codepostal }}" /> + <br /> + + <label for="ville">Ville</label> + <input type="text" id="ville" name="ville" size="50" value="{{ @@user.adresse.ville }}" /> + <br /> + + <label for="etat">Etat / Province / Comté</label> + <input type="text" id="etat" name="etat" size="50" value="{{ @@user.adresse.etat }}" /> + <br /> + + <label for="pays">Pays</label> + <input type="text" id="pays" name="pays" size="30" value="{{ @@user.adresse.pays }}" /> + <br /> + + <input type="submit" value="Modifier l'adresse" /> + </form> + <form name="del_addr_{{@id}}" method="POST" action="{{ 'adresse' | alias }}"> + <input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" /> + <input type="hidden" name="id" id="id" value="{{ @@user.adresse.id }}" /> + <input type="hidden" name="action" id="action" value="delete" /> + <input type="submit" value="Effacer l'adresse" /> + </form> + </check> </section> <section id="contreparties"> <check if="{{ count(@user.contreparties) > 0}}"> @@ -123,7 +121,7 @@ <td> <check if="{{ @row.adresse_id != null }}"> <true> - {{ @user.adresses[@row.adresse_id].alias }} + {{ @@user.adresses[@row.adresse_id].nom }} </true> <false> - @@ -174,7 +172,6 @@ <th>ID</th> <th>Date</th> <th>Don</th> - <th>Adresse</th> <th>PDF</th> <th>Statut</th> <th>Actions</th> @@ -185,16 +182,6 @@ <td>{{ @row.id }}</td> <td class="inline">{{ @row.datec }}</td> <td>{{ @row.somme }}</td> - <td> - <check if="{{ array_key_exists(@row.adresse_id, @user.adresses)}}"> - <true> - {{ @user.adresses[@row.adresse_id].alias }} - </true> - <false> - - </false> - </check> - </td> <td> <check if="{{ @row.pdf == '' }}"> <true> diff --git a/src/LQDN/Command/CounterpartCreateCommand.php b/src/LQDN/Command/CounterpartCreateCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..08e31ccce276f4f42439268ed673712f61ee8714 --- /dev/null +++ b/src/LQDN/Command/CounterpartCreateCommand.php @@ -0,0 +1,54 @@ +<?php + +namespace LQDN\Command; + +class CounterPartCreateCommand +{ + private $counterpartId; + private $adresseId; + private $userId; + private $quoi; + private $taille; + private $status; + private $date; + + public function __construct($adresseId, $userId, $quoi, $taille, $status, $date) + { + $this->userId = $userId; + $this->addressId = $addressId; + $this->quoi = $quoi; + $this->taille = $taille; + $this->status = $status; + $this->date = $date; + } + + public function getUserId() + { + return $this->userId; + } + + public function getAddressId() + { + return $this->addressid; + } + + public function getQuoi() + { + return $this->quoi; + } + + public function getTaille() + { + return $this->taille; + } + + public function getStatus() + { + return $this->status; + } + + public function getDateCreation() + { + return $this->date; + } +} diff --git a/src/LQDN/Container.php b/src/LQDN/Container.php index 8a677111154a2aa7ef8ef7f440a86b08b9ecf43a..700a996f06849a2cd894a9a44d63f0070f47bbeb 100644 --- a/src/LQDN/Container.php +++ b/src/LQDN/Container.php @@ -56,6 +56,7 @@ class Container extends BaseContainer return new CommandHandler([ new Handler\AddressHandler($c['db']), new Handler\DonationHandler($c['db']), + new Handler\CounterpartHandler($c['db']), new Handler\AdminHandler($c['db']), new Handler\UserHandler($c['db']), ]); diff --git a/src/LQDN/Finder/AddressFinder.php b/src/LQDN/Finder/AddressFinder.php index eea114f7216688dfce24bf77ca4eca3b61344325..f3a395549a09031459f96d8e73db3b5e6a3d0cd1 100644 --- a/src/LQDN/Finder/AddressFinder.php +++ b/src/LQDN/Finder/AddressFinder.php @@ -27,4 +27,19 @@ class AddressFinder $addresse = $stmt->fetch(); return $addresse; } + + /** + * Return adresses linked to a counterpart + * + * @param mixed $counterpartId + * + * @return array + */ + public function findByCounterpartId($counterpartId) + { + $counterpartId = (int) $counterpartId; + $stmt = $this->connection->executeQuery('SELECT * FROM adresses WHERE user_id = :user_id', ['user_id' => $counterpartId]); + $addresse = $stmt->fetch(); + return $addresse; + } } diff --git a/src/LQDN/Finder/DonationFinder.php b/src/LQDN/Finder/DonationFinder.php index d65f779c081a9d5546374dce4744f266c9ac3edf..b2ff9feb01ec19fd6203ece4cc90331eac579894 100644 --- a/src/LQDN/Finder/DonationFinder.php +++ b/src/LQDN/Finder/DonationFinder.php @@ -53,6 +53,7 @@ SELECT d.id as id, d.status AS status, d.user_id AS user_id, u.email AS email, + u.pseudo AS pseudo, a.nom AS nom, a.adresse AS adresse, a.adresse2 AS adresse2, diff --git a/src/LQDN/Handler/CounterpartHandler.php b/src/LQDN/Handler/CounterpartHandler.php new file mode 100644 index 0000000000000000000000000000000000000000..d3a9d0ccc8d5e041470b379fc37db2f42f7d1e00 --- /dev/null +++ b/src/LQDN/Handler/CounterpartHandler.php @@ -0,0 +1,54 @@ +<?php + +namespace LQDN\Handler; + +use Doctrine\DBAL\Connection; +use LQDN\Command\CounterpartCreateCommand; +use LQDN\Command\CounterpartDeleteCommand; +use LQDN\Command\CounterpartUpdateCommand; +use LQDN\Exception\CounterpartAlreadyExistsException; + +class CounterpartHandler +{ + private $connection; + + public function __construct(Connection $connection) + { + $this->connection = $connection; + } + + /** + * Delete a counterpart + * + * @param CounterpartDeleteCommand $command + */ + public function handleCounterpartDeleteCommand(CounterpartDeleteCommand $command) + { + $counterpartId = $command->getCounterpartId(); + $this->connection->executeUpdate("DELETE FROM counterparts WHERE id = :id", + ['id' => $counterpartId()]); + } + + /** + * Create a counterpart + * + * @param CounterpartCreateCommand $command + */ + public function handleCounterpartCreateCommand(CounterpartCreateCommand $command) + { + $userId = $command->getUserId(); + $adresseId = $command->getAdressId(); + + $query =<<<EOF +REPLACE INTO counterparts(datec, user_id, addresse_id, quoi, taille, status) +VALUES (:datec, :user_id, :addresse_id, :quoi, :taille, :status) +EOF; + $stmt = $this->connection->prepare($query); + $stmt->bindValue('user_id', $command->getUserId()); + $stmt->bindValue('adresse_id', $command->getAddressId()); + $stmt->bindValue('quoi', $command->getQuoi()); + $stmt->bindValue('taille', $command->getTaille()); + $stmt->bindValue('datec', $command->getDate()); + $stmt->bindValue('status', $command->getStatus()); + } +} diff --git a/tests/functional/Finder/AddressFinderTest.php b/tests/functional/Finder/AddressFinderTest.php index e9a1b2f163fcb50309092ff386da1ea549f69154..117706e1a8a8e0f06648322478da3d50116e9e01 100644 --- a/tests/functional/Finder/AddressFinderTest.php +++ b/tests/functional/Finder/AddressFinderTest.php @@ -25,4 +25,24 @@ class AddressFinderTest extends FunctionalTest ]; $this->assertEquals($expectedAddress, $addresse); } + + public function testFindByCounterpartId() + { + $addresse = $this->container['address_finder']->findByCounterpartId(1); + $this->assertCount(9, $addresse); + + // Check the address have an ID of 1 + $expectedAddress = [ + 'id' => '1', + 'nom' => 'Main', + 'adresse' => '1 rue Ménars', + 'adresse2' => null, + 'codepostal' => '75001', + 'ville' => 'Paris', + 'etat' => null, + 'pays' => 'France', + 'user_id' => '1', + ]; + $this->assertEquals($expectedAddress, $addresse); + } }