[eluser]xwero[/eluser]
Great, i didn't know about the set method but once it is available i'm going to use this nice addition.
Another small addition in the AR class would be selecting the wildcard position for the like method; both (default), left, right
Code:
/**
* Like
*
* Generates a &#xLI;KE% portion of the query. Separates
* multiple calls with AND
*
* @access public
* @param mixed
* @param mixed
* @return object
*/
function like($field, $match = '',$wildcard = 'both') // changed
{
return $this->_like($field, $match, 'AND ', $wildcard);
}
// --------------------------------------------------------------------
/**
* OR Like
*
* Generates a &#xLI;KE% portion of the query. Separates
* multiple calls with OR
*
* @access public
* @param mixed
* @param mixed
* @return object
*/
function orlike($field, $match = '',$wildcard = 'both') // changed
{
return $this->_like($field, $match, 'OR ',$wildcard); // changed
}
// --------------------------------------------------------------------
/**
* Like
*
* Called by like() or orlike()
*
* @access private
* @param mixed
* @param mixed
* @param string
@param string
* @return object
*/
function _like($field, $match = '', $type = 'AND ', $wildcard = 'both')
{
if ( ! is_array($field))
{
$field = array($field => $match);
}
foreach ($field as $k => $v)
{
$prefix = (count($this->ar_like) == 0) ? '' : $type;
$v = $this->escape_str($v);
// begin change
switch($wildcard)
{
case 'left': $this->ar_like[] = $prefix." $k LIKE '%{$v}'"; break;
case 'right': $this->ar_like[] = $prefix." $k LIKE '{$v}%'"; break;
default: $this->ar_like[] = $prefix." $k LIKE '%{$v}%'"; break;
}
// end change
}
return $this;
}