Reputation: 2529
I am creating one component for managing leads[leads or client leads are submitted from front end],in this component i want to implement a ACL like this.
My client requirement...
SuperAdmin
|— Manager
|—|— Administrator
consider Administrator
is under Manager
.Please dont compare with joomla default ACL.
All leads are show to superadmin.Superadmin will assign the leads to other users.
If the logged in user is a Manager
,he able to see all user leads those who are under Manager
group & Administrator
group.
If the logged in user is a Administrator
,he have no permission for to see others leads because administrator haven't any sub groups,its the last group.
I am using the following query
$query->select( 'c.id as groupid,c.title AS group_name');
$query->from('#__usergroups AS c');
$query->join('LEFT', '#__usergroups AS s ON (s.lft <= c.lft AND s.rgt >= c.rgt) OR (s.lft > c.lft AND s.rgt < c.rgt)' );
$query->where('s.id = "'.$UG.'"');
$query->order('c.lft');
$db->setquery($query);
$gids = $db->loadResultArray();
$gids = implode(",",$gids);
$UG
=> logged in user groupid.
If logged in user is Manager
,$UG
is 6
OUTPUT
groupid group_name
1 Public
6 Manager
7 Administrator
If logged in user is Administrator
,$UG
is 7
.Its also return same answer....I want the output as
If the Manager
logged in
OUTPUT Will be
groupid group_name
6 Manager
7 Administrator
If the Administrator
logged in
OUTPUT Will be
groupid group_name
7 Administrator
or empty
Any one please help me....
Upvotes: 2
Views: 219
Reputation: 2529
Finally i found the answer
Added line AND s.lft <= c.lft AND s.rgt >= c.rgt
in where
condition
$query->select( 'c.id as groupid,c.title AS group_name');
$query->from('#__usergroups AS c');
$query->join('LEFT', '#__usergroups AS s ON (s.lft <= c.lft AND s.rgt >= c.rgt) OR (s.lft > c.lft AND s.rgt < c.rgt)' );
$query->where('s.id = "'.$UG.'" AND s.lft <= c.lft AND s.rgt >= c.rgt ');
$query->order('c.lft');
$db->setquery($query);
$gids = $db->loadResultArray();
Upvotes: 3