<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(2); $v = new sfValidatorPass(); // ->clean() $t->diag('->clean()'); $t->is($v->clean(''), '', '->clean() always returns the value unmodified'); $t->is($v->clean(null), null, '->clean() always returns the value unmodified');
protected function processMmwExtJSFilters(array $requestParams, $q) { if (isset($requestParams['mmwExtJSFilters']) && ($filters = json_decode($requestParams['mmwExtJSFilters']))) { foreach ($filters as $filter) { // The obtained filter is a stdClass object. get_object_vars transforms it into an array. $filter = get_object_vars($filter); $fieldName = sfMmwExtjsUtil::getSfFieldNameFromExtjs($filter['field']); // Value validation switch ($filter['type']) { case 'numeric': $validator = new sfValidatorNumber(); break; case 'boolean': $validator = new sfValidatorBoolean(); break; case 'date': $validator = new sfValidatorDate(); break; case 'string': $validator = new sfValidatorString(); break; case 'list': $validator = new sfValidatorPass(); if (!is_array($filter['value']) || count($filter['value']) == 0) { break 2; } break; default: $validator = new sfValidatorPass(); break; } try { $value = $validator->clean($filter['value']); } catch (sfValidatorError $e) { break; } $rootAlias = $q->getRootAlias(); $query = $rootAlias . '.' . $fieldName; // Filter applying switch ($filter['type']) { case 'numeric': case 'date': switch ($filter['comparison']) { case 'lt': $query .= ' < "' . $value . '"'; break; case 'gt': $query .= ' > "' . $value . '"'; break; case 'eq': $query .= ' = "' . $value . '"'; break; default: break 2; } break; case 'boolean': $query .= ' = ' . $value; break; case 'string': $query .= ' LIKE "' . $value . '%"'; break; case 'list': $query .= ' IN ('; foreach ($value as $v) { $query .= '"' . $v . '"'; } $query .= ')'; break; default: $query .= ' = ' . $value; break; } $q->addWhere($query); } } }