<?php
require_once (PATH_TABLES . "campaign/CampaignDeliveryTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class CampaignDeliveryClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= CampaignDeliveryTable::C_TABLE;
		$this->fldid 	= CampaignDeliveryTable::C_DELIVERY_ID;
	}
	function __destruct() {
	}
	
	function getCampaignDeliveryByGiftID($id){
		$sql = "SELECT * FROM " . CampaignDeliveryTable::C_TABLE . " WHERE " . CampaignDeliveryTable::C_ID . " = " . $id;
		$rows = $this->db->getTable($sql);

		if(!is_null($rows) && count($rows) > 0){
			return $rows;
		}else{
			return null;
		}
	}

	function deleteCampaignDeliveryByGiftID($id){
		$sql = "DELETE FROM " . CampaignDeliveryTable::C_TABLE . " WHERE " . CampaignDeliveryTable::C_ID . " = " . $id;

		$this->db->executeSql($sql);
	}

	function getDeliveryTimeByGiftID($id, $date = ""){
		$sql = "SELECT * FROM " . CampaignDeliveryTable::C_TABLE . 
				" WHERE " . CampaignDeliveryTable::C_ID . " = " . $id;
		
		$filter = "";
		if($date != ""){
			$filter .= " AND " . CampaignDeliveryTable::C_DATE . " = '" . $date . "'";
		}

		return $this->db->getTable($sql . $filter);
	}
}
