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

class Admin_model extends CI_Model
{
	public function getRoleById($id)
	{
		return $this->db->get_where('user_role', ['id_role' => $id])->row_array();
	}

	public function getAllDataById($table, $primary, $id)
	{
		return $this->db->get_where($table, [$primary => $id])->result_array();
	}

	public function editRole()
	{
		$data = [
        	"role" => $this->input->post('role', true)
		];

		$this->db->where('id_role', $this->input->post('id'));
		$this->db->update('user_role', $data);
	}

	public function deleteRole($id)
	{
		return $this->db->delete('user_role', ['id_role' => $id]);
	}

	public function getUser()
	{	
		$this->db->select('*');
		$this->db->from('user');
		$this->db->order_by("id_role", "asc");
		$query = $this->db->get()->result_array();
		return $query;
	}

	public function getUserById($id)
	{
		return $this->db->get_where('user', ['id_user' => $id])->row_array();
	}

	public function deleteUser($id)
	{
		return $this->db->delete('user', ['id_user' => $id]);
	}

	public function count($table)
    {
        return $this->db->count_all($table);
    }

	public function companyProfile()
	{
		return $this->db->get_where('profile', ['id_profile' => 1])->row_array();
	}
}