Commit f2003609 authored by okhin's avatar okhin 🚴

Merge branch 'preprod' into 'master'

Preprod

See merge request !89
parents 7a87d896 38baf090
Pipeline #2335 passed with stages
in 1 minute and 37 seconds
......@@ -439,7 +439,9 @@ class Admin extends Controller
}
if ($user['cumul'] >= $needed) {
// Assez de point, on crée
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand($adresse['id'], $user['id'], $quoi, 1, 2, date("Y-m-d H:i:s"), 'Imported from a file'));
// On récupère le dernier ID inséré
$parent = $f3->get('container')['counterpart_finder']->getNextInsertedId();
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand($adresse['id'], $user['id'], $quoi, 1, 2, date("Y-m-d H:i:s"), 'Imported from a file', $parent));
// On mets à jour le cumul de l'utilisateur
$f3->get('container')['command_handler']->handle(new UserUpdateCumulCommand($user['id'], $user['cumul'] - $needed));
$total[$quoi] +=1;
......
......@@ -309,6 +309,7 @@ class Perso extends Controller
$f3->error('401');
}
$db = $f3->get('DB');
$user = $f3->get('container')['user_finder']->findById($f3->get('SESSION.id'));
// Récupération des valeurs du formulaire
......@@ -336,18 +337,19 @@ class Perso extends Controller
// Ajout d'une demande de contrepartie pour chaque contrepartie
if ((int) $user['cumul'] >= $valeur) {
$parent = $f3->get('container')['counterpart_finder']->getNextInsertedId();
switch ($quoi) {
case 'piplome':
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'piplome', \Utils::asl($piplome_id), 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire)));
break;
case 'pibag':
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'pibag', '', 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire)));
break;
case 'pishirt':
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'pishirt', \Utils::asl($taille), 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire)));
break;
case 'hoodie':
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'hoodie', \Utils::asl($taille_h), 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire)));
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'hoodie', \Utils::asl($taille_h), 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire), $parent));
// no break
case 'pishirt':
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'pishirt', \Utils::asl($taille), 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire), $parent));
// no break
case 'pibag':
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'pibag', '', 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire), $parent));
// no break
case 'piplome':
$f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'piplome', \Utils::asl($piplome_id), 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire), $parent));
break;
}
// Puis diminution du cumul de la valeur des contreparties
......
......@@ -43,6 +43,7 @@
<table cellspacing="0" cellpadding="0">
<theader>
<th>Id</th>
<th>Id du parent</th>
<th>Email</th>
<th>Date</th>
<th>Quoi</th>
......@@ -56,7 +57,8 @@
<repeat group="{{ @data }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td><a href="{{'user_info', 'id='.@row.user_id | alias }}">{{ @row.email }}</a></td>
<td>{{ @row.parent }}</td>
<td><a href="{{'user_info', 'id='.@row.user_id | alias }}">{{ @row.email }}</a></td>
<td>{{ @row.datec }}</td>
<td>{{ @row.quoi }}</td>
<td>
......
......@@ -95,6 +95,7 @@
<table cellspacing="0" cellpadding="0">
<theader>
<th>Id</th>
<th>Id du parent</th>
<th>Date</th>
<th>Quoi</th>
<th>Taille/Piplome</th>
......@@ -106,6 +107,7 @@
<repeat group="{{ @user.contreparties }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td>{{ @row.parent }}</td>
<td>{{ @row.datec }}</td>
<td>{{ @row.quoi }}</td>
<td>
......
<?php
use Phinx\Migration\AbstractMigration;
class AddParentField 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('contreparties');
if (!$table->hasColumn('parent')) {
$table->addColumn('parent', 'integer');
$table->save();
}
// Let's set some default value
$builder = $this->getQueryBuilder();
$stmt = $builder->update('contreparties', 'c')
->set('parent', 'id')
// ->where('parent = 0')
->execute();
}
public function down()
{
$table = $this->table('contreparties');
if ($table->hasColumn('parent')) {
$table->removeColumn('parent')
->save();
}
}
}
......@@ -23,6 +23,7 @@ class CounterpartSeeder extends AbstractSeed
'taille' => 8,
'status' => 1,
'adresse_id' => 1,
'parent' => 1,
),
array(
'id' => 2,
......@@ -32,6 +33,7 @@ class CounterpartSeeder extends AbstractSeed
'taille' => 2,
'status' => 2,
'adresse_id' => null,
'parent' => 4,
),
array(
'id' => 3,
......@@ -41,6 +43,7 @@ class CounterpartSeeder extends AbstractSeed
'taille' => 2,
'status' => 2,
'adresse_id' => null,
'parent' => 4,
),
array(
'id' => 4,
......@@ -50,6 +53,7 @@ class CounterpartSeeder extends AbstractSeed
'taille' => 2,
'status' => 2,
'adresse_id' => null,
'parent' => 4,
),
);
......
......@@ -12,7 +12,7 @@ class CounterpartCreateCommand
private $status;
private $date;
public function __construct($addressId, $userId, $quoi, $taille, $status, $date, $commentaire)
public function __construct($addressId, $userId, $quoi, $taille, $status, $date, $commentaire, $parent)
{
$this->userId = $userId;
$this->addressId = $addressId;
......@@ -21,6 +21,7 @@ class CounterpartCreateCommand
$this->status = $status;
$this->date = $date;
$this->commentaire = $commentaire;
$this->parent = $parent;
}
public function getUserId()
......@@ -57,4 +58,9 @@ class CounterpartCreateCommand
{
return $this->commentaire;
}
public function getParent()
{
return $this->parent;
}
}
......@@ -57,6 +57,18 @@ EOQ;
return $counterparts;
}
/**
* return the id of the next item to be inserted
*
* @return int
*/
public function getNextInsertedId()
{
return (int) $this->connection->fetchColumn(
"SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'contreparties' AND table_schema = DATABASE()"
);
}
/**
* Return all counterparts in a specific status
*
......
......@@ -43,8 +43,8 @@ class CounterpartHandler
$adresseId = $command->getAddressId();
$query =<<<EOF
INSERT INTO contreparties(datec, user_id, adresse_id, quoi, taille, status, commentaire)
VALUES (:datec, :user_id, :adresse_id, :quoi, :taille, :status, :commentaire)
INSERT INTO contreparties(datec, user_id, adresse_id, quoi, taille, status, commentaire, parent)
VALUES (:datec, :user_id, :adresse_id, :quoi, :taille, :status, :commentaire, :parent)
EOF;
$stmt = $this->connection->prepare($query);
$stmt->bindValue('datec', $command->getDateCreation());
......@@ -54,6 +54,7 @@ EOF;
$stmt->bindValue('taille', $command->getTaille());
$stmt->bindValue('status', $command->getStatus());
$stmt->bindValue('commentaire', $command->getCommentaire());
$stmt->bindValue('parent', $command->getParent());
$stmt->execute();
}
......
......@@ -100,12 +100,13 @@ class UserHandler
])->fetchAll(\PDO::FETCH_COLUMN)[0];
// Let's compute the cumul too
// We only want line where id == parent, others are children of one claim
// quoi = 'hoodie' somme = 250
// quoi = 'pishirt' somme = 100
// quoi = 'pibag' somme = 50
// quoi = 'piplome' somme = 30
$spent = $this->connection->executeQuery(
"SELECT sum(IF(quoi = 'hoodie',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 = 'hoodie',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 AND id = parent",
[ 'user_id' => $user_id]
)->fetchAll(\PDO::FETCH_COLUMN)[0];
$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]);
......
......@@ -26,6 +26,7 @@ class CounterpartFinderTest extends FunctionalTest
'pdf_nom' => 'Main',
'pdf_url' => 'pdf',
'commentaire' => '',
'parent' => '4',
];
$this->assertEquals($expectedCounterpart, $firstCounterpart);
}
......@@ -49,6 +50,7 @@ class CounterpartFinderTest extends FunctionalTest
'pdf_nom' => 'Main',
'pdf_url' => 'pdf',
'commentaire' => '',
'parent' => '4',
];
$this->assertEquals($expectedCounterpart, $firstCounterpart);
......@@ -72,6 +74,7 @@ class CounterpartFinderTest extends FunctionalTest
'pdf_nom' => '',
'pdf_url' => '',
'commentaire' => '',
'parent' => '1',
];
$this->assertEquals($expectedCounterpart, $firstCounterpart);
}
......
......@@ -21,7 +21,7 @@ class CounterpartHandlerTest extends FunctionalTest
{
$this->assertFalse($this->counterpartExists(5));
$this->container['command_handler']->handle(new CounterpartCreateCommand(1, 1, 'pishirt', 4, 1, date("Y-m-d H:i:s"), ''));
$this->container['command_handler']->handle(new CounterpartCreateCommand(1, 1, 'pishirt', 4, 1, date("Y-m-d H:i:s"), '', 1));
}
public function testCounterpartChangeState()
......
......@@ -16,6 +16,8 @@ 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']);
$this->assertSame(1000, (int) $this->getUser(2)['total']);
$this->assertSame(750, (int) $this->getUser(2)['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