issue #0000106 : Use the new table and enhance search method
This commit is contained in:
parent
964159ea84
commit
94092139e5
@ -786,21 +786,41 @@ class RechercheController extends Zend_Controller_Action
|
|||||||
public function nafAction()
|
public function nafAction()
|
||||||
{
|
{
|
||||||
$this->_helper->layout()->disableLayout();
|
$this->_helper->layout()->disableLayout();
|
||||||
$this->_helper->viewRenderer->setNoRender(true);
|
|
||||||
|
|
||||||
$q = strtolower($this->getRequest()->getParam('q', ''));
|
$q = strtolower($this->getRequest()->getParam('q', null));
|
||||||
$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);
|
|
||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
|
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 ) {
|
if ( count($rows)>0 ) {
|
||||||
$separator = " , ";
|
$separator = " , ";
|
||||||
foreach ($rows as $item) {
|
foreach ($rows as $item) {
|
||||||
if (strpos(strtolower($item->codNaf5), $q) !== false ||
|
if (strpos(strtolower($item->codNaf5), $q) !== false ||
|
||||||
strpos(strtolower($item->libNaf5), $q) !== false )
|
strpos(strtolower($item->libNaf5), $q) !== false ) {
|
||||||
{
|
|
||||||
$output[] = array(
|
$output[] = array(
|
||||||
'label' => $item->codNaf5 . $separator . $item->libNaf5,
|
'label' => $item->codNaf5 . $separator . $item->libNaf5,
|
||||||
'value' => $item->codNaf5,
|
'value' => $item->codNaf5,
|
||||||
@ -808,7 +828,9 @@ class RechercheController extends Zend_Controller_Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo json_encode($output);
|
}
|
||||||
|
|
||||||
|
$this->view->assign('output', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refclientAction()
|
public function refclientAction()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
class Application_Model_Naf5 extends Zend_Db_Table_Abstract
|
class Application_Model_Naf5 extends Zend_Db_Table_Abstract
|
||||||
{
|
{
|
||||||
protected $_name = 'tabnaf5';
|
protected $_name = 'tabnaf5tmp';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
application/views/default/scripts/recherche/naf.phtml
Normal file
1
application/views/default/scripts/recherche/naf.phtml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?=json_encode($this->output)?>
|
Loading…
Reference in New Issue
Block a user