<?php defined('BASEPATH') || exit('No direct script access allowed');

/**
* User Resource Model
*/
class User_Notes_Model extends CI_Model
{
	public $table = 'user_notes';
        public $user_id;
	
	function __construct()
	{
		parent::__construct();
                $this->user_id = $this->auth->user();
               
	}	

	public function get($user_notes_ID = NULL)
	{
		if($user_notes_ID !== NULL){
			$query = $this->db->get_where($this->table, array('user_notes_ID'=>$user_notes_ID));			
			return $query->row();
		}
		$this->db->order_by("user_notes_ID", "DESC");
                $this->db->where('user_ID',$this->user_id->user_ID);
		$query = $this->db->get($this->table);
	             
		return $query->result();
	}
        
        public function insert()
	{
                
		$data = array(
			'note_text' 	=> $this->input->post('user_notes'),
			'user_ID'	=> $this->user_id->user_ID
			);

		return $this->db->insert($this->table,$data);
	}

	public function update()
	{
		$data = array(
			'note_text' => $this->input->post('user_notes')
			);
		$this->db->where('user_notes_ID',$this->input->post('user_notes_ID'));
		return $this->db->update($this->table, $data);
	}

	public function delete($user_notes_ID = null){
		return $this->db->delete($this->table, array('user_notes_ID' => $user_notes_ID ));
	}

}