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

class CampaignClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= CampaignTable::C_TABLE;
		$this->fldid 	= CampaignTable::C_ID;
		$this->flddesc 	= CampaignTable::C_NAME;
	}
	function __destruct() {
	}

	function getCampaignList($orderby = ''){
        $sql = "SELECT * FROM " . $this->tbl . " ";

        if($orderby != "")
            $sql .= " ORDER BY " . $orderby;

        $rows = $this->db->getTable($sql);

        return $rows;
    }

    public function getExistingRecords($gift_name, $gift_id=0) {
        $sql  = "SELECT * FROM " . $this->tbl .
            " WHERE " . $this->flddesc . " = '" . $gift_name . "' ";

        if($gift_id != 0) {
            $sql  .= " AND " . $this->fldid . " <> " . $gift_id . " ";
        }

        $rows = $this->db->getTable($sql);

        if (is_null($rows) || count($rows) == 0) {
            return null;
        } else {
            return $rows;
        }
    }

    public function getCampaignActive(){
        $sql =" SELECT * FROM " . CampaignTable::C_TABLE . " WHERE " . CampaignTable::C_STATUS . " = 1 ";
        $rows = $this->db->getTable($sql);

        if (is_null($rows) || count($rows) == 0) {
            return null;
        } else {
            return $rows;
        }
    }
}
