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

class Frequency_model extends MY_Model {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */

	function __construct(){
		parent::__construct();
		$this->tb_name = "tbl_frequency";
	}
	
	function get_lastest(){
	    $query = $this->db->select("duration")
	                      ->from($this->tb_name)
	                      ->order_by('created_date', 'desc')
	                      ->limit(1)
	                      ->get();
	   if($query->num_rows()>0) {
	       $row = $query->row_array();
	       return $row["duration"];
	   }else{
	       return 60;
	   }
	}

	public function delete_data_between($start, $end)
    {
        $start_time = $start . " 00:00:00";
        $end_time = $end . " 23:59:59";
        $result = $this->db->where("created_date between '{$start}' and '{$end}'")
                           ->delete($this->tb_name);
        return $this->db->affected_rows();
    }

}
