Skip to content

Commit

Permalink
Merge pull request #243 from mattgu74/fix_semestre
Browse files Browse the repository at this point in the history
Gestion générique des semestres dans le module stats fix #180
  • Loading branch information
trecouvr committed Sep 21, 2013
2 parents 8d78722 + c443abe commit 760dfb9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/Payutc/Service/STATS.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,23 @@ public function getNbSell($obj_id, $fun_id, $start=null, $end=null, $tick=null)
* $top => (Récupére uniquement les X premiers) (par défaut 20)
* $by => "nbBuy" | "totalPrice"
*/
public function getRank($fun_id, $obj_id=null, $semestre="P13", $top=20, $sort_by="nbBuy") {
public function getRank($fun_id, $obj_id=null, $semestre="A13", $top=20, $sort_by="nbBuy") {
// Le client et l'user doivent avoir les droits stats !
$this->checkRight(true, true, true, $fun_id);

// Conversion de la période
// TODO: A l'avenir une table devrait nous permettre de lier les semestres a des plages de dates
switch($semestre) {
case "A12":
$start = "2012-08-01 00:00";
$end = "2013-02-01 00:00";
break;
case "P13":
$start = "2013-02-01 00:00";
$end = "2013-08-01 00:00";
break;
default:
throw new \Payutc\Exception\PayutcException("Période non reconnu !");
break;
preg_match("/[AP]\d{2}/", $semestre, $output);
if(count($output) != 1) {
throw new \Payutc\Exception\PayutcException("Période non reconnu !");
}

$year = intval($output[0][1] . $output[0][2]);

if($output[0][0] == 'A') {
$start = "20" . $year . "-08-01 00:00";
$end = "20" . $year . "-02-01 00:00";
} else {
$start = "20" . $year . "-02-01 00:00";
$end = "20" . ($year+1) . "-08-01 00:00";
}

return \Payutc\Bom\Purchase::getRank($fun_id, $obj_id, $start, $end, $top, $sort_by);
Expand Down
64 changes: 64 additions & 0 deletions tests/Payutc/Service/StatsRodbTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

require_once "ServiceBaseRodbTest.php";

use \Payutc\Bom\User;

class StatsRodbTest extends ServiceBaseRodbTest
{
public function getFixtures()
{
return array_merge(parent::getFixtures(), array(
'products.yml', 'purchase.yml'
));
}


/* ========== TEST DE GET NB SELL =============================== */

/**
* @requires PHP 5.4
*/
public function testGetNbSell()
{
$cookie = '';
$r = null;
$this->loginCas($cookie, $r, 'mguffroy@POSS3', 'POSS3');
$this->loginApp($cookie, $r, 'app_stats');
$r = httpSend('STATS', 'getNbSell', $cookie, array(
'obj_id' => '4',
'fun_id' => '1'
));
$this->assertEquals(200, $r->code);
$this->assertEquals(8, $r->body);
}


/* ========== TEST DE GETRANK =============================== */
/**
* @requires PHP 5.4
*/
public function testGetRank()
{
$cookie = '';
$r = null;
$this->loginCas($cookie, $r, 'mguffroy@POSS3', 'POSS3');
$this->loginApp($cookie, $r, 'app_stats');
$r = httpSend('STATS', 'getRank', $cookie, array(
'fun_id' => '1',
'semestre' => 'P13'
));
$this->assertEquals(200, $r->code);
$this->assertEquals(array(array(
'totalPrice' => 630,
'nbBuy' => 9,
'usr_firstname' => 'Matthieu',
'usr_lastname' => 'Guffroy',
'usr_nickname' => 'mguffroy'
)), $r->body);
}

}



4 changes: 4 additions & 0 deletions tests/seed/applicationright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ tj_app_fun_afu:
app_id: 1
fun_id: 1
afu_service: ADMINRIGHT
-
app_id: 3
fun_id: 1
afu_service: STATS
7 changes: 7 additions & 0 deletions tests/seed/applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ t_application_app:
app_creator: trecouvr
app_lastuse: 2012-01-01
app_created: 2012-01-01
-
app_id: 3
app_key: app_stats
app_name: app_stats
app_creator: mguffroy
app_lastuse: 2013-09-01
app_created: 2013-09-01

4 changes: 4 additions & 0 deletions tests/seed/fundationrights.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ tj_usr_fun_ufu:
usr_id: 1
fun_id: 1
ufu_service: ADMINRIGHT
-
usr_id: 9447
fun_id: 1
ufu_service: STATS

0 comments on commit 760dfb9

Please sign in to comment.