diff --git a/library/WsScore/Entreprise/v0.9/Service.php b/library/WsScore/Entreprise/v0.9/Service.php index c673ba82..8fced21b 100644 --- a/library/WsScore/Entreprise/v0.9/Service.php +++ b/library/WsScore/Entreprise/v0.9/Service.php @@ -829,29 +829,32 @@ class Entreprise extends Scores_Ws_Server $tiers = 'DE'; } - $db = Zend_Db_Table_Abstract::getDefaultAdapter(); - // --- Recherche de tiers (type DE ou DF) apparaissant dans les affaires - $tierSql = "SELECT count(idAffaire) AS Nb FROM jo.greffes_affaires_siren " . - "WHERE entSiren=".$companyId." AND qualite='".$tiers."'"; try { - $tierResult = $db->fetchRow($tierSql, null, Zend_DB::FETCH_OBJ); - } catch (Zend_Db_Exception $e) { - if ($this->User->idClient==1) { + $sql = "SELECT count(idAffaire) AS Nb FROM jo.greffes_affaires_siren + WHERE entSiren=:siren AND qualite=:qualite"; + $stmt = $this->conn->prepare($sql); + $stmt->bindValue('siren', $companyId); + $stmt->bindValue('qualite', $tiers); + $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"); } } - $totalNb = 0; - if ($tierResult !== null) { - $totalNb = $tierResult->Nb; - } + + $tierResult = $stmt->fetch(\PDO::FETCH_OBJ); + $totalNb = $tierResult->Nb; $output = new GreffeAffaireList(); $output->Nb = $totalNb; - if (count($totalNb) > 0) { + if ($totalNb > 0) { // --- Selection des affaires $tierSubQuery = "SELECT idAffaire FROM jo.greffes_affaires_siren " . "WHERE entSiren=".$companyId." AND qualite='".$tiers."' GROUP BY idAffaire"; @@ -866,13 +869,32 @@ class Entreprise extends Scores_Ws_Server throw new SoapFault('ERR', "Application error"); } } + try { + $tierSubQuery = "SELECT idAffaire FROM jo.greffes_affaires_siren + WHERE entSiren=:siren AND qualite=:qualite GROUP BY idAffaire"; + $affaireSql = "SELECT id, idAffaire, numGreffe, natureDemande, codNatureDemande, etatAffaire, dateEnrolement FROM jo.greffes_affaires + WHERE idAffaire IN (".$tierSubQuery.") ORDER BY dateEnrolement DESC LIMIT $p,$limit"; + $stmt = $this->conn->prepare($affaireSql); + $stmt->bindValue('siren', $companyId); + $stmt->bindValue('qualite', $tiers); + $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"); + } + } $status = include APPLICATION_PATH . '/../library/Metier/Ctx/AffaireStatus.php'; $categories = include APPLICATION_PATH . '/../library/Metier/Table/AffairesTypes.php'; $affaireList = array(); - if (count($affaireResult) > 0) { - foreach ($affaireResult as $a) { + if ($stmt->rowCount() > 0) { + while ($a = $stmt->fetch(\PDO::FETCH_OBJ)) { // --- Formattage $item = new GreffeAffaire(); @@ -896,18 +918,25 @@ class Entreprise extends Scores_Ws_Server } elseif ($tiers == 'DF') { $tiersQualite = 'DE'; } - $tierSql = "SELECT nomPartie FROM jo.greffes_affaires_siren WHERE idAffaire='".$a->idAffaire."' AND qualite='".$tiersQualite."'"; try { - $tierResult = $db->fetchAll($tierSql, null, Zend_DB::FETCH_OBJ); - } catch (Zend_Db_Exception $e) { - if ($this->User->idClient==1) { + $sql = "SELECT nomPartie FROM jo.greffes_affaires_siren WHERE idAffaire=:id AND qualite=:qualite"; + $tierStmt = $this->conn->prepare($sql); + $tierStmt->bindValue('id', $a->idAffaire); + $tierStmt->bindValue('qualite', $tiers); + $tierStmt->execute(); + } catch(\Doctrine\DBAL\DBALException $e) { + if ($this->logger !== null) { + $this->logger->error($e->getMessage()); + } + if ($this->User->idClient == 1) { throw new SoapFault('ERR', $tierSql . " - " . $e->getMessage()); } else { throw new SoapFault('ERR', "Application error"); } } - if (count($tierResult) > 0) { - foreach ($tierResult as $t) { + + if ($tierStmt->rowCount() > 0) { + while ($t = $tierStmt->fetch(\PDO::FETCH_OBJ)) { $item->TierName[] = $t->nomPartie; } }