Created
August 9, 2013 21:15
-
-
Save gilsonbp/6197274 to your computer and use it in GitHub Desktop.
Método para transformar array de campos em uma condição SQL para busca do grid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
class Plugins_Campossearch extends Zend_Controller_Plugin_Abstract { | |
/** | |
* Converte um array em uma condição WHERE com OR e LIKE para uma busca no banco | |
* | |
* @param string $busca Valor buscado | |
* @param array $campos Array de campos para busca | |
* @param bolleam $where TRUE para inserir a tag WHERE e FALSE para não incluir | |
* @return string contendo uma condição WHERE com OR e LIKE | |
*/ | |
public function campossearch($busca, $campos = array(), $where = FALSE) { | |
if (!empty($campos)) { | |
$camposW = array(); | |
foreach ($campos as $campo) { | |
array_push($camposW, $campo . " LIKE '%$busca%'"); | |
} | |
if ($where) { | |
return 'WHERE ' . implode(' OR ', $camposW); | |
} else { | |
return '(' . implode(' OR ', $camposW) . ')'; | |
} | |
} else { | |
return ''; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment