<?php
class ModelSettingAnalyze extends Model {
	public function addAnalyze($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "analyze SET titulo = '" . $this->db->escape($data['analyze_title']) . "', `codigo` = '" . $this->db->escape($data['analyze_code']) . "' ");

		return $this->db->getLastId();
	}

	public function editAnalyze($analyze_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "analyze SET titulo = '" . $this->db->escape($data['analyze_title']) . "' WHERE analyze_id = '" . (int)$analyze_id . "'");

	}

	public function deleteAnalyze($analyze_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "analyze WHERE analyze_id = '" . (int)$analyze_id . "'");
	}

	public function getAnalyze($analyze_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "analyze WHERE analyze_id = '" . (int)$analyze_id . "'");

		return $query->row;
	}

	public function getAnalyzes($data = array()) {

		$sql = "SELECT * FROM " . DB_PREFIX . "analyze ORDER BY analyze_id DESC";

		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);
		$analyze_data = $query->rows;

		return $analyze_data;
	}

	public function getTotalAnalyzes() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "analyze");

		return $query->row['total'];
	}


}
