Entreprise - getSubventionList : remove Zend_Db

This commit is contained in:
Michael RICOIS 2017-03-15 15:58:25 +01:00
parent 75b9abeda8
commit 9f04226286

View File

@ -2099,14 +2099,19 @@ class Entreprise extends Scores_Ws_Server
$entites[] = $entite; $entites[] = $entite;
//Search titulaire //Search titulaire
$boamplotsM = new Application_Model_JoBoampLots(); try {
$sql = $boamplotsM->select()->from($boamplotsM, array( $sql = "SELECT LPAD(siren, 9, 000000000) AS siren, LPAD(nic, 5, 00000) AS nic, nom, adresse, cp, ville, pays
'LPAD(siren, 9, 000000000) AS siren', FROM jo.boamp_lots WHERE idAnn=:id";
'LPAD(nic, 5, 00000) AS nic', 'nom','adresse','cp', 'ville', 'pays') $stmt = $this->conn->prepare($sql);
)->where('idAnn=?', substr($ann['id'],2)); $stmt->bindValue('id', substr($ann['id'],2));
$result = $boamplotsM->fetchAll($sql); $stmt->execute();
if (count($result) > 0) { } catch(\Doctrine\DBAL\DBALException $e) {
foreach ($result as $entity) { if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
}
if ($stmt->rowCount() > 0) {
while ($entity = $stmt->fetch(\PDO::FETCH_OBJ)) {
$entite = new AnnonceEntite(); $entite = new AnnonceEntite();
$entite->siret = $entity->siren.$entity->nic; $entite->siret = $entity->siren.$entity->nic;
$entite->raisonSociale = $entity->nom; $entite->raisonSociale = $entity->nom;
@ -5338,7 +5343,7 @@ class Entreprise extends Scores_Ws_Server
{ {
$this->authenticate(); $this->authenticate();
//Init // Init
if ( intval($companyId) == 0 ) { if ( intval($companyId) == 0 ) {
$this->sendError('1010'); $this->sendError('1010');
} elseif ( strlen($companyId)!=9 ) { } elseif ( strlen($companyId)!=9 ) {
@ -5348,77 +5353,94 @@ class Entreprise extends Scores_Ws_Server
if ( empty($nbItems) || $nbItems > 100 ) { $nbItems = 100; } if ( empty($nbItems) || $nbItems > 100 ) { $nbItems = 100; }
if ( !empty($type) ) { $type = strtoupper($type); } if ( !empty($type) ) { $type = strtoupper($type); }
//SQL // SQL
$listM = new Application_Model_JoAssoSubventions(); $qbList = $this->conn->createQueryBuilder();
$countsql = $listM->select()->from($listM, array('COUNT(*) AS num')); $qbCount = $this->conn->createQueryBuilder();
$sql = $listM->select()->from($listM, array( $qbList->select(array(
'id', 'id',
'millesime', //Annee 'millesime', //Annee
'sirenAsso', //sirenIn 'sirenAsso', //sirenIn
'nomAsso', 'nomAsso',
'sirenOrigine', //sirenOut 'sirenOrigine', //sirenOut
'libOrigine', //Origine 'libOrigine', //Origine
'libImputation', //Programme 'libImputation', //Programme
'mtSubvention', //Montant 'mtSubvention', //Montant
)); ))->from(jo.asso_subventions);
$qbCount->select('COUNT(*) AS num')->from('jo.asso_subventions');
//Subvention reçues => sirenAsso = companyId // Subvention reçues => sirenAsso = companyId
if ($type == 'IN') { if ($type == 'IN') {
$sql->where('sirenAsso=?', $companyId); $qbList->where('sirenAsso=:companyId')->setParameter('companyId', $companyId);
$countsql->where('sirenAsso=?', $companyId); $qbCount->where('sirenAsso=:companyId')->setParameter('companyId', $companyId);
} }
//Subvention reçues => sirenOrigine = companyId // Subvention reçues => sirenOrigine = companyId
elseif ($type == 'OUT') { elseif ($type == 'OUT') {
$sql->where('sirenOrigine=?', $companyId); $qbList->where('sirenOrigine=:companyId')->setParameter('companyId', $companyId);
$countsql->where('sirenOrigine=?', $companyId); $qbCount->where('sirenOrigine=:companyId')->setParameter('companyId', $companyId);
} }
//All // All
else { else {
$sql->where('sirenAsso=?', $companyId) $qbList->where('sirenAsso=:companyId')->orWhere('sirenOrigine=:companyId')->setParameter('companyId', $companyId);
->orWhere('sirenOrigine=?', $companyId); $qbCount->where('sirenAsso=:companyId')->orWhere('sirenOrigine=:companyId')->setParameter('companyId', $companyId);
$countsql->where('sirenAsso=?', $companyId)
->orWhere('sirenOrigine=?', $companyId);
} }
$sql->order('millesime DESC')->limit($nbItems, $offset); $qbList->orderBy('millesime DESC')->setFirstResult($offset)->setMaxResults($nbItems);
$count = $listM->fetchRow($countsql); try {
$nbReponsesTotal = 0; $stmt = $qbCount->execute();
if ( $count!==null ) { } catch(\Doctrine\DBAL\DBALException $e) {
$nbReponsesTotal = $count->num; if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
} }
if ( $nbReponsesTotal != 0 ) { $count = $stmt->fetch(\PDO::FETCH_OBJ);
$nbReponsesTotal = $count->num;
$rows = $listM->fetchAll($sql); if ($nbReponsesTotal > 0) {
try {
$stmt = $qbList->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
$output = new SubventionList(); $output = new SubventionList();
$output->nbReponsesTotal = $nbReponsesTotal; $output->nbReponsesTotal = $nbReponsesTotal;
$result = array(); $result = array();
if ( $rows !== null ) { while ($row = $stmt->fetch(\PDO::FETCH_OBJ)) {
foreach ( $rows as $row ) { $item = new Subvention();
$item->Id = $row->id;
$item = new Subvention(); if ( $row->sirenAsso == $companyId ) {
$item->Id = $row->id; $item->Type = 'IN';
if ( $row->sirenAsso == $companyId ) { } elseif ( $row->sirenOrigine == $companyId ) {
$item->Type = 'IN'; $item->Type = 'OUT';
} elseif ( $row->sirenOrigine == $companyId ) {
$item->Type = 'OUT';
}
$item->Millesime = $row->millesime;
$item->AssoSiren = $row->sirenAsso;
$item->AssoNom = $row->nomAsso;
$item->OrigineSiren = $row->sirenOrigine;
$item->OrigineLib = $row->libOrigine;
$item->Programme = $row->libImputation;
$item->Montant = $row->mtSubvention;
$result[] = $item;
} }
$output->result = $result; $item->Millesime = $row->millesime;
$this->wsLog('subventionlist', $companyId); $item->AssoSiren = $row->sirenAsso;
$item->AssoNom = $row->nomAsso;
$item->OrigineSiren = $row->sirenOrigine;
$item->OrigineLib = $row->libOrigine;
$item->Programme = $row->libImputation;
$item->Montant = $row->mtSubvention;
$result[] = $item;
} }
$output->result = $result;
$this->wsLog('subventionlist', $companyId);
} }
return $output; return $output;
@ -5434,14 +5456,27 @@ class Entreprise extends Scores_Ws_Server
{ {
$this->authenticate(); $this->authenticate();
$subventionM = new Application_Model_JoAssoSubventions(); try {
$row = $subventionM->find($id); $sql = "SELECT * FROM jo.asso_subventions WHERE id=:id";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('id', $id);
$stmt->execute();
} catch(\Doctrine\DBAL\DBALException $e) {
if ($this->logger !== null) {
$this->logger->error($e->getMessage());
}
if ($this->User->idClient == 1) {
throw new SoapFault('ERR', $e->getMessage());
} else {
throw new SoapFault('ERR', "Application error");
}
}
if (null === row) { if ($stmt->rowCount() == 0) {
throw new SoapFault('MSG', "Aucun résultat"); throw new SoapFault('MSG', "Aucun résultat");
} }
$data = $row->current(); $data = $stmt->fetch(\PDO::FETCH_OBJ);
$item = new SubventionDetail(); $item = new SubventionDetail();
$item->Millesime = $data->millesime; $item->Millesime = $data->millesime;