Skip to content

Commit

Permalink
making the filter work for the letter list, if one char is searched i…
Browse files Browse the repository at this point in the history
…t will look for Like x% not LIKE %x%
  • Loading branch information
dogmatic69 committed Jun 27, 2012
1 parent 7717abd commit 6ab7ba8
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Core/Filter/Controller/Component/FilterComponent.php
Expand Up @@ -15,7 +15,7 @@
* @subpackage app.controller.components
*/
App::uses('InfinitasComponent', 'Libs/Component');

class FilterComponent extends InfinitasComponent {
/**
* Fields which will replace the regular syntax in where i.e. field = 'value'
Expand Down Expand Up @@ -105,7 +105,7 @@ public function initialize($Controller) {
public function processAction($Controller, $controllerAction) {
if ($Controller->request->params['action'] == $controllerAction) {
$this->filter = $this->processFilters($Controller);

$this->_paginationRecall($Controller);
$url = (empty($this->url)) ? '/' : $this->url;

Expand Down Expand Up @@ -185,14 +185,14 @@ public function processFilters($controller, $whiteList = null) {
if(empty($data[$controller->{$controller->modelClass}->alias])) {
$data[$controller->{$controller->modelClass}->alias] = array();
}

$ret = array();
if (empty($controller->request->data)) {
$this->__checkRedirect();

return $ret;
}

foreach($data as $model => $fields) {
$modelFieldNames = array();
if (!empty($controller->{$model}) && $controller->{$model} instanceof Model) {
Expand All @@ -202,7 +202,7 @@ public function processFilters($controller, $whiteList = null) {
else if (isset($controller->{$controller->modelClass}->belongsTo[$model]) || isset($controller->{$controller->modelClass}->hasOne[$model])) {
$modelFieldNames = $controller->{$controller->modelClass}->{$model}->getColumnTypes();
}

if (!empty($modelFieldNames)) {
foreach($fields as $filteredFieldName => $filteredFieldData) {
if(isset($controller->{$model}) && $controller->{$model} instanceof Model && !$controller->{$model}->hasField($filteredFieldName)) {
Expand All @@ -220,7 +220,12 @@ public function processFilters($controller, $whiteList = null) {

if (isset($modelFieldNames[$filteredFieldName]) && isset($this->fieldFormatting[$modelFieldNames[$filteredFieldName]])) {
// insert value into fieldFormatting
$tmp = sprintf($this->fieldFormatting[$modelFieldNames[$filteredFieldName]], $filteredFieldData);
if($modelFieldNames[$filteredFieldName] == 'string' && strlen($filteredFieldData) == 1) {
$tmp = sprintf("LIKE '%s%%'", $filteredFieldData);
} else {
$tmp = sprintf($this->fieldFormatting[$modelFieldNames[$filteredFieldName]], $filteredFieldData);
}

// don't put key.fieldname as array key if a LIKE clause
if (substr($tmp, 0, 4) == 'LIKE') {
$ret[] = "{$model}.{$filteredFieldName} {$tmp}";
Expand Down Expand Up @@ -319,15 +324,15 @@ public function processFilters($controller, $whiteList = null) {
unset($controller->request->data[$model]);
}
}

$this->__checkRedirect();

return $ret;
}

/**
* If redirect has been set true, and the data had not been parsed before
* and put into the url, does it now
* If redirect has been set true, and the data had not been parsed before
* and put into the url, does it now
*/
private function __checkRedirect() {
if (!$this->parsed && $this->redirect) {
Expand Down

0 comments on commit 6ab7ba8

Please sign in to comment.