Commit 1aabb465 authored by okhin's avatar okhin 🚴

Let's use a new command to recompute total and cumul

parent 811866d6
Pipeline #2294 failed with stages
in 1 second
......@@ -48,14 +48,6 @@ class Admin extends Controller
100 => "non applicable",
));
// Test si il y a des messages
if (!$f3->exists('SESSION.message')) {
$f3->push('SESSION.message', '');
}
if (!$f3->exists('SESSION.error')) {
$f3->push('SESSION.error', '');
}
if (!$f3->get('SESSION.admin')) {
$mapper = new\DB\SQL\Mapper($f3->get('DB'), 'admins');
$auth = new \Auth($mapper, array('id'=>'user_id', 'pw'=>'password'));
......@@ -73,6 +65,14 @@ class Admin extends Controller
public function afterRoute($f3, $args)
{
// Test si il y a des messages
if (!$f3->exists('SESSION.message')) {
$f3->push('SESSION.message', '');
}
if (!$f3->exists('SESSION.error')) {
$f3->push('SESSION.error', '');
}
// Rendu de la page
if ($this->template!='') {
echo \Template::instance()->render($this->template);
......@@ -80,14 +80,9 @@ class Admin extends Controller
// Une fois que tout est affiché, on peut supprimer les notifications
$f3->clear('SESSION.message');
$f3->clear('SESSION.error');
}
public static function recompute($f3, $args)
{
$f3->get('container')['command_handler']->handle(new AdminUpdateTotalUsersCommand());
$f3->set('block_content', 'backend/dons.html');
}
public static function hash_password($password)
{
return hash('sha256', $password);
......@@ -1427,6 +1422,12 @@ class Admin extends Controller
$f3->set('block_content', 'backend/stats.html');
}
public function recompute($f3, $args)
{
$f3->get('container')['command_handler']->handle(new AdminUpdateTotalUsersCommand());
$this->show($f3, $args);
}
public function accounts($f3, $args)
{
if ($f3->get('VERB') == 'POST') {
......
......@@ -95,8 +95,18 @@ class UserHandler
$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)', [
'user_id' => $user_id
])->fetch(\PDO::FETCH_ASSOC);
$this->connection->executeUpdate('UPDATE users SET total = :total WHERE id = :user_id', ['total' => $total['total'], 'user_id' => $user_id]);
])->fetchColumn();
// Let's compute the cumul too
// quoi = 'hoopie' somme = 250
// quoi = 'pishirt' somme = 100
// quoi = 'pibag' somme = 50
// quoi = 'piplome' somme = 30
$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",
[ 'user_id' => $user_id]
)->fetchColumn();
$this->connection->executeUpdate('UPDATE users SET total = :total, cumul = :cumul WHERE id = :user_id', ['total' => $total, 'cumul' => $total - $spent, 'user_id' => $user_id]);
}
}
}
......@@ -15,6 +15,7 @@ class UserHandlerTest extends FunctionalTest
{
$this->container['command_handler']->handle(new AdminUpdateTotalUsersCommand());
$this->assertSame(1000, (int) $this->getUser(1)['total']);
$this->assertSame(900, (int) $this->getUser(1)['cumul']);
}
public function testUserUpdateFromAdmin()
......
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