Lissage complet des fonction getRapport/getIndiscoreé et getIndiscore

This commit is contained in:
Claire DELBOS 2017-03-14 14:06:31 +01:00
parent 770d6f3b16
commit 12dcdf4f57
9 changed files with 110 additions and 88 deletions

View File

@ -15,7 +15,7 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
public function __construct($db = null) public function __construct($db = null)
{ {
// Set Database // Set Database
if ($conn === null) { if ($this->conn === null) {
$this->conn = Zend_Registry::get('doctrine'); $this->conn = Zend_Registry::get('doctrine');
} else { } else {
$this->conn = $conn; $this->conn = $conn;
@ -23,7 +23,6 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
if (Zend_Registry::isRegistered('logger')) { if (Zend_Registry::isRegistered('logger')) {
$this->logger = Zend_Registry::get('logger'); $this->logger = Zend_Registry::get('logger');
$this->logger->info('Decrement');
} }
} }
public function canUse($idLog,$user){ public function canUse($idLog,$user){
@ -51,7 +50,7 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
'consumption' => $this->logCost, 'consumption' => $this->logCost,
'created' => Date('Y-m-d H:i:s'), 'created' => Date('Y-m-d H:i:s'),
); );
$this->conn->insert('sdv1.credit__consumption',$declog); $res=$this->conn->insert('sdv1.credit__consumption',$declog);
switch($this->rateType){ switch($this->rateType){
case 1: case 1:
$this->setBalance($user,''); $this->setBalance($user,'');
@ -61,6 +60,8 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
break; break;
} }
//$newbalance= //$newbalance=
$this->logger->info(var_export($res,true));
return true;
return $this->logCost.'--->'.$this->rateType; return $this->logCost.'--->'.$this->rateType;
} }
private function setBalance($user, $idLog){ private function setBalance($user, $idLog){
@ -118,7 +119,7 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
}else{ }else{
$this->rateType=0; $this->rateType=0;
$this->logCost=0; $this->logCost=0;
$this->logger->info(__LINE__ . 'getRateType KO'); $this->logger->info(__LINE__ . 'getRateType KO'.$idLog.'-'.$user->idClient);
} }
} }
private function sessionGetRateType(){ private function sessionGetRateType(){

View File

@ -75,6 +75,8 @@ class Scores_Ws_Server
protected $idLog = 'unknown'; protected $idLog = 'unknown';
protected $idMainLog = 'unknown';
/** /**
* Liste des permissions * Liste des permissions
* @var array * @var array
@ -383,10 +385,17 @@ class Scores_Ws_Server
$this->conn->insert('sdv1.logs', $dataInsert); $this->conn->insert('sdv1.logs', $dataInsert);
} catch (\Doctrine\DBAL\DBALException $e) { } catch (\Doctrine\DBAL\DBALException $e) {
} }
$this->decLog($this->idLog);
}
protected function decLog($idLog=null){
if($this->idMainLog=='getRapport' && $this->idLog!=$this->idMainLog){
return true;
}
$this->idLog=$idLog;
$crdt=new Metier_Credit_Decrement(); $crdt=new Metier_Credit_Decrement();
$ok=$crdt->setUsed($this->idLog,$this->User); $ok=$crdt->setUsed($this->idLog,$this->User);
} return $ok;
}
/** /**
* Authenticate with SoapHeader, Optional (Authentication could be done by sending HTTP Basic header - see the doc) * Authenticate with SoapHeader, Optional (Authentication could be done by sending HTTP Basic header - see the doc)
* @param string $username * @param string $username
@ -461,14 +470,8 @@ class Scores_Ws_Server
if (!$this->checkPerm($perm)) { if (!$this->checkPerm($perm)) {
$this->sendError('0902'); $this->sendError('0902');
} }
$this->sendError('0907'); if (!$this->checkCredit($idLog)) {
if(empty($idLog)){$idLog=$this->getIdLog();} $this->sendError('0907');
//if(empty($idLog)){$idLog=$this->idLog;;}
if(!empty($idLog)){
$this->idLog=$idLog;
if (!$this->checkCredit($idLog)) {
$this->sendError('0907');
}
} }
} }
@ -477,7 +480,17 @@ class Scores_Ws_Server
* @throws SoapFault * @throws SoapFault
*/ */
protected function checkCredit($idLog){ protected function checkCredit($idLog){
//$this->idLog=$this->getIdLog(); if(
$idLog=="getRapport"
|| $idLog=="getIndiScore2"
){
$this->idMainLog=$idLog;
}
if(empty($idLog)){$idLog=$this->getIdLog();}
//@todo:retirer la securite apres verif
if(!empty($idLog)){
$this->idLog=$idLog;
}
$crdt=new Metier_Credit_Decrement(); $crdt=new Metier_Credit_Decrement();
$ok=$crdt->canUse($idLog,$this->User); $ok=$crdt->canUse($idLog,$this->User);
return $ok->result; return $ok->result;
@ -572,7 +585,7 @@ class Scores_Ws_Server
$qb->select(array( $qb->select(array(
'u.login', 'u.id', 'u.email', 'u.password', 'u.idClient', 'u.typeCompte', 'u.actif', 'u.login', 'u.id', 'u.email', 'u.password', 'u.idClient', 'u.typeCompte', 'u.actif',
'u.filtre_ip', 'u.profil', 'u.civilite', 'u.nom', 'u.prenom', 'u.tel', 'u.fax', 'u.filtre_ip', 'u.profil', 'u.civilite', 'u.nom', 'u.prenom', 'u.tel', 'u.fax',
'u.mobile', 'u.pref', 'u.rechRefType', 'u.profil', 'u.nombreConnexions', 'u.mobile', 'u.pref', 'u.rechRefType', 'u.profil', 'u.nombreConnexions', 'u.siret',
'u.dateDerniereConnexion', 'u.droits', 'u.referenceParDefaut', 'u.nbReponses', 'u.lang', 'u.dateDerniereConnexion', 'u.droits', 'u.referenceParDefaut', 'u.nbReponses', 'u.lang',
'u.formatMail', 'u.dateDebutCompte', 'u.dateFinCompte', 'u.accesWS', 'u.acceptationCGU', 'u.formatMail', 'u.dateDebutCompte', 'u.dateFinCompte', 'u.accesWS', 'u.acceptationCGU',
'c.droits AS droitsClients', 'c.test AS clientTest', 'c.typeScore', 'c.timeout', 'c.droits AS droitsClients', 'c.test AS clientTest', 'c.typeScore', 'c.timeout',
@ -823,6 +836,7 @@ class Scores_Ws_Server
$this->User->dateFinCompte = $userInfos->dateFinCompte; $this->User->dateFinCompte = $userInfos->dateFinCompte;
$this->User->acceptationCGU = $userInfos->acceptationCGU; $this->User->acceptationCGU = $userInfos->acceptationCGU;
$this->User->version = $userInfos->version; $this->User->version = $userInfos->version;
$this->User->siret = isset($userInfos->siret)?$userInfos->siret:0;
return true; return true;
} }
@ -920,6 +934,7 @@ class Scores_Ws_Server
$this->User->dateFinCompte = $userInfos->dateFinCompte; $this->User->dateFinCompte = $userInfos->dateFinCompte;
$this->User->acceptationCGU = $userInfos->acceptationCGU; $this->User->acceptationCGU = $userInfos->acceptationCGU;
$this->User->version = $userInfos->version; $this->User->version = $userInfos->version;
$this->User->siret = isset($userInfos->siret)?$userInfos->siret:0;
// Add Service Parameter to user definition // Add Service Parameter to user definition
$this->User->typeScore = $result->TypeScore; $this->User->typeScore = $result->TypeScore;

View File

@ -1,7 +1,7 @@
<?php <?php
return array( return array(
'GetCredit' => 'GetCredit', 'GetCredit' => 'GetCredit',
'infoCredit' => 'infoCredit', 'InfoCredit' => 'InfoCredit',
'PayCredit' => 'PayCredit', 'PayCredit' => 'PayCredit',
'CanUse' => 'CanUse', 'UseCredit' => 'UseCredit',
); );

View File

@ -77,13 +77,15 @@ class Credit extends Scores_Ws_Server
$stmt->execute(); $stmt->execute();
$info->paid=$stmt->fetchAll(\PDO::FETCH_ASSOC); $info->paid=$stmt->fetchAll(\PDO::FETCH_ASSOC);
$sql = "SELECT * FROM sdv1.credit__consumption c $sql = "SELECT * FROM sdv1.credit__consumption c
WHERE c.idUser=:idUser order by id desc limit 20"; inner join credit__rate r on c.idLog=r.idLog
WHERE c.idUser=:idUser and r.idClient=:idClient order by c.id desc limit 20";
$stmt = $this->conn->prepare($sql); $stmt = $this->conn->prepare($sql);
$stmt->bindValue('idUser', $idUser); $stmt->bindValue('idUser', $idUser);
$stmt->bindValue('idClient', $this->User->idClient);
$stmt->execute(); $stmt->execute();
$info->used=$stmt->fetchAll(\PDO::FETCH_ASSOC); $info->used=$stmt->fetchAll(\PDO::FETCH_ASSOC);
$this->wsLog(__FUNCTION__,$siret,$id); $this->wsLog(__FUNCTION__,$idUser,'0');
return $info; return $info;
} }
@ -95,7 +97,7 @@ class Credit extends Scores_Ws_Server
public function payCredit($ligneCredit='') public function payCredit($ligneCredit='')
{ {
$this->authenticate(); $this->authenticate();
$this->permission($this->libdroits); $this->permission($this->libdroits,__FUNCTION__);
$PayCreditResult=new PayCredit(); $PayCreditResult=new PayCredit();
$ir=(array)json_decode($ligneCredit); $ir=(array)json_decode($ligneCredit);
$tab=explode('ww',$ir['idCmd']); $tab=explode('ww',$ir['idCmd']);
@ -170,41 +172,37 @@ class Credit extends Scores_Ws_Server
return $PayCreditResult; return $PayCreditResult;
} }
/**
* Decrement sur cache Extranet
* @param string idLog
* @return UseCredit
*/
public function useCredit($idLog)
{
$UseCreditResult=new UseCredit();
$UseCreditResult->idLog=$idLog;
$this->authenticate();
$idUser = $this->User->id;
$this->logger->info('idUser : '.$this->User->id.'idLog : '.$idLog);
//$this->permission($this->libdroits);
$this->decLog($idLog);
$UseCreditResult->result=true;
return $UseCreditResult;
}
/** /**
* Vérifie le droit de consommer une page * Vérifie le droit de consommer une page
* @param string idLog * @param string idLog
* @return CanUse * @return CanUse
*/
public function canUse($idLog)
{
$this->authenticate();
$idUser = $this->User->id;
$myRights=new \Metier_Credit_Decrement();
/*test de la librairie pour auth
$ok=$myRights->canUse('synthese',$this->User);
throw(new SoapFault('MSG', 'canUse : '.__LINE__ . var_export($ok,true)));
$canUseResult=$ok;
*/
/*test de la librairie pour dec*/
$ok=$myRights->setUsed('synthese',$this->User);
throw(new SoapFault('MSG', 'canUse : '.__LINE__ . var_export($ok,true)));
$canUseResult=$ok;
public function canUseByCredit($idLog)
return $canUseResult;
}
/**
* Ajoute des crédits supplémentaires à un utilisateur
* @param $nbCredit
public function addCredit($nbCredit)
{ {
$this->authenticate(); $this->authenticate();
$this->permission('addcredit');
$this->updateCredit($this->User->idClient, $this->User->login, $nbCredit); $idUser = $this->User->id;
$canUseResult=$this->checkCredit($idLog);
$this->wsLog('addcredit', $this->User->idClient, $nbCredit); return $canUseResult;
} }
/** /**

View File

@ -40,37 +40,19 @@ class PayCredit
*/ */
public $ligneCredit; public $ligneCredit;
} }
class CanUse
class UseCredit
{ {
/**
* Identifiant de log service
* @var string
*/
public $idLog;
/** /**
* Success or failed * Success or failed
* @var boolean * @var boolean
*/ */
public $result; public $result;
/** /**
* Type de fonctionnement des credits * Params sent
* @var int * @var string
*/ */
public $typecredit; public $idLog;
} }
class AddCredit
{
}
class SubCredit
{
}
class UpdateCredit
{
}

View File

@ -1556,12 +1556,21 @@ class Entreprise extends Scores_Ws_Server
$perm = false; $perm = false;
//@todo : Gestion des droits //@todo : Gestion des droits
switch($niveau){ switch($niveau){
case 3: $perms = array('indiscore3', 'indiscore3p'); break; case 3:
case 2: $perms = array('indiscore2', 'indiscore2p', 'indiscore3', 'indiscore3p'); break; $perms = array('indiscore3', 'indiscore3p');
case 1: $perms = array('indiscore', 'indiscorep'); break; $idLog='getReportSynthese';
break;
case 2:
$perms = array('indiscore2', 'indiscore2p', 'indiscore3', 'indiscore3p');
$idLog='getReportSynthese';
break;
case 1:
$perms = array('indiscore', 'indiscorep');
$idLog='getIndiScore';
break;
} }
foreach($perms as $item){ foreach($perms as $item){
if ( $this->checkPerm($item,'get'.ucfirst($item)) ){ if ( $this->checkPerm($item, $idLog) ){
$perm = true; $perm = true;
break; break;
} }
@ -1782,6 +1791,7 @@ class Entreprise extends Scores_Ws_Server
$this->wsLog('indiscore+',$siren); $this->wsLog('indiscore+',$siren);
} else } else
$this->wsLog('indiscore',$siren); $this->wsLog('indiscore',$siren);
//$this->decLog($idLog);
return $output; return $output;
} }
@ -3346,6 +3356,7 @@ class Entreprise extends Scores_Ws_Server
} }
$this->wsLog('bilan',$siren, $millesime.':'.$typeBilan.':'.$ref); $this->wsLog('bilan',$siren, $millesime.':'.$typeBilan.':'.$ref);
$resultBilan->POSTES = $tabPoste; $resultBilan->POSTES = $tabPoste;
$this->decLog('getBilan');
return $resultBilan; return $resultBilan;
} }
@ -3745,6 +3756,7 @@ class Entreprise extends Scores_Ws_Server
public function getRapport($siren, $niveau=3, $id=0, $plus=false, $ref='', $encours=0, $email='') public function getRapport($siren, $niveau=3, $id=0, $plus=false, $ref='', $encours=0, $email='')
{ {
$this->authenticate(); $this->authenticate();
$this->checkCredit(__FUNCTION__);
if (empty($niveau)) $niveau = 3; if (empty($niveau)) $niveau = 3;
if (empty($id)) $id = 0; if (empty($id)) $id = 0;
$result = new Rapport(); $result = new Rapport();
@ -3759,7 +3771,7 @@ class Entreprise extends Scores_Ws_Server
case 3: $perms = array('indiscore3', 'indiscore3p'); break; case 3: $perms = array('indiscore3', 'indiscore3p'); break;
} }
foreach($perms as $item){ foreach($perms as $item){
if ( $this->checkPerm($item,__FUNCTION__) ){ if ( $this->checkPerm($item) ){
$perm = true; $perm = true;
break; break;
} }

View File

@ -283,7 +283,7 @@ class Entreprise extends Scores_Ws_Server
public function getAvisRncs($siren) public function getAvisRncs($siren)
{ {
$this->authenticate(); $this->authenticate();
$this->permission('avisrncs'); $this->permission('avisrncs',__FUNCTION__);
$len = strlen($siren); $len = strlen($siren);
if ( $len != 9 ) { if ( $len != 9 ) {
@ -1043,7 +1043,7 @@ class Entreprise extends Scores_Ws_Server
public function getLiensById($id, $type = null) public function getLiensById($id, $type = null)
{ {
$this->authenticate(); $this->authenticate();
$this->permission('liens'); $this->permission('liens',__FUNCTION__);
try { try {
$countryM = new Application_Model_JoTabPays(); $countryM = new Application_Model_JoTabPays();
@ -2238,12 +2238,24 @@ class Entreprise extends Scores_Ws_Server
$perm = false; $perm = false;
//@todo : Gestion des droits //@todo : Gestion des droits
switch($niveau){ switch($niveau){
case 3: $perms = array('indiscore3', 'indiscore3p'); break; case 3:
case 2: $perms = array('indiscore2', 'indiscore2p', 'indiscore3', 'indiscore3p'); break; $perms = array('indiscore3', 'indiscore3p');
case 1: $perms = array('indiscore', 'indiscorep'); break; $idLog='getReportSynthese';
break;
case 2:
$perms = array('indiscore2', 'indiscore2p', 'indiscore3', 'indiscore3p');
$idLog='getRapport';
break;
case 1:
$perms = array('indiscore', 'indiscorep');
$idLog='getIndiScore';
break;
default:
$idLog='getIndiScore';
break;
} }
foreach($perms as $item){ foreach($perms as $item){
if ( $this->checkPerm($item, __FUNCTION__) ){ if ( $this->checkPerm($item) ){
$perm = true; $perm = true;
break; break;
} }
@ -2251,7 +2263,7 @@ class Entreprise extends Scores_Ws_Server
if ($perm === false) { if ($perm === false) {
$this->sendError('0902'); $this->sendError('0902');
} }
$this->checkCredit($idLog);
$tabRet = array(); $tabRet = array();
$this->logger->info("IndiScore demandée pour $siren en niveau $niveau"); $this->logger->info("IndiScore demandée pour $siren en niveau $niveau");
if (strlen($siren) > 9 || (substr($siren,0,9)*1) < 100 ){ if (strlen($siren) > 9 || (substr($siren,0,9)*1) < 100 ){
@ -2473,7 +2485,6 @@ class Entreprise extends Scores_Ws_Server
} else { } else {
$this->wsLog('indiscore',$siren); $this->wsLog('indiscore',$siren);
} }
return $output; return $output;
} }
@ -2487,7 +2498,7 @@ class Entreprise extends Scores_Ws_Server
public function getValo($siren, $nic=0, $niveau=2) public function getValo($siren, $nic=0, $niveau=2)
{ {
$this->authenticate(); $this->authenticate();
$this->permission('VALORISATION'); $this->permission('VALORISATION',__FUNCTION__);
//Initialisation //Initialisation
$accesPartenaire = true; $accesPartenaire = true;
@ -4574,7 +4585,7 @@ class Entreprise extends Scores_Ws_Server
public function getRatios($siren, $page='ratios') public function getRatios($siren, $page='ratios')
{ {
$this->authenticate(); $this->authenticate();
$this->permission('ratios',__FUNCTION__); $this->permission('ratios','get'.ucfirst($page));
//Initialisation //Initialisation
if (empty($page)) $page = 'ratios'; if (empty($page)) $page = 'ratios';
@ -4847,6 +4858,7 @@ class Entreprise extends Scores_Ws_Server
public function getRapport($siren, $niveau=3, $id=0, $plus=false, $ref='', $encours=0, $email='') public function getRapport($siren, $niveau=3, $id=0, $plus=false, $ref='', $encours=0, $email='')
{ {
$this->authenticate(); $this->authenticate();
$this->checkCredit(__FUNCTION__.'cd');
if (empty($niveau)) $niveau = 3; if (empty($niveau)) $niveau = 3;
if (empty($id)) $id = 0; if (empty($id)) $id = 0;
$result = new Rapport(); $result = new Rapport();
@ -4861,7 +4873,7 @@ class Entreprise extends Scores_Ws_Server
case 3: $perms = array('indiscore3', 'indiscore3p'); break; case 3: $perms = array('indiscore3', 'indiscore3p'); break;
} }
foreach($perms as $item){ foreach($perms as $item){
if ( $this->checkPerm($item, __FUNCTION__) ){ if ( $this->checkPerm($item) ){
$perm = true; $perm = true;
break; break;
} }

View File

@ -1268,7 +1268,7 @@ class Entreprise extends Scores_Ws_Server
$output = new Indiscore(); $output = new Indiscore();
$output = $this->formatIndiscore($indiscoreStruct); $output = $this->formatIndiscore($indiscoreStruct);
$this->decLog(__FUNCTION__);
return $output; return $output;
} }
@ -1291,6 +1291,7 @@ class Entreprise extends Scores_Ws_Server
$indiscoreStruct = $scoring->calculIndiScore($siren); $indiscoreStruct = $scoring->calculIndiScore($siren);
//$ratiosStruct = $this->getRatios($siren); //$ratiosStruct = $this->getRatios($siren);
$this->decLog(__FUNCTION__);
} }

View File

@ -16,4 +16,5 @@ if (APPLICATION_ENV == 'development'){
// --- Create application, bootstrap, and run // --- Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run(); $application->bootstrap()->run();