Skip to content

Commit

Permalink
Add date & qte fields to purchases
Browse files Browse the repository at this point in the history
* add date & qte fields to purchases of Purchase$getPurchasesForUser return
* rename User$getLastPurchase into User$getLastPurchases
  • Loading branch information
trecouvr committed Sep 12, 2013
1 parent faf1bc4 commit d1f30ad
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Payutc/Bom/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static function getRank($fun_id, $obj_id, $start, $end, $top, $sort_by) {
public static function getPurchasesForUser($usr_id, $time_limit=null)
{
$qb = Dbal::createQueryBuilder();
$qb->select('pur_id', 'obj_id', 'pur_price')
$qb->select('pur_id', 'obj_id', 'pur_price', 'pur_qte', 'pur_date')
->from('t_purchase_pur', 'pur')
->Where('usr_id_buyer = :usr_id')
->andWhere('pur_removed = 0')
Expand Down
4 changes: 2 additions & 2 deletions src/Payutc/Bom/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ public function isCotisant() {
*
* @return array $return
*/
public function getLastPurchase() {
public function getLastPurchases() {
return Purchase::getPurchasesForUser($this->getId(), 60*15);
}

/**
* Initialiser ginger, éventuellement avec une URL perso
*
Expand Down
2 changes: 1 addition & 1 deletion src/Payutc/Service/POSS2.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function getBuyerInfo($badge_id) {
"firstname"=>$buyer->getFirstname(),
"lastname"=>$buyer->getLastname(),
"solde"=>$buyer->getCredit(),
"last_purchase"=>$buyer->getLastPurchase()
"last_purchase"=>$buyer->getLastPurchases()
));
} else {
Log::warn("getBuyerInfo() : No Seller loaded");
Expand Down
2 changes: 1 addition & 1 deletion src/Payutc/Service/POSS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getBuyerInfo($badge_id) {
"firstname"=>$buyer->getFirstname(),
"lastname"=>$buyer->getLastname(),
"solde"=>$buyer->getCredit(),
"last_purchases"=>$buyer->getLastPurchase()
"last_purchases"=>$buyer->getLastPurchases()
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Payutc/Service/Poss3RodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testTransactionWithoutEnoughCredit()
{
$u = new User("trecouvr");
$solde = $u->getCredit();
$nb_purchase = count($u->getLastPurchase());
$nb_purchase = count($u->getLastPurchases());
$cookie = '';
$r = httpSend('POSS3', 'loginCas', $cookie, array(
'ticket' => 'trecouvr@POSS3',
Expand Down
6 changes: 3 additions & 3 deletions tests/Payutc/Service/Poss3RwdbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testTransaction()
{
$u = new User("trecouvr");
$solde = $u->getCredit();
$nb_purchase = count($u->getLastPurchase());
$nb_purchase = count($u->getLastPurchases());
$cookie = '';
$r = httpSend('POSS3', 'loginCas', $cookie, array(
'ticket' => 'trecouvr@POSS3',
Expand All @@ -55,7 +55,7 @@ public function testTransaction()
$this->assertEquals(200, $r->code);
$u = new User("trecouvr");
$this->assertEquals($solde-280, $u->getCredit());
$purchases = $u->getLastPurchase();
$purchases = $u->getLastPurchases();
sort_by_key($purchases, 'pur_id');
$this->assertEquals($nb_purchase+3, count($purchases));
$purchases = array_slice($purchases, count($purchases)-3);
Expand All @@ -74,7 +74,7 @@ public function testCancel()
{
$u = new User("trecouvr");
$solde = $u->getCredit();
$nb_purchase = count($u->getLastPurchase());
$nb_purchase = count($u->getLastPurchases());
$cookie = '';
$r = httpSend('POSS3', 'loginCas', $cookie, array(
'ticket' => 'trecouvr@POSS3',
Expand Down
11 changes: 11 additions & 0 deletions tests/PurchaseRodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public function testGetRank() {
$this->assertEquals($waited,$r);

}

public function testGetPurchasesForUser() {
$purchases = Purchase::getPurchasesForUser(9447);
$this->assertTrue(count($purchases) > 0);
$pur = $purchases[0];
$this->assertArrayHasKey('pur_id', $pur);
$this->assertArrayHasKey('obj_id', $pur);
$this->assertArrayHasKey('pur_price', $pur);
$this->assertArrayHasKey('pur_qte', $pur);
$this->assertArrayHasKey('pur_date', $pur);
}
}


0 comments on commit d1f30ad

Please sign in to comment.