Page 1 of 1
Using LISE MAMS Groups Multi Select
Posted: Fri Jun 21, 2024 2:18 pm
by webform
I have a field in LISE set to the type "MAMS Groups Multi Select", where I can choose which MAMS groups should have access to a LISE item.
But the output from the field is a comma separated list of MAMS group IDs.
How do I get it translated to group names so it can be used in {mams_smarty::is_user_memberof($groups[,$uid])}?
Re: Using LISE MAMS Groups Multi Select
Posted: Fri Jun 21, 2024 4:50 pm
by Jo Morg
I didn't test it but an UDT like this:
Code: Select all
$gids = $params['gids'] ?? [];
$out = '';
$assign = $params['assign'] ?? 'groups';
if(!is_array($gids) && FALSE !== strpos($gids, ','))
{
$gids = explode(',', $gids);
}
$mams = cms_utils::get_module('MAMS');
if( is_object($mams) )
{
$g_alias = [];
foreach($gids as $gid)
{
$tmp = $mams->GetGroupInfo($gid);
$g_alias[] = $tmp['groupname'];
}
$out = implode(',', $g_alias);
}
if($assign)
{
cms_utils::get_smarty()->assign($assign, $out);
}
return $out;
Then in your template, assuming you named the UDT
'ConvertGIDS2Names', something like:
Code: Select all
{ConvertGIDS2Names}
{mams_smarty::is_user_memberof($groups}
Disclaimer: didn't test it so might not work out of the box, but the gist is there...
Re: Using LISE MAMS Groups Multi Select
Posted: Sun Jun 23, 2024 10:50 am
by webform
Now I have had time to test and the UDT just works perfectly "Out of the box". Thank you very much!
It was more complicated to retrieve the MAMS group names than I first thought. And the solution was not at all within my thinking, how to solve it.
Just out of curiosity, what is the original thought behind "MAMS Groups Multi Select" and how the field and output should be used?
Re: Using LISE MAMS Groups Multi Select
Posted: Sun Jun 23, 2024 11:44 am
by webform
Fo reference if others can use it:
In my LISE Instance i've setup a field named "MAMS Groups" of type "MAMS Groups Multi Select".
Using Jo Morg's UDT "ConvertGIDS2Names" in my LISE Summary template:
Code: Select all
{foreach from=$items item=item}
{if !empty($item->mams_groups) && mams_smarty::is_user_memberof("{ConvertGIDS2Names gids=$item->mams_groups}") || empty($item->mams_groups)}
Content
{/if}
{/foreach}
Re: Using LISE MAMS Groups Multi Select
Posted: Sun Jun 23, 2024 12:10 pm
by Jo Morg
webform wrote: ↑Sun Jun 23, 2024 10:50 am
Now I have had time to test and the UDT just works perfectly "Out of the box". Thank you very much!
It was more complicated to retrieve the MAMS group names than I first thought. And the solution was not at all within my thinking, how to solve it.
Just out of curiosity, what is the original thought behind "MAMS Groups Multi Select" and how the field and output should be used?
To be perfectly honest, I believe that one is just a fork of an existing FEU one, but can't remember whether that's just it. I know that the
users versions of the fields for FEU and then their adaptation to MAMS were bespoke and sponsored and have a lot more versatility. I'll add the features as possible to the other custom field too, while the FEU custom fields will be removed in a near future anyway. I'll venture saying that a better implementation of "MAMS Groups Multi Select" will make its configuration and use easier and more intuitive, so expect that soon.
I'm glad the UDT actually worked as expected.
Cheers!