<?php

class Dependant {

    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['Dependant_FirstName'],
            &$this->info['Dependant_MiddleName'],
            &$this->info['Dependant_LastName'],
            &$this->info['Dependant_Relationship'],
            &$this->info['Dependant_DOB'],
            &$this->info['Dependant_CertificateNumber'],
            &$this->info['Dependant_DateOfRegistration'],
            &$this->info['Employee_ID']];

        $this->db->prepare_Stmt('INSERT INTO 
				tbl_hrm_dependants
			(
			Dependant_FirstName,
			Dependant_MiddleName,
			Dependant_LastName,
			Dependant_Relationship,
			Dependant_DOB,
			Dependant_CertificateNumber,
			Dependant_DateOfRegistration,
			Employee_ID
			)
			VALUES (?,?,?,?,?,?,?,?)', $data);
        $error = $this->db->error();
        if (empty($error))
            return true;
        return false;
    }

    public function viewByEmployeeID($employeeID) {
        $data = array();
        $query = '
			SELECT * FROM
				tbl_hrm_dependants
			WHERE
				Employee_ID	=	"' . $employeeID . '"
		';
        $result = $this->db->query($query);
        while ($row = $this->db->assoc($result))
            $data[] = $row;
        return $data;
    }

}
