Permissions of Modules

Asked

Viewed 40 times

0

I have this class but at the time of comparing if there is this permission inside the return of the array, it appears that it has none.

The permission is listed within the array.

class Permission{

    var $Permission = array();
    var $table = 'permissoes';//Nome tabela onde ficam armazenadas as permissões
    var $pk = 'idPermissao';// Nome da chave primaria da tabela
    var $select = 'permissoes';// Campo onde fica o array de permissoes.

    public function  __construct() {
        log_message('debug', "Permission Class Initialized");
        $this->CI =& get_instance();
        $this->CI->load->database();

    }

    public function checkPermission($idPermissao = null,$atividade = null){

        echo $idPermissao;


        if($idPermissao == null || $atividade == null){
            return false;
        }
        // Se as permissões não estiverem carregadas, requisita o carregamento
        if($this->Permission == null){
            // Se não carregar retorna falso
            if(!$this->loadPermission($idPermissao)){
                return false;
            }
        }

        if(is_array($this->Permission[0])){


            //echo $atividade."<br><br>";
            echo "<pre>";
            print_r($this->Permission[0]);
            echo "</pre>";
            //die();

            if(array_key_exists($atividade, $this->Permission[0])){
                // compara a atividade requisitada com a permissão.
                if ($this->Permission[0][$atividade] == 1) {
                    return true;
                } else {
                    return false;
                }
            }
            else{
                return false;
            }
        }
        else{
            return false;
        }

    }
    private function loadPermission($id = null){

        if($id != null){
            $this->CI->db->select($this->table.'.'.$this->select);
            $this->CI->db->where($this->pk,$id);
            $this->CI->db->limit(1);
            $array = $this->CI->db->get($this->table)->row_array();

            if(count($array) > 0){

                $array = unserialize($array[$this->select]);
                //Atribui as permissoes ao atributo permission
                $this->Permission = array($array);
                return true;


            }
            else{
                return false;
            }

        }
        else{
            return false;
        }

    }
}

The print_r listing is as follows:

Array
(
    [0] => aCedentes
    [1] => eCedentes
    [2] => dCedentes
    [3] => vCedentes
    [4] => aUsuarios
    [5] => eUsuarios
    [6] => dUsuarios
)

In this case, it would have to have been TRUE and not FALSE.

  • Here if(array_key_exists($activity, $this->Permission[0])){ can’t find $activity posted... As much as you have on the Permission list

  • @Rray can give me strength?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.