ActiveRecord.php 863 Bytes
<?php
/**
 * Common model function
 * 
 */
abstract class ActiveRecord extends CActiveRecord
{
    /**
     * @param   integer, record start
     * @param   integer, record limit number
     */
    public function limited($start = 0, $limit = 100)
    {
        $this->getDbCriteria()->mergeWith(array(
            'offset' => $start,
            'limit' => $limit
        ));
        return $this;
    }
    
    
    /**
     * Finds out sort parameters
     */
    public static function getSort( $sort )
    {
        if(!is_array($sort) || count($sort) == 0) {
            return '';
        }
        
        $_str = array();
        
        array_walk($sort, create_function('$item, $key, $_tmp', '
            $_tmp[0][] = $item["property"] . " " . $item["direction"];
        '), array( &$_str ));
        
        return implode(", ", $_str);
    }
}