issue #0000106 : Use the new table and enhance search method

This commit is contained in:
Michael RICOIS 2013-03-12 14:39:22 +00:00
parent 964159ea84
commit 94092139e5
3 changed files with 45 additions and 22 deletions

View File

@ -786,29 +786,51 @@ class RechercheController extends Zend_Controller_Action
public function nafAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$q = strtolower($this->getRequest()->getParam('q', ''));
$naf = new Application_Model_Naf5();
$rowset = $naf->select('codNaf5, libNaf5')
->where("codNaf5 LIKE '%$q%' OR libNaf5 LIKE '%$q%'")
->order('poids DESC');
$rows = $naf->fetchAll($rowset);
$q = strtolower($this->getRequest()->getParam('q', null));
$output = array();
if (count($rows)>0){
$separator = " , ";
foreach ($rows as $item) {
if (strpos(strtolower($item->codNaf5), $q) !== false ||
strpos(strtolower($item->libNaf5), $q) !== false )
{
$output[] = array(
'label' => $item->codNaf5 . $separator . $item->libNaf5,
'value' => $item->codNaf5,
);
}
}
}
echo json_encode($output);
if ( null !== $q ) {
$naf = new Application_Model_Naf5();
$sql = $naf->select('codNaf5, libNaf5');
if ( is_numeric(substr($q,0,4)) ) {
$sql->where("codNaf5 LIKE '%".$q."%'");
} else {
$queries = explode(' ', $q);
if (count($queries)>0) {
$where = '';
$i = 0;
foreach ($queries as $item) {
$i++;
if (empty($where)) {
$op = 'LIKE ';
} elseif ($i < count($queries)) {
$op = ' OR ';
}
if (strlen($item)>2) {
$where.= $op.'"%'.strtolower($item).'%"';
}
}
$sql->where("LOWER(libNaf5) ".$where);
}
}
$rows = $naf->fetchAll($sql);
if ( count($rows)>0 ) {
$separator = " , ";
foreach ($rows as $item) {
if (strpos(strtolower($item->codNaf5), $q) !== false ||
strpos(strtolower($item->libNaf5), $q) !== false ) {
$output[] = array(
'label' => $item->codNaf5 . $separator . $item->libNaf5,
'value' => $item->codNaf5,
);
}
}
}
}
$this->view->assign('output', $output);
}
public function refclientAction()

View File

@ -1,6 +1,6 @@
<?php
class Application_Model_Naf5 extends Zend_Db_Table_Abstract
{
protected $_name = 'tabnaf5';
protected $_name = 'tabnaf5tmp';
}

View File

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