We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17921
    • 101 Posts
    Hi, everyone. I need some help smiley

    How can I display on a page web-users of a current web-group? And no one else?

    Thanks.
      samurai smiley
      • 17921
      • 101 Posts
      I found this one. But how to display all the propities?


      <?php
      // ShowUserList - MODx snippet to display the users assigned to a given web group.
      // the webgroup is set in the snippet properties tab or the snippet call.
      // &webgroup=webgroup;text;webgroupname
      // [[ShowUserList? &webgroup=`webgroupname`]]
      
      // check for valid web user group
      if(!isset($webgroup) || $webgroup == '') { return; } // quietly do nothing if webgroup is not set
      $result = $modx->db->select('id',$modx->getFullTableName('webgroup_names'),"name = '".$webgroup."'");
      if($modx->db->getRecordCount($result) != 1) { return; } // quietly do nothing if webgroup does not exist
      
      $table1 = $modx->getFullTableName('web_users');
      $table2 = $modx->getFullTableName('webgroup_names');
      $table3 = $modx->getFullTableName('web_groups');
      $results = $modx->db->select("tbl1.username", "$table1 AS tbl1, $table2 AS tbl2, $table3 AS tbl3", "tbl2.name='$webgroup' AND tbl3.webgroup=tbl2.id AND tbl1.id = tbl3.webuser", 'tbl1.username ASC');
      $userlist = '';
      while($users = $modx->db->getRow($results)) {
        $userlist .= $users['username'].'<br />';
      }
      
      return $userlist;
      ?>
        samurai smiley
        • 34162
        • 1 Posts
        You can use the snippet ShowMembers for this, which you can find here
          • 17921
          • 101 Posts
          Thanks, it works smiley
          But how to make fullname a link to profile?
            samurai smiley
            • 34162
            • 1 Posts
            Glad you got it working smiley

            I’m sorry I can’t help you with linking to a profile, but I’m sure someone else can.
              • 2449
              • 11 Posts
              Great way, but any idea on how to just display the user_group which the loggedin user is in?
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Some of the user’s information is in the $_SESSION.
                <?php
                echo "<pre>";
                print_r($_SESSION);
                echo "</pre>";
                

                Session ID:
                e3acc3893f196bc09de14e22398a5d47
                SESSION values:

                Array
                (
                [groups] => Array
                (
                [0] => Registered Users
                [1] => Fans
                )

                [webShortname] => test
                [webFullname] => Test User
                [webEmail] => [email protected]
                [webValidated] => 1
                [webInternalKey] => 1
                [webValid] => dGVzdGluZw==
                [webUser] => dGVzdA==
                [webFailedlogins] => 0
                [webLastlogin] => 1276848244
                [webnrlogins] => 499
                [webUserGroupNames] =>
                [webDocgroups] => Array
                (
                [0] => 1
                )

                [modx.session.created.time] => 1278090721
                [webUsrConfigSet] => Array
                (
                [login_home] => 10
                )

                [mgrUsrConfigSet] => Array
                (
                )

                )
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 2449
                  • 11 Posts
                  [webUserGroupNames] =>

                  Doesn’t seem like it holds the group name though
                    • 2449
                    • 11 Posts
                    I see that
                    Array
                    (
                    [groups] => Array
                    (

                    => Registered Users
                    [1] => Fans
                    )

                    Has a Fans group? I’m guessing?
                    Is there a way to $_SESSION[’groups.1’] to isolate that?
                      • 4041
                      • 788 Posts
                      Maybe something like this:
                      <?php
                      /*  [!webgroup_names!]
                      
                      */
                      $webgroups ='';
                      if(isset($_SESSION['webUserGroupNames'])){
                         $count = count($_SESSION['webUserGroupNames']);
                         if($count > 0){
                            $webgroups .='<ul>';
                            foreach($_SESSION['webUserGroupNames'] as $wugn){
                              $webgroups .='<li>'.$wugn.'</li>';
                            }
                            $webgroups .='</ul>';
                         }
                      }
                      
                      return $webgroups;
                      ?>
                        xforum
                        http://frsbuilders.net (under construction) forum for evolution