This commit is contained in:
Aram HARUTYUNYAN 2013-11-20 08:36:52 +00:00
parent e0372ca5f0
commit b780a59f8b
7 changed files with 81 additions and 0 deletions

View File

@ -2211,4 +2211,29 @@ class SaisieController extends Zend_Controller_Action
$this->view->assign('message', $message);
$this->view->assign('refresh', $refresh);
}
public function citysearchAction()
{
$this->_helper->layout()->disableLayout();
$cp = $this->getRequest()->getParam('cp', null);
$output = array();
if ( null !== $cp && strlen($cp)<6) {
$city = new Application_Model_City();
$sql = $city->select('cp, commune');
$sql->where("cp LIKE '".$cp."%'");
$rows = $city->fetchAll($sql);
if ( count($rows)>0 ) {
foreach ($rows as $item) {
$output[] = array(
'label' => $item->cp.": ".$item->commune,
'value' => $item->cp,
);
}
}
}
$this->view->assign('output', $output);
}
}

View File

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

View File

@ -0,0 +1 @@
<?=json_encode($this->output)?>

View File

@ -92,6 +92,25 @@ $('input[name=naissance_date]').datepicker({ changeMonth: true, changeYear: true
</div>
</div>
<script>
$('input[name=adresse_cp]').autocomplete({
minLength: 4,
delay: 250,
source: function(request, response) {
var cp = $('input[name=adresse_cp]').val();
$.getJSON('<?=$this->url(array('controller'=>'saisie','action'=>'citysearch'),null,true)?>', { cp: cp },
function(data) { response(data); }
);
},
select: function( event, ui ) {
var value = ui.item.label;
value = value.replace(ui.item.value+': ','');
$('input[name=adresse_ville]').val(value);
$('select[name=adresse_pays]').val('FRA');
}
});
</script>
<div class="fieldgrp">
<label>Pays</label>
<div class="field">

View File

@ -280,6 +280,26 @@ class WsScores
}
}
}
public function getCatalogCity($id, $columns)
{
$params = new stdClass();
$params->id = $id;
$params->columns = $columns;
$client = $this->loadClient('catalog');
try {
$reponse = $client->getCity($params);
return $reponse->getCityResult;
} catch (SoapFault $fault) {
if ( in_array($fault->faultcode, array('ERR', 'MSG')) ){
return $fault->faultstring;
} else {
echo $client->__getLastResponse();
//$this->soaperror(__FUNCTION__, $fault, $client->__getLastRequest(), $client->__getLastResponse());
return false;
}
}
}
public function getCatalogLegalForm($id, $columns)
{

View File

@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS `tabVilles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cp` char(5) NOT NULL,
`commune` varchar(80) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM COMMENT='Codes Postales';

View File

@ -43,6 +43,11 @@ $catalogs = array(
'table' => 'tabFJur',
'method' => array('name'=>'getCatalogLegalForm', 'params'=> array( null , array('code', 'libelle', 'libelleEn') ))
),
'city' => array(
'sql' => 'tabVilles.sql',
'table' => 'tabVilles',
'method' => array('name'=>'getCatalogCity', 'params'=> array( null , array('cp', 'commune') ))
),
);
try {