<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class M_gelombang extends CI_Model
	{
		function __construct()
		{
			parent::__construct();
		}
		
		function getGelombang()
		{
			$this->db->select('*');
			$this->db->from('gelombang');
			$this->db->order_by('start_date', 'asc');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addGelombang($data)
		{
			return $this->db->insert('gelombang',$data);
		}
		
		function getGelombangDetail($id_gelombang)
		{
			$this->db->select('*');
			$this->db->from('gelombang');
			$this->db->where('id_gelombang',$id_gelombang);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updateGelombang($id_gelombang,$data)
		{
			$this->db->where('id_gelombang',$id_gelombang);
			return $this->db->update('gelombang',$data);
		}
		
		function deleteGelombang($id_gelombang)
		{
			$this->db->delete('gelombang', array('id_gelombang' => $id_gelombang));
		}
		
		function getGelombangOpen($today)
		{
			$this->db->select('*');
			$this->db->from('gelombang');
			$this->db->where('start_date <=', $today);
			$this->db->where('end_date >=', $today);
			$this->db->order_by('id_gelombang', 'desc');
			$this->db->limit(1);
			$result = $this->db->get();
			return $result;
		}
	}
