Commit f6b606c8 authored by okhin's avatar okhin 🚴

Merge branch '78-souci-sur-solde-des-donateurs' into 'preprod'

Resolve "Souci sur solde des donateurs"

Closes #78

See merge request !77
parents 50a0b08e e1ffca28
Pipeline #2307 passed with stages
in 13 seconds
...@@ -887,9 +887,11 @@ class Admin extends Controller ...@@ -887,9 +887,11 @@ class Admin extends Controller
$pseudo = \Utils::asl($f3->get('POST.pseudo')); $pseudo = \Utils::asl($f3->get('POST.pseudo'));
$email = $f3->get('POST.email'); $email = $f3->get('POST.email');
$commentaire = $f3->get('POST.commentaire'); $commentaire = $f3->get('POST.commentaire');
$total = $f3->get('POST.total', 0);
$cumul = $f3->get('POST.cumul', 0);
if ($id > 0) { if ($id > 0) {
$f3->get('container')['command_handler']->handle(new UserUpdateByAdminCommand($id, $pseudo, $email, $commentaire)); $f3->get('container')['command_handler']->handle(new UserUpdateByAdminCommand($id, $pseudo, $email, $commentaire, $total, $cumul));
} else { } else {
$password = hash('sha256', \Utils::generate_password()); $password = hash('sha256', \Utils::generate_password());
$db = $f3->get('DB'); $db = $f3->get('DB');
......
...@@ -19,12 +19,20 @@ ...@@ -19,12 +19,20 @@
<input type="text" id="email" name="email" size="30" value="{{ @user.email }}" /> <input type="text" id="email" name="email" size="30" value="{{ @user.email }}" />
<br /> <br />
<label for=commentaire">Commentaire</label> <label for="commentaire">Commentaire</label>
<textarea type="textarea" id="commentaire" name="commentaire" cols="30" rows="2">{{ @user.commentaire }}</textarea> <textarea type="textarea" id="commentaire" name="commentaire" cols="30" rows="2">{{ @user.commentaire }}</textarea>
<br /> <br />
<check if="{{ @id>0 }}"> <check if="{{ @id>0 }}">
<true> <true>
<label for="total">Total de dons cumulés</label>
<input type="text" id="total" name="total" size="30" value="{{ @user.total }}" />
<br />
<label for="cumul">Cumul disponible pour les contreparties</label>
<input type="text" id="cumul" name="cumul" size="30" value="{{ @user.cumul }}" />
<br />
<input type="submit" value="Modifier cet utilisateur" /> <input type="submit" value="Modifier cet utilisateur" />
</true> </true>
<false> <false>
......
...@@ -8,6 +8,8 @@ class UserUpdateByAdminCommand ...@@ -8,6 +8,8 @@ class UserUpdateByAdminCommand
private $username; private $username;
private $email; private $email;
private $comment; private $comment;
private $cumul;
private $total;
/** /**
* __construct * __construct
...@@ -16,13 +18,17 @@ class UserUpdateByAdminCommand ...@@ -16,13 +18,17 @@ class UserUpdateByAdminCommand
* @param string $username * @param string $username
* @param string $email * @param string $email
* @param string $comment * @param string $comment
* @param string $cumul
* @param string $total
*/ */
public function __construct($id, $username, $email, $comment) public function __construct($id, $username, $email, $comment, $total, $cumul)
{ {
$this->id = $id; $this->id = $id;
$this->username = $username; $this->username = $username;
$this->email = $email; $this->email = $email;
$this->comment = $comment; $this->comment = $comment;
$this->total = $total;
$this->cumul = $cumul;
} }
public function getId() public function getId()
...@@ -44,4 +50,14 @@ class UserUpdateByAdminCommand ...@@ -44,4 +50,14 @@ class UserUpdateByAdminCommand
{ {
return $this->comment; return $this->comment;
} }
public function getTotal()
{
return $this->total;
}
public function getCumul()
{
return $this->cumul;
}
} }
...@@ -25,11 +25,13 @@ class UserHandler ...@@ -25,11 +25,13 @@ class UserHandler
*/ */
public function handleUserUpdateByAdminCommand(UserUpdateByAdminCommand $command) public function handleUserUpdateByAdminCommand(UserUpdateByAdminCommand $command)
{ {
$this->connection->executeUpdate('UPDATE users SET pseudo = :username, email = :email, commentaire = :comment WHERE id = :id', [ $this->connection->executeUpdate('UPDATE users SET pseudo = :username, email = :email, commentaire = :comment, cumul = :cumul, total = :total WHERE id = :id', [
'username' => $command->getUsername(), 'username' => $command->getUsername(),
'email' => $command->getEmail(), 'email' => $command->getEmail(),
'comment' => $command->getComment(), 'comment' => $command->getComment(),
'id' => $command->getId(), 'id' => $command->getId(),
'total' => $command->getTotal(),
'cumul' => $command->getCumul(),
]); ]);
} }
...@@ -95,7 +97,7 @@ class UserHandler ...@@ -95,7 +97,7 @@ class UserHandler
$user_id = (int) $user_id; $user_id = (int) $user_id;
$total = $this->connection->executeQuery('SELECT SUM(somme) AS total FROM dons WHERE user_id = :user_id AND STATUS IN (1, 102)', [ $total = $this->connection->executeQuery('SELECT SUM(somme) AS total FROM dons WHERE user_id = :user_id AND STATUS IN (1, 102)', [
'user_id' => $user_id 'user_id' => $user_id
])->fetchColumn(); ])->fetchAll(\PDO::FETCH_COLUMN)[0];
// Let's compute the cumul too // Let's compute the cumul too
// quoi = 'hoopie' somme = 250 // quoi = 'hoopie' somme = 250
...@@ -105,8 +107,8 @@ class UserHandler ...@@ -105,8 +107,8 @@ class UserHandler
$spent = $this->connection->executeQuery( $spent = $this->connection->executeQuery(
"SELECT sum(IF(quoi = 'hoopie',250,0)) + sum(IF(quoi = 'pishirt', 100, 0)) + sum(IF(quoi = 'pibag', 50, 0)) + sum(IF(quoi = 'piplome', 30, 0)) AS spent FROM contreparties WHERE user_id = :user_id", "SELECT sum(IF(quoi = 'hoopie',250,0)) + sum(IF(quoi = 'pishirt', 100, 0)) + sum(IF(quoi = 'pibag', 50, 0)) + sum(IF(quoi = 'piplome', 30, 0)) AS spent FROM contreparties WHERE user_id = :user_id",
[ 'user_id' => $user_id] [ 'user_id' => $user_id]
)->fetchColumn(); )->fetchAll(\PDO::FETCH_COLUMN)[0];
$this->connection->executeUpdate('UPDATE users SET total = :total, cumul = :cumul WHERE id = :user_id', ['total' => $total, 'cumul' => $total - $spent, 'user_id' => $user_id]); $this->connection->executeUpdate('UPDATE users SET total = :total, cumul = :cumul WHERE id = :user_id', ['total' => (int) $total, 'cumul' => (int) $total - (int) $spent, 'user_id' => $user_id]);
} }
} }
} }
...@@ -25,12 +25,14 @@ class UserHandlerTest extends FunctionalTest ...@@ -25,12 +25,14 @@ class UserHandlerTest extends FunctionalTest
$this->assertSame('alice@example.org', $user['email']); $this->assertSame('alice@example.org', $user['email']);
$this->assertSame('RAS', $user['commentaire']); $this->assertSame('RAS', $user['commentaire']);
$this->container['command_handler']->handle(new UserUpdateByAdminCommand(1, 'Foobar', 'foobar@example.org', 'This is foobar avé dé accênts !')); $this->container['command_handler']->handle(new UserUpdateByAdminCommand(1, 'Foobar', 'foobar@example.org', 'This is foobar avé dé accênts !', 2000, 1000));
$user = $this->getUser(1); $user = $this->getUser(1);
$this->assertSame('Foobar', $user['pseudo']); $this->assertSame('Foobar', $user['pseudo']);
$this->assertSame('foobar@example.org', $user['email']); $this->assertSame('foobar@example.org', $user['email']);
$this->assertSame('This is foobar avé dé accênts !', $user['commentaire']); $this->assertSame('This is foobar avé dé accênts !', $user['commentaire']);
$this->assertSame(2000, (int) $user['total']);
$this->assertSame(1000, (int) $user['cumul']);
} }
public function testUserCreateCommand() public function testUserCreateCommand()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment