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

class TaskPlanScheduleClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= TaskPlanScheduleTable::C_TABLE ;
		$this->fldid 	= TaskPlanScheduleTable::C_ID ;
	}
	function __destruct() {
	}
    
    function getTaskPlanSchedule($taskID){
        $sql = "SELECT * FROM " . TaskPlanScheduleTable::C_TABLE . " ";
        $filter = "WHERE " . TaskPlanScheduleTable::C_ID . " = " . $taskID . " ";
        
        $rows = $this->db->getTable($sql . $filter);
        
        return $rows;
    }
	
    function setTaskPlanSchedule($taskID, $taskScheduleTime){
		try {
			if (count($taskScheduleTime) > 0){
				$sql = "INSERT INTO " . TaskPlanScheduleTable::C_TABLE . " VALUES ";
				$values = "";
				foreach($taskScheduleTime as $time){
					if($values != "") $values .= ", ";
					$values .= "( " . $taskID . ", " . $taskScheduleTime . ")";
				}
				
				$this->db->executeSql($sql);
			}
			
		} catch (Exception $e) {
			Log::write('[TaskPlanSchedule]' . $e->getMessage());
			return false;
		}
        
        return true;
    }
	
    function deleteTaskPlanSchedule($taskID){
		try {
			$sql = "DELETE FROM " . TaskPlanScheduleTable::C_TABLE . " ";
			$filter = "WHERE " . TaskPlanScheduleTable::C_ID . " = " . $taskID . " ";
			
			$this->db->executeSql($sql . $filter);
			
		} catch (Exception $e) {
			Log::write('[TaskPlanSchedule]' . $e->getMessage());
			return false;
		}
        
        return true;
    }
}
?>