User Group lookup [Solved]

PaulT

Member
I have a timesheet form that contains an employee_name field which is the user_id. I want to make an element on the timesheet hidden or visible conditional on if this employee is part of the Driver (user_group) Group. I have a Fabrik Employee table that contains the user_id and user_group.
How can I have a hidden field on the Timesheet form check the employee_name and return true or false if that use_id is a member of the Driver group (11)?

I think this might be possible as a calc element but I am not sure how to write the calculation.

Something like:
$ename = '{geh_timesheet___employee_name}';
$ugroup = '{geh_employees___user_group}';
$uid = '{geh_employees___user_id}';
$egroup = '{geh_timesheet___employee_group}';

$egroup = 1 if $ugroup contains 11
$egroup = 0 if $ugroup != 11

return $egroup;

geh_timesheet___employee_name is FK for geh_employees___user_id
Most employees are only in one group but when in more than one the values in user_group are like this ["14","18"]
 
Last edited:
You'd probably want to use the J! API to get the array of group ID's the user belongs to.

Code:
$thisUser = JFactory::getUser((int)'{geh_employees___user_id}');
return in_array(11, $thisUser->getAuthorisedGroups());

Note that you'll need to set "Calc on save only" to No, so it calculates it on display, as any data you have already in your table won't have the value in it yet.

-- hugh
 
You'd probably want to use the J! API to get the array of group ID's the user belongs to.

Code:
$thisUser = JFactory::getUser((int)'{geh_employees___user_id}');
return in_array(11, $thisUser->getAuthorisedGroups());

Note that you'll need to set "Calc on save only" to No, so it calculates it on display, as any data you have already in your table won't have the value in it yet.

-- hugh

Unfortunately when I used this code as the calc. nothing happened except when I looked in the database, the employee_group in the timesheet table had changed from NULL to blank.
It somehow needs to see what is entered into {geh_timesheet___employee_name} in this form so it knows who to look up in {geh_employees___user_id} and return {geh_employees___user_group} to this field {geh_timesheet___employee_group}.
 
Last edited:
I have solved what I originally wanted to do by simply adding a new field to the timesheet called groups that is a field plugin (hidden) with {$my->groups} placed in the default box. This automatically detects the current logged in user and I was able to hide the field I wanted from a particular group using JavaScript in the JavaScript tab.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top