<?php
class ModelSaleSizeMaster extends Model {
	public function addSize($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "size SET size_code = '" . $this->db->escape($data['size_code']) . "',measlength = '" . $this->db->escape($data['measlength']) . "',measwidth = '" . $this->db->escape($data['measwidth']) . "'");
	}
	
	public function editSize($size_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "size SET size_code = '" . $this->db->escape($data['size_code']) . "',measlength = '" . $this->db->escape($data['measlength']) . "',measwidth = '" . $this->db->escape($data['measwidth']) . "' WHERE size_id = '" . (int)$size_id . "'");
	}
	
	public function deleteSize($size_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "size WHERE size_id = '" . (int)$size_id . "'");
		
	}
	
	public function getSize($size_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "size WHERE size_id = '" . (int)$size_id . "'");
		
		return $query->row;
	}
	
	public function getSizes($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "size";
		
		$sql .= " ORDER BY size_id";	
			
		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;
	}
	
	public function getTotalSizes() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "size");
		
		return $query->row['total'];
	}
}
?>