issue #001391 : Ajout méthodes setLien, setLienRef et searchLienRef

This commit is contained in:
Michael RICOIS 2012-10-16 08:37:37 +00:00
parent 48fb99de55
commit 3f585797cf
5 changed files with 227 additions and 3 deletions

View File

@ -0,0 +1,5 @@
<?php
class Application_Model_JoLiens extends Zend_Db_Table_Abstract
{
protected $_name = 'liens';
}

View File

@ -0,0 +1,15 @@
<?php
class Application_Model_JoLiensRef extends Zend_Db_Table_Abstract
{
protected $_name = 'liensRef';
public function insert(array $data)
{
// Ajout d'un timestamp
if (empty($data['dateInsert'])) {
$data['dateInsert'] = date('YmdHis');
}
return parent::insert($data);
}
}

View File

@ -18,3 +18,4 @@ Type[] = "JalCollecte"
Type[] = "SupprAnnonceReturn" Type[] = "SupprAnnonceReturn"
Type[] = "DupliqueAnnonceReturn" Type[] = "DupliqueAnnonceReturn"
Type[] = "BilanInfos" Type[] = "BilanInfos"
Type[] = "SearchLienRef"

View File

@ -1583,19 +1583,211 @@ class Saisie extends WsScore
return $id; return $id;
} }
protected function setLien($infos, $action) /**
* Définition d'un lien
* @param string $infos
* @param string $id
* @throws SoapFault
* @return int
*/
public function setLien($infos, $id=null)
{ {
$this->authenticate(); $this->authenticate();
$data = json_decode($infos, true); $dataLien = json_decode($infos, true);
//Connect to the database
try {
$db = Zend_Db::factory($this->dbConfig->db->jo);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
} catch (Zend_Exception $e) {
throw new SoapFault('ERR', "Application error");
}
$lienM = new Application_Model_JoLiens($db);
//Enregistrer les infos //Enregistrer les infos
if ($id===null) {
try {
$id = $lienM->insert($dataLien);
} catch (Zend_Db_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
}
//Mise à jour des infos
else {
try {
$id = $lienM->update($dataLien, 'id = '.$id);
} catch (Zend_Db_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
}
// return $id;
}
/**
* Définition d'une fiche lien
* @param string $infos
* @param string $id
* @throws SoapFault
* @return int
*/
public function setLienRef($infos, $id=null)
{
$this->authenticate();
$dataRef = json_decode($infos, true);
//Connect to the database
try {
$db = Zend_Db::factory($this->dbConfig->db->jo);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
} catch (Zend_Exception $e) {
throw new SoapFault('ERR', "Application error");
}
$refM = new Application_Model_JoLiensRef($db);
//Check if exist
if (intval($dataRef['siren'])!=0) {
$sql = $refM->select()->from($refM, array('id'))->where('siren=?', $dataRef['siren']);
$rowset = $refM->fetchRow($sql);
if ( $rowset!==null ) {
return $rowset->id;
}
}
//Insert
if ($id===null) {
$dataRef = array_merge($dataRef, array('dateInsert'=>date('Ymd')));
try {
$id = $refM->insert($dataRef);
} catch (Zend_Db_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
}
//Update
else {
try {
$id = $refM->update($dataRef, 'id = '.$id);
} catch (Zend_Db_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
}
return $id;
}
/**
* Recherche de fiche lien dans le référentiel
* @param string $query
* @throws SoapFault
* @return SearchLienRef[]
*/
public function searchLienRef($query)
{
$this->authenticate();
//Connect to the database
try {
$db = Zend_Db::factory($this->dbConfig->db->jo);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
} catch (Zend_Exception $e) {
throw new SoapFault('ERR', "Application error");
}
$refM = new Application_Model_JoLiensRef($db);
$queries = explode(' ', $query);
$sql = $refM->select()->from($refM,array('id','siren', 'RS', 'nom', 'idLoc1Num'));
if (count($queries)>0) {
$where = '';
$i = 0;
foreach ($queries as $item) {
if (strlen($item)>2) {
$where = 'LIKE "%'.strtolower($item).'%"';
}
$i++;
if (count($queries) < $i){
$where.= ' OR ';
}
}
$sql->where("(siren ".$where.") OR (RS ".$where.") OR (nom ".$where.") OR (idLoc1Num ".$where.")");
}
try {
$result = $refM->fetchAll($sql, 20);
} catch (Zend_Db_Exception $e) {
if ($this->tabInfoUser['idClient']!=1) {
throw new SoapFault('ERR', "Application error");
} else {
throw new SoapFault('ERR', $e->getMessage());
}
}
$output = array();
if ($result->count()>0) {
foreach($result as $item) {
$tmp = new SearchLienRef();
$tmp->id = $item->id;
$itemsLib = array('siren', 'RS', 'nom', 'idLoc1Num');
$lib = '';
foreach($itemsLib as $value) {
if (!empty($item->$value)) {
$lib.= ' , '.$item->$value;
}
}
$tmp->lib = $lib;
$output[] = $tmp;
}
}
return $output;
} }
} }

View File

@ -302,3 +302,14 @@ class BilanInfos
public $postes; public $postes;
} }
class SearchLienRef
{
/** @var int */
public $id;
/** @var string */
public $lib;
}