<?php
require_once (PATH_TABLES . "activity/JobCentreAttachmentTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class JobCentreAttachmentClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= JobCentreAttachmentTable::C_TABLE ;
		$this->fldid 	= JobCentreAttachmentTable::C_ID ;
	}

	function __destruct() {
	}
    
    function getDocs($id) {     
        $sql = "SELECT * FROM " .JobCentreAttachmentTable::C_TABLE . 
        " WHERE " . JobCentreAttachmentTable::C_ID . " = " . $id;
        
        $rows = $this->db->getTable($sql) ;
        
        if(is_null($rows) || count($rows) == 0){
            return null;
        }else {
            return $rows;
        }
    }

    function deleteDocs($id) {      
        $sql = "delete from " . $this->tbl 
            . " where " . $this->db->fieldParam(JobCentreAttachmentTable::C_ID) ;

        $params = array() ;
        $params[] = $this->db->valueParam(JobCentreAttachmentTable::C_ID,$id) ;
        
        return $this->db->deleteRows($sql,$params) ;
    }

    function deleteDoc($id, $doc_id) {      
        $sql = "delete from " . $this->tbl 
            . " where " . $this->db->fieldParam(JobCentreAttachmentTable::C_ID) 
            . " and " . $this->db->fieldParam(JobCentreAttachmentTable::C_ATTACH_ID);

        $params = array() ;
        $params[] = $this->db->valueParam(JobCentreAttachmentTable::C_ID,$id) ;
        $params[] = $this->db->valueParam(JobCentreAttachmentTable::C_ATTACH_ID,$doc_id) ;
        
        return $this->db->deleteRows($sql,$params) ;
    }

    function updateJobCentreDocId($id){
        try {
            $sql = "UPDATE " . JobCentreAttachmentTable::C_TABLE . 
                    " SET " . JobCentreAttachmentTable::C_ID . " = " . $id . " " .
                    " WHERE " . JobCentreAttachmentTable::C_ID . " = 0 ";

            $this->db->executeSql($sql);
        } catch (Exception $e){
            Log::write("[UpdateDoc] " . $e->getMessage());
        }
    }
}
?>