<?php
class ModelSaleContestsample extends Model {
	public function addcontestsample($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "contest_sample_designs SET theme = '" . $this->db->escape($data['theme']) . "',design_category = '" . $this->db->escape($data['design_category']) . "',description = '" . $this->db->escape($data['description']) . "',image = '" . $this->db->escape($data['image']) . "'");
	}
	
	public function editcontestsample($contest_sample_designs_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "contest_sample_designs SET theme = '" . $this->db->escape($data['theme']) . "',design_category = '" . $this->db->escape($data['design_category']) . "',description = '" . $this->db->escape($data['description']) . "',image = '" . $this->db->escape($data['image']) . "'  WHERE contest_sample_designs_id = '" . (int)$contest_sample_designs_id . "'");
	}
	
	public function deletecontestsample($contest_sample_designs_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "contest_sample_designs WHERE contest_sample_designs_id = '" . (int)$contest_sample_designs_id . "'");
	//	$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE metal_id = '" . (int)$metal_id . "'");
	}
	
	public function getcontestsample($contest_sample_designs_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "contest_sample_designs WHERE contest_sample_designs_id = '" . (int)$contest_sample_designs_id . "'");
		
		return $query->row;
	}
	
	public function getcontestsamples($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "contest_sample_designs";
		
		$sql .= " ORDER BY theme";	
			
		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 getTotalcontestsamples() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "contest_sample_designs");
		
		return $query->row['total'];
	}
}
?>