Jump to content

How to get a User's groups

Graham Quince

Recommended Posts

I thought I'd share this snippet more for reference than for a specific need, but it saves you have to work it out later.  It uses an FDP API (fixed so they will not be changed, unlike the internal APIs)

This is example, it was needed to change the site's background and banner to match a student's house colours.  I know I could have set the CSS in Javascript, but pages load on demand and by rendering out the CSS, it is easy to adapt for all sites, or all pages etc...

<div class="styling"></div>

var siteUUID = 'SITE_UUID',
    user = FrogOS ? FrogOS.getUser() : this.getUser(),
    styling = arguments[0].find('.styling');
    houseColours = {
        'House1': {
            background: 'rgba(0,255,0,1)',
            banner: 'file/resource/7E4864D720030D3DB0338F5280C6A104F3BB61EC80ADD2A4'
        'House2': {
            background: 'rgba(255,0,0,1)',
            banner: 'file/resource/7E4864D720030D3DB0338F5280C6A104F3BB61EC80ADD2A4'
        'House3': {
            background: 'rgba(255,255,0,1)',
            banner: 'file/resource/7E4864D720030D3DB0338F5280C6A104F3BB61EC80ADD2A4'
        'House4': {
            background: 'rgba(0,0,255,1)',
            banner: 'file/resource/7E4864D720030D3DB0338F5280C6A104F3BB61EC80ADD2A4'

    if (user.profile.type == 'admin' || user.profile.type == 'superuser') {
        user.uuid = 'STUDENT_UUID'; 
    url: 'group/memberships',
    path: '/api/fdp/2/',
    data: { 
        uuid: user.uuid
}).done(function(response) {

    var house = 'House1';
    var groups = response.response;
    $.each(groups, function(index,group) {
        if (group.type == 'house') {
            house = group.name;
    var background = houseColours[house].background,
        banner = houseColours[house].banner;
        'div[data-site-uuid="'+siteUUID+'"] .ui-theme-mobilesmallbanner-bodyline {'+
            'background: '+background+' !important;'+
            'background: linear-gradient(180deg, '+background+' 0%, rgba(255,255,255,1) 20%) !important;'+
        'div[data-site-uuid="'+siteUUID+'"] .ui-theme-mobilesmallbanner-container {'+
            'background-image: url('+banner+') !important;'+ 
}).fail(function(e) {
   // Report Error



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...