Fork me on GitHub

API for showing a users group  Bottom

  • To much code to currently do this, hope its available in .8 and just as easy to show a users group as it is his/her ID
  • In fact I said it's in .760. The groups module is API compliant so exposes a number of module API's for querying and manipulating groups.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Ah, sry i missed that post, thats great. So i should be able to show the users group by just echoing something like this?


    Code

    $usersgroups = pnModAPIFunc('groups', 'user', 'getusergroups', array('uid' => $userid));
    echo $usersgroups;
  • Quote

    In fact I said it's in .760


    oops ;)

    Presumably the function returns an array of group ids rather than group names - so you couldnt echo it out.

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • To output a debug message where the result will be an array use print_r or var_dump.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Would be nice to know how to use it in templates too.

    For example, I would like to be able to show what groups the user is in in the member list, or using advprofile and its templates.

    How would i do it to show their group name instead of just their group ID, without doing an "if" statement, etc.
  • Groups_userapi_get()

    Returns an array of group name, id and member ids - if you want to find the groups of lots of users you might be better off doing it through that API...

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • what if its just for that specific user. Sry, just trying to get some better examples as thats how I learn best. Partial code doesnt help me to much, and as its looking, it doesnt look like its really that much easier than it was before.
  • I'm guessing that you would set the $userid variable for this - ie $userid = 10; (put this before the function) you would then display the groups with a and array loop I suppose...put this after the fucntion call: print_r($usersgroups); you will then see output of what the function is returning.

    -Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • The advProfile plugin would probably be something like this on a pn0.760 install...

    Code

    <?php

    function advProfile_userapi_usergroups($args)
    {

        extract($args);
        unset($args);

        if (!isset($uid)) {
            return false;
        }

        if (!pnModAPILoad('Groups', 'user')) {
            return false;
        }

        $usergroups = array();
       
        $usergroups = pnModAPIFunc('Groups',
                                   'user',
                                   'getusergroups',
                                   array('uid' => $uid));
                                   
        return $usergroups;

    }

    ?>


    The template, something like this :

    Code

    <!--[section name="usergroups" loop=$usergroups]-->
      <!--[$usergroups[usergroups].name]--><br />
    <!--[/section]-->


    This is done reallllly fast and I don't have time to check it......... I'm REAAAALLLY LATE....

    Cya ! wink
  • Thanks Chestnut, thats exactly the type of example i was looking for. I will definately try it out when i get home. Would it be possible to use that same type of logic in any module?
  • Doh, doesnt work. I added the function to the pnuserapi.php file and then the template code to user_main.tpl, still no luck
  • The Plugin way......

    usergroups.php

    advProfile_plugin_usergroups.tpl

    And in the main tpl :

    Code

    <!--[$plugins.usergroups]-->


    Still untested and not much time to test anything until later though...
  • sweet, that one worked. Thanks!

This list is based on users active over the last 60 minutes.