<?php

require_once (PATH_TABLES . "activity/ChecklistDetailTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

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

	function getJobChecklist($headerId){
		$sql = "SELECT H.".ChecklistHeaderTable::C_ID .",H.".ChecklistHeaderTable::C_NAME .",D.* ".
				" FROM " . ChecklistHeaderTable::C_TABLE . " H " .
				" LEFT OUTER JOIN " . ChecklistDetailTable::C_TABLE . " D " .
				" ON H." . ChecklistHeaderTable::C_ID." = D.".ChecklistDetailTable::C_HEADER_ID .
                " WHERE H." . ChecklistHeaderTable::C_ID . " = " . $headerId . " " .
                " ORDER BY D." . ChecklistDetailTable::C_ORDER . " ";
				
        $result = null;
        try{
            $result = $this->db->getTable($sql);
        } catch (Exception $e){
            Log::write("[ChecklistDetailClass]" . $e->getMessage());
        }
        
        return $result;
        
	}

	function deleteChecklist($id){
		$sql = "DELETE FROM " . ChecklistDetailTable::C_TABLE . 
                " WHERE " . ChecklistDetailTable::C_HEADER_ID . " = " . $id. "";
        
        try{
            $this->db->executeSql($sql);
        } catch (Exception $e){
            Log::write("[ChecklistDetailClass]" . $e->getMessage());
        }
	}

	function getChecklist($id){
		$sql = "SELECT * ". 
                " FROM " . ChecklistDetailTable::C_TABLE . "  " .
                " WHERE " . ChecklistDetailTable::C_HEADER_ID . " = " . $id . " " .
                " ORDER BY " . ChecklistDetailTable::C_ORDER . " ";
        
        $result = null;
        try{
            $result = $this->db->getTable($sql);
        } catch (Exception $e){
            Log::write("[ChecklistDetailClass]" . $e->getMessage());
        }
        
        return $result;
        
	}

}
?>