<?php
class ModelCatalogSpecialAction extends Model {

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

		$this->load->helper('ftr_geral');
		$this->load->type('tipocomum');

		$data = ftr_geral::ConvertCaracter($data);

		//$sql = "SELECT * from " . DB_PREFIX . "order_promotion op WHERE op.id_futura > 0";

		$sql = "SELECT DISTINCT op.order_promotion_id, 
		op.`description`, 
		op.`status`, 
		op.registry_date, 
		op.id_futura, 
		op.image,
		od.date_end 
		FROM oc_order_promotion op 
		LEFT JOIN oc_order_discount od 
		ON op.order_promotion_id = od.order_promotion_id
		WHERE od.date_end > CURRENT_DATE() 
		AND op.id_futura > 0
		AND op.`status` = 0";

		if (!empty($data['filter_special'])) {
			$sql .= " AND op.description LIKE '" . $this->db->escape($data['filter_special']) . "%'";
		}

		if (!empty($data['filter_status'])) {
			$sql .= " AND op.status = " . $this->db->escape($data['filter_status']);
		}

		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 getSpecialAction($specialActionId){

		$this->load->helper('ftr_geral');
		$this->load->type('tipocomum');

		$sql = "SELECT * from " . DB_PREFIX . "order_promotion op WHERE op.order_promotion_id = ".$specialActionId;

		$query = $this->db->query($sql);

		return $query->row;

	}

}
