Welcome Guest, Not a member yet? Register   Sign In
AR update bug when calculating with fields
#3

[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;
    }


Messages In This Thread
AR update bug when calculating with fields - by El Forum - 01-03-2008, 05:18 AM
AR update bug when calculating with fields - by El Forum - 01-03-2008, 09:36 AM
AR update bug when calculating with fields - by El Forum - 01-03-2008, 10:20 AM
AR update bug when calculating with fields - by El Forum - 01-03-2008, 11:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB