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

class RolePermission_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    // Get permissions assigned to a role
    public function get_permissions_by_role($role_id) {
        $this->db->select('permission_id');
        $this->db->from('kns1_role_permissions');
        $this->db->where('role_id', $role_id);
        $query = $this->db->get();
        return array_column($query->result_array(), 'permission_id');
    }

    // Assign a permission to a role
    public function assign($role_id, $permission_id) {
        $data = [
            'role_id' => $role_id,
            'permission_id' => $permission_id
        ];
        return $this->db->insert('kns1_role_permissions', $data);
    }

    // Remove all permissions for a role
    public function clear_permissions($role_id) {
        return $this->db->delete('kns1_role_permissions', ['role_id' => $role_id]);
    }







}
