We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1240
    • 43 Posts
    Hello, I’m a (french) beginner at the MODx CMS and I’m trying to write a snippet.
    My problem is that I don’t know how finding the group that the user have the right.
    I’ve found this : $modx->getUserDocGroups(2) but I don’t know how use it.

    Is it possible that someone learn me how get the rights and show them with "echo ..." for example ?

    thanks wink

    --- Edit ---
    My real objective is to restrict some parts of my snippet using the user group rights
      • 13312
      • 13 Posts
      I hope you still need the solution:

      <?php
      
      $logged_in_user_id = $modx->getLoginUserID();
      
      if(isUserInGroup($logged_in_user_id, 'GroupName'))
      {
      	//user is part of a GroupName webgroup...code goes here
      }
      else
      {
      	//user is not part of a GroupName webgroup
      }
      
      function isUserInGroup($user_id, $webgroup_name)
      {
          $sql='SELECT COUNT(*) FROM modx_web_groups INNER JOIN modx_webgroup_names ON modx_web_groups.webgroup=modx_webgroup_names WHERE modx_web_groups.webuser='.$user_id.' AND modx_webgroup_names.name=\''.$webgroup_name.'\'';
      	$rs = $modx->db->query($sql);
      	
      	return mysql_num_rows($rs);
      }
      
      ?>
      
        • 27376
        • 576 Posts
        What you’re looking for is the isMemberOfWebGroup API Function.

        The getUserDocGroups function returns ALL the document groups that the current logged in user is assigned to.