framework/db/schema/CDbCommandBuilder.php
public function createSearchCondition($table,$columns,$keywords,$prefix=null,$caseSensitive=true)
	{
		$this->ensureTable($table);
		if(!is_array($keywords))
			$keywords=preg_split('/\s+/u',$keywords,-1,PREG_SPLIT_NO_EMPTY);
		if(empty($keywords))
			return '';
		if($prefix===null)
			$prefix=$table->rawName.'.';
		$conditions=array();
		foreach($columns as $name)
		{
			if(($column=$table->getColumn($name))===null)
				throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
					array('{table}'=>$table->name,'{column}'=>$name)));
			$condition=array();
			foreach($keywords as $keyword)
			{
				$keyword='%'.strtr($keyword,array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%';
				if($caseSensitive)
					$condition[]=$prefix.$column->rawName.' LIKE '.$this->_connection->quoteValue($keyword);
				else
					$condition[]='LOWER('.$prefix.$column->rawName.') LIKE LOWER('.$this->_connection->quoteValue($keyword).')';
			}
			$conditions[]=implode(' AND ',$condition);
		}
		return '('.implode(' OR ',$conditions).')';
	}
public function createSearchCondition($table,$columns,$keywords,$prefix=null,$caseSensitive=true)
	{
		$this->ensureTable($table);
		if(!is_array($keywords))
			$keywords=preg_split('/\s+/u',$keywords,-1,PREG_SPLIT_NO_EMPTY);
		if(empty($keywords))
			return '';
		if($prefix===null)
			$prefix=$table->rawName.'.';
		$conditions=array();
		foreach($columns as $name)
		{
			if(($column=$table->getColumn($name))===null)
				throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
					array('{table}'=>$table->name,'{column}'=>$name)));
			$condition=array();
			foreach($keywords as $keyword)
			{
				$keyword='%'.strtr($keyword,array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%';
				if($caseSensitive)
					$condition[]=$prefix.$column->rawName.' LIKE '.$this->_connection->quoteValue($keyword);
				else
					$condition[]='LOWER('.$prefix.$column->rawName.') LIKE LOWER('.$this->_connection->quoteValue($keyword).')';
			}
			$conditions[]=implode(' AND ',$condition);
		}
		return '('.implode(' OR ',$conditions).')';
	}
public function createSearchCondition ( $ table , $ columns , $ keywords , $ prefix = null , $ caseSensitive = true ) { $ this -> ensureTable ( $ table ) ; if ( ! is_array ( $ keywords ) ) $ keywords = preg_split ( '/\s+/u' , $ keywords , - 1 , PREG_SPLIT_NO_EMPTY ) ; if ( empty ( $ keywords ) ) return '' ; if ( $ prefix === null ) $ prefix = $ table -> rawName . '.' ; $ conditions = array ( ) ; foreach ( $ columns as $ name ) { if ( ( $ column = $ table -> getColumn ( $ name ) ) === null ) throw new CDbException ( Yii :: t ( 'yii' , 'Table "{table}" does not have a column named "{column}".' , array ( '{table}' => $ table -> name , '{column}' => $ name ) ) ) ; $ condition = array ( ) ; foreach ( $ keywords as $ keyword ) { $ keyword = '%' . strtr ( $ keyword , array ( '%' => '\%' , '_' => '\_' , '\\' => '\\\\' ) ) . '%' ; if ( $ caseSensitive ) $ condition [ ] = $ prefix . $ column -> rawName . ' LIKE ' . $ this -> _connection -> quoteValue ( $ keyword ) ; else $ condition [ ] = 'LOWER(' . $ prefix . $ column -> rawName . ') LIKE LOWER(' . $ this -> _connection -> quoteValue ( $ keyword ) . ')' ; } $ conditions [ ] = implode ( ' AND ' , $ condition ) ; } return '(' . implode ( ' OR ' , $ conditions ) . ')' ; }
Generates the expression for searching the specified keywords within a list of columns.
The search expression is generated using the 'LIKE' SQL syntax.
Every word in the keywords must be present and appear in at least one of the columns.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array $columns list of column names for potential search condition.
@param mixed $keywords search keywords. This can be either a string with space-separated keywords or an array of keywords.
@param string $prefix optional column prefix (with dot at the end). If null, the table name will be used as the prefix.
@param boolean $caseSensitive whether the search is case-sensitive. Defaults to true.
@throws CDbException if specified column is not found in given table
@return string SQL search condition matching on a set of columns. An empty string is returned
if either the column array or the keywords are empty.
Generates the expression for searching the specified keywords within a list of columns . The search expression is generated using the LIKE SQL syntax . Every word in the keywords must be present and appear in at least one of the columns .