<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends MY_Model
{
	
	protected $table_name = 'tbluser';
	protected $id_name = 'us_id';

	function __construct()
	{
		parent::__construct();
	}
	
	function check_data($login_name)
	{
		$this->db->where('login_name', $login_name);
		$query = $this->db->get($this->table_name);
		return $query->num_rows();
	}
	
	function get_list_users($data)
	{
		$sql="SELECT * FROM ".$this->table_name;
		$data['keyword']='';
		if ($data['keyword'])
		{
			$sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%') ";
		}
		return $this->db->query($sql." ORDER BY us_id DESC LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
	}

	function get_total_users($data)
	{
		$sql="SELECT COUNT(".$this->id_name.") AS total FROM ".$this->table_name;
		if (isset($data['keyword']))
		{
			$sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%') ";
		}
		return $this->db->query($sql)->row_array()['total'];
	}
}