<?php
class ModelSalecolorclarity extends Model {
	public function addCustomerGroup($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "colour_clarity SET  gemstone_id = '" . $this->db->escape($data['gemstone_id']) . "',clarity_id = '" . $this->db->escape($data['clarity_id']) . "',colour_id = '" . $this->db->escape($data['colour_id']) . "'");
	}
	
	public function editCustomerGroup($colorclarity_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "colour_clarity SET  gemstone_id = '" . $this->db->escape($data['gemstone_id']) . "',clarity_id = '" . $this->db->escape($data['clarity_id']) . "',colour_id = '" . $this->db->escape($data['colour_id']) . "' WHERE colorclarity_id = '" . (int)$colorclarity_id . "'");
	}
	
	public function deleteCustomerGroup($colorclarity_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "colour_clarity WHERE colorclarity_id = '" . (int)$colorclarity_id . "'");
	//	$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE colorclarity_id = '" . (int)$colorclarity_id . "'");
	}
	
	public function getCustomerGroup($colorclarity_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "colour_clarity WHERE colorclarity_id = '" . (int)$colorclarity_id . "'");
		
		return $query->row;
	}
	
	public function getCustomerGroups($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "colour_clarity a,gemstone b where a.gemstone_id=b.gemstone_id";
		
		$sql .= " ORDER BY a.gemstone_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 getTotalCustomerGroups() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "colour_clarity");
		
		return $query->row['total'];
	}
}
?>