<?php
class ModelCatalogSizeProduct extends Model {
	
        public function getSizes($data = array()) {
                $sql = "SELECT * FROM " . DB_PREFIX . "product_size";
            
		if (!empty($data['filter_size'])) {
			$sql .= " WHERE description LIKE '" . $this->db->escape($data['filter_size']) . "%'";
		}
		
		$sort_data = array(
			'description',
			'sort_order'
		);	
		
		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
			$sql .= " ORDER BY " . $data['sort'];	
		} else {
			$sql .= " ORDER BY description";	
		}
		
		if (isset($data['order']) && ($data['order'] == 'DESC')) {
			$sql .= " DESC";
		} else {
			$sql .= " ASC";
		}
		
		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}					

			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}	
		
			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}				
		
		$query = $this->db->query($sql);
	
		return $query->rows;
        }
}
