Graham Quince Posted September 20, 2018 Share Posted September 20, 2018 Here's something you might like to experiment with... This code below searches for the children of a logged-in parent, displays them, lists their classes and then displays the teachers of those classes with a link to their email address: <style> .childlist { border: 1px solid #CCCCCC; border-radius: 10px; padding: 10px; font-size: 14pt; line-height: 14pt; width: 40%; float: left; margin: 10px; } .childlist a { color: #FF0000; font-weight: bold; } </style> <div class="emailList"></div> <script> var emailList = this.element.find('.emailList'); var getGroupsforChild = function(child) { Frog.Model.api('groups.getFor', { identity: child.uuid, group_type: "Class" }).done(function(groupResponse) { var groupString=""; $.each(groupResponse.data, function(index1,group) { var classid = child.user_uuid+index1 /* Now run the function to list all the members of the group */ getTeachersforGroup(group,classid); groupString+='<li class="Class'+classid+'">'+group.name+'</li>' }); emailList.append( '<div class="childlist">'+ '<h3>'+child.displayname+"'s classes:</h3>"+ '<ul>'+groupString+'</ul>'+ '</div>' ); }); }; var getTeachersforGroup = function(group,classid) { Frog.Model.api('groups.getMembers', { uuid: group.uuid }).done(function(membersResponse) { var members = membersResponse.data, TeacherString=" - "; //console.log(groups); $.each(members, function(index2,member) { /* This IF statement looks for Staff profiles */ if (member.profile.name==="Staff" || member.profile.name==="Admin") { TeacherString+='<a href="mailto:'+member.email+'">'+member.displayname+'</a> ' } }); if (TeacherString!==" - ") { emailList.find(".Class"+classid).append(TeacherString); } }); }; /* First, get each child of the parent */ Frog.Model.api('users.getChildren').done(function(listResponse) { var children = listResponse.data; $.each(children, function(index,child) { /* now run the function to list all the groups */ getGroupsforChild(child); }); }); </script> @adamw helped me refine this script and showed me some more APIs I wasn't aware of. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now