<?php
class TaskModel extends CI_Model{
    private $_tasks = 'tasks';
	function employeeList($sessionuser){
		//$hasil=$this->db->get('tasks');
		$hasil=$this->db->select('*')->order_by('created_at','asc')
    			->get_where($this->_tasks,array('status'=>0, 'employee_id'=>$sessionuser));
 		return $hasil->result();
	}
	function DoneTaskList($sessionuser){
		//$hasil=$this->db->get('tasks');
		$hasil=$this->db->select('*')->order_by('started_at','asc')
    			->get_where($this->_tasks,array('status'=>2, 'employee_id'=>$sessionuser));
		return $hasil->result();
	}
	function saveEmp(){
		$data = array(				
				'employee_id' 	=> $this->input->post('employee_id'), 
				'details' 		=> $this->input->post('details'), 
				'priority' 	    => $this->input->post('priority'),
				'created_at' 	=> $this->input->post('created_at'),
			);
		$result=$this->db->insert('tasks',$data);
		return $result;
	}
	function updateEmp(){
		$id=$this->input->post('id');
		$details=$this->input->post('details');
		$created_at=$this->input->post('created_at');

		$this->db->set('details', $details);
		$this->db->set('created_at', $created_at);
		$this->db->where('id', $id);
		$result=$this->db->update('tasks');
		return $result;	
	}
	function doneTask(){
	    $dt = new DateTime();
        $tz = new DateTimeZone('Asia/Dhaka'); 
        $dt->setTimezone($tz);
        $timenow= $dt->format('Y-m-d');
	    $id=$this->input->post('id');
		$this->db->set('status', 2);
		$this->db->set('started_at', $timenow);
		$this->db->where('id', $id);
		$result=$this->db->update('tasks');
		return $result;	
	}
	function deleteEmp(){
		$id=$this->input->post('id');
		$this->db->where('id', $id);
		$result=$this->db->delete('tasks');
		return $result;
	}	
}