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

/**
* User Resource Model
*/
class Menu_permission_model extends CI_Model
{
    public $table = 'tbl_menu_mtr';
    public $table1 = 'tbl_page_mtr';
    public $table2 = 'tbl_user_mtr';
    public $table3 = 'tbl_menu_permission';

   public function get_menus($menu_id=FALSE)
   {
        if($menu_id==null)
        {
            $query = $this->db->get($this->table);
            return $query->result_array();
        }
    $query = $this->db->get_where($this->table,array('id' => $menu_id));
    return $query->row_array();
   }

   public function get_last_added_menu_id($menu_name=FALSE)
   {
        if($menu_name==null)
        {
            $query = $this->db->get($this->table)->order_by('id',"desc")->limit(1);
            return $query->row_array();
        }
    $query = $this->db->get_where($this->table,array('menu_name' => $menu_name));
    return $query->row_array()['id'];
   }

   public function get_pages($page_id=FALSE)
   {
        if($page_id==null)
        {
            $query = $this->db->get($this->table1);
            return $query->result_array();
        }
    $query = $this->db->get_where($this->table1,array('id' => $page_id));
    return $query->row_array();
   }

   public function get_user_types($user_type_id=FALSE)
   {
        if($user_type_id==null)
        {
            $query = $this->db->get($this->table2);
            return $query->result_array();
        }
    $query = $this->db->get_where($this->table2,array('id' => $user_type_id));
    return $query->row_array();
    }

    public function get_user_types_count()
    {
        $i=0;
        $query = $this->db->get_where($this->table2);
        $result=$query->result_array();
        foreach($result as $res):
            $i++;
        endforeach;
        return $i;
     }
 
    public function get_menu_permissions($permission_id=FALSE)
    {
        if($permission_id==null)
        {
            $query = $this->db->get($this->table3);
            return $query->result_array();
        }
    $query = $this->db->get_where($this->table3,array('id' => $permission_id));
    return $query->row_array();        
    }

    public function add_menu_master($menu_name, $file_path, $under_menu_id, $menu_order)
    {
        $data=array(
            'menu_name'=>$menu_name , 
            'file_path'=>$file_path,
            'under_menu_id'=>$under_menu_id,
            'menu_order'=>$menu_order
        );    
        return $this->db->insert('tbl_menu_mtr',$data);

    }

    public function add_menu_permission($menu_id,$usertype_id, $active_status)
    {
        $data=array(
            'menu_id'=>$menu_id ,
            'user_type_id'=>$usertype_id , 
            'status'=>$active_status
        );    
        return $this->db->insert('tbl_menu_permission',$data);

    }


    public function  add_page_function($page_name,$page_link,$page_desc)
    {
        $data=array(
            'page_name'=>$page_name ,
            'page_desc'=>$page_link , 
            'page_link'=>$page_desc,
            'created_by'=>'101/admin/veer'
        );    
        return $this->db->insert('tbl_page_mtr',$data);

    }




}