Ion Auth Multigroups

The more I use codeigniter the better I like it - I've already changed some sites from Drupal to CI.

Anyway a small problem, that I've mentioned in the forum

http://codeigniter.com/forums/viewthread/145263/P1030/

Using Ion 2

Small problem, first the function $this->ion_auth->is_group($group) should be in_group().
I think I remember seeing this elsewhere. However a problem exists if you pass an array of groups.

Currently is_group returns in_array($check_group, $groups) which won’t work if check_group is an array.

Solution:
application/libraries/Icon_auth.php

Add condition to check if $check_groups is an array and if it is then walk through the array checking for a match.

public function in_group($check_group) { 
$this
->ci->ion_auth_model->trigger_events('is_group');
$users_groups
= $this->ci->ion_auth_model->get_users_groups();
$groups
= array();
foreach (
$users_groups as $group) {
$groups[]
= $group->name;
}  
$permission
= false;
if(
is_array($check_group)) {
foreach($check_group $key => $value){
if(in_array($value, $groups)) {  
$permission
= true;  
}  
}  
}
else {
if(
in_array($check_group, $groups)) {
$permission
= true;
}
}
return $permission;
}

 

Tags: 

Add new comment