Using LISE MAMS Groups Multi Select Topic is solved

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Using LISE MAMS Groups Multi Select

Post 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])}?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: Using LISE MAMS Groups Multi Select

Post 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...
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Using LISE MAMS Groups Multi Select

Post 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?
User avatar
webform
Power Poster
Power Poster
Posts: 503
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Using LISE MAMS Groups Multi Select

Post 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}
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1967
Joined: Mon Jan 29, 2007 4:47 pm

Re: Using LISE MAMS Groups Multi Select

Post 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!
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Modules/Add-Ons”