<?php
require_once (PATH_TABLES . "destination/DestinationTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class DestinationClass extends MasterBase {
    private $fldname ;
	private $fldlink ;

	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= DestinationTable::C_TABLE;
		$this->fldid 	= DestinationTable::C_ID ;
		$this->fldname 	= DestinationTable::C_NAME ;
		$this->fldlink 	= DestinationTable::C_LINK ;
	}
	function __destruct() {
	}
    function getDestinationByName($name){
        $sql = "SELECT * FROM " . $this->tbl . " ";
        $sql .= "WHERE " . $this->fldname . " = '" . $name . "' ";

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

        if (is_null($rows) || count($rows) == 0)
            return null ;
        else
            return $rows[0] ;
    }
    
	function getDestinationLinkById($id){
        $sql = "SELECT * FROM " . $this->tbl . " ";
        $sql .= "WHERE " . $this->fldid . " = '" . $id . "' ";

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

        if (is_null($rows) || count($rows) == 0)
            return null ;
        else
            return $rows[0][DestinationTable::C_LINK];
    }

    function isNameFound($name) {
		$filter = $this->db->fieldParam($this->fldname);
		$params = array() ;
		$params[] = $this->db->valueParam($this->fldname,$name) ;
		if ($this->db->getRowsCount($this->tbl,$filter,$params) > 0 )
			return true ;
		else
			return false ;
	}

    function deleteDestinationRecord($ids){
		$sql = "delete from ". $this->tbl ." where ". $this->fldid ." in ( ".$ids.") ";
		$this->db->executeSql($sql);
	}

}
