hominid4
Member
Hi, I have a dbjoin element(client_id) that creates a dropdown of the #__users table, with an element pre-filter so that in the form it only pulls the Clients who are assigned to #__usergroups called ?Clients? (GID = 11):
That works correctly. I also have another #__usergroups called ?Employee? (GID = 13) and a ?portal_user_relationship? table that associates the employees with the clients:
When a Employee logs in, and views the form, I need for them to only see the clients they are associated with:
Each of those element pre-filters work on their own but I?m needing to combine them , so that if a ?Special? user logs in they see all "Clients" in the form?s dropdown (only the Clients not the full #__users table), but if an Employee logs in and goes to the form they only see their related clients.
I?ve been trying different subqueries and such but keep only getting an either/or result. Is it possible to start with a form element pre-filter showing the Clients, and then an "IF" pre-filter saying if an ?Employee? then add the second pre-filter based on the ?portal_user_relationship? table?
Thanks!
UPDATE: I've been trying if/then statements (which I may be way off base and not using it correctly at all) such as below but receiving errors such as "right syntax to use near ') THEN (".
Code:
Data - where tab:
WHERE {thistable}.id IN (SELECT user_id FROM #__user_usergroup_map WHERE group_id = 11)
Apply where to: Public
That works correctly. I also have another #__usergroups called ?Employee? (GID = 13) and a ?portal_user_relationship? table that associates the employees with the clients:
Code:
==================
portal_user_relationship
==================
id | employee_id | client_id
1 | 365 | 501
2 | 874 | 506
3 | 365 | 538
4 | 471 | 590
5 | 471 | 611
When a Employee logs in, and views the form, I need for them to only see the clients they are associated with:
Code:
Data - where tab:
WHERE {thistable}.id IN (SELECT client_id FROM portal_user_relationship WHERE employee_id = {$my->id})
Apply where to: Employee
Each of those element pre-filters work on their own but I?m needing to combine them , so that if a ?Special? user logs in they see all "Clients" in the form?s dropdown (only the Clients not the full #__users table), but if an Employee logs in and goes to the form they only see their related clients.
I?ve been trying different subqueries and such but keep only getting an either/or result. Is it possible to start with a form element pre-filter showing the Clients, and then an "IF" pre-filter saying if an ?Employee? then add the second pre-filter based on the ?portal_user_relationship? table?
Thanks!
UPDATE: I've been trying if/then statements (which I may be way off base and not using it correctly at all) such as below but receiving errors such as "right syntax to use near ') THEN (".
Code:
WHERE {thistable}.id IN (SELECT user_id FROM #__user_usergroup_map WHERE group_id = 11) AND IF ({$my->id} IN (SELECT user_id FROM #__user_usergroup_map WHERE group_id = 13)) THEN {thistable}.id IN (SELECT client_id FROM portal_user_relationship WHERE employee_id = {$my->id});