[SOLVED] - Dropdown list filtered on joomla user group

mzanotto

New Member
I think this is a common question but I really didn't find an answer...

I have a table like the following:
+---+-----------+-------+
| id | title | filter |
+---+-----------+-------+
| 1 | title1 | A |
| 2 | title2 | B |
| 3 | title3 | C |
| 4 | title4 | A |

and a form with a databasejoin to that table rendered as a dropdown element
I need to filter the options list based on which joomla usergroup the user is member of.
So if user is in registered-A group then list must show only options with A filter.

How can I do that?

Thanks,
Max
 
No, that's not a common question.

When you say A and registered-A, do you literally mean strings that are part of the group name, or do you mean actual group IDs?

The way I'd do it would be with group IDs, so 'filter' is the numeric group ID not a letter, and a where clause of something like

Code:
WHERE {thistable}.filter IN (SELECT group_id FROM #__users_usergroup_map WHERE user_id = '{$my->id}')

If you are actually talking about strings in a group name, it'b be similar, but in that subquery you'd have to join the #__usegroups table and do a LIKE comparison on the group name. But really, don't do that, use numeric group ids.

-- hugh
 
Hi hugh
thanks for your reply, I did it this way and it works ;)

table: articles (is not the real structure, just to explain)
+---+-----------+-------+
| id | title | groupid_filter |
+---+-----------+-------+
| 1 | title1 | 9 |
| 2 | title2 | 10 |
| 3 | title3 | 11 |
| 4 | title4 | 9 |

table: usergroups (joomla usergroups table)
+----+-----------+-----+-----+-------------------+
| id | parent_id | lft | rgt | title |
+----+-----------+-----+-----+-------------------+
| 1 | 0 | 1 | 28 | Public |
| 2 | 1 | 6 | 25 | Registered |
| 3 | 2 | 7 | 12 | Author |
| 4 | 3 | 8 | 11 | Editor |
| 5 | 4 | 9 | 10 | Publisher |
| 6 | 1 | 2 | 5 | Manager |
| 7 | 6 | 3 | 4 | Administrator |
| 8 | 1 | 26 | 27 | Super Users |
| 9 | 2 | 13 | 16 | registered-A |
| 10 | 9 | 14 | 15 | registered-B |
| 11 | 2 | 21 | 24 | registered-C |
+----+-----------+-----+-----+-------------------+

in the databasejoin dropdown element I set "Data - Where" field in a way similar to what you have suggested:
WHERE {thistable}.`groupid_filter` IN ({$my->groups})

Thanks a lot!
Max
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top