<?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";

		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;

	}

}
