<?php
class EmergencyContact {
	protected $db;
	protected $info;
	
	public function __construct(){
		$this->db			=	DBConnectorFactory::loadDriver();	
	}
	
	public function setData(array $info){
		$this->info			=	$info;
		return $this;
	}
	
	public function create(){
            $data = [&$this->info['EmergencyContact_FirstName'],
                    &$this->info['EmergencyContact_MiddleName'],
                    &$this->info['EmergencyContact_LastName'],
                    &$this->info['Employee_Relationship_ID'],
                    &$this->info['EmergencyContact_HomePhone'],
                    &$this->info['EmergencyContact_MobilePhone'],
                    &$this->info['EmergencyContact_WorkPhone'],
                    &$this->info['Employee_ID'],
                    &$this->info[0]];
		$this->db->prepare_Stmt('INSERT INTO 
				tbl_hrm_emergency_contact
			(
			EmergencyContact_FirstName, 
			EmergencyContact_MiddleName, 
			EmergencyContact_LastName, 
			Employee_Relationship_ID, 
			EmergencyContact_HomePhone, 
			EmergencyContact_MobilePhone, 
			EmergencyContact_WorkPhone, 
			Employee_ID,
			Logged_ID_ID
            
			)
			VALUES (?,?,?,?,?,?,?,?,?)',$data);
                $error = $this->db->error();
		return $error;
	}
	
	public function viewByEmployeeID($employeeID){
		$data				=	array();
		$query				=	'
			SELECT * FROM
				tbl_hrm_emergency_contact
			WHERE
				Employee_ID	=	"'.$employeeID.'"
		';
		$result				=	$this->db->query($query);
		while($row			=	$this->db->assoc($result))
			$data[]			=	$row;
		return $data;
	}
}