I am not sure on how to access this through the membership provider api, but can offer up an xslt extension that will provide a series of member calls.
Some of these are good, others are not so good. Pardon the use of string builder rather than building the xml document directly - something I wrote a long time ago.
[code]
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;
using System.Xml;
using umbraco.cms.businesslogic.member;
using umbraco;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Net;
using System.Web.Caching;
using System.IO;
using System.Data;
namespace bctllc.xsltext
{
class members
{
#region Member XML Methods
public static XPathNodeIterator GetMembersByGroupName(string groupName)
{
try
{
return GetMembersByGroupId(MemberGroup.GetByName(groupName).Id);
}
catch (Exception ex)
{
XmlDocument xd = new XmlDocument();
xd.LoadXml("");
return xd.CreateNavigator().Select("/response");
}
}
public static XPathNodeIterator GetMembersByGroupId(int id)
{
XmlDocument xd = new XmlDocument();
try
{
DataSet ds = SqlHelper.ExecuteDataset(
new SqlConnection(GlobalSettings.DbDSN),
CommandType.Text,
@"
Select ccx.xml
from cmsContentXml ccx
inner join cmsMember cm
on ccx.nodeId = cm.nodeId
inner join cmsMember2MemberGroup cm2mg
on cm.nodeId = cm2mg.Member
Where cm2mg.MemberGroup = @group
", new SqlParameter("@group", id.ToString()));
StringBuilder sb = new StringBuilder();
sb.AppendLine("");
try
{
DataSet ds = SqlHelper.ExecuteDataset(
new SqlConnection(GlobalSettings.DbDSN),
CommandType.Text,
@"
Select ccx.xml from cmsContentXml ccx inner join cmsMember cm on ccx.nodeId = cm.nodeId
");
StringBuilder sb = new StringBuilder();
sb.AppendLine("");
xd.LoadXml(sb.ToString());
return xd.CreateNavigator().Select("/root");
}
catch (Exception ex)
{
xd.LoadXml("");
return xd.CreateNavigator().Select("/response");
}
}
public static XPathNodeIterator GetMemberGroupsAll()
{
MemberGroup[] mga = MemberGroup.GetAll;
XmlDocument d = new XmlDocument();
XmlElement g = d.CreateElement("groups");
foreach (MemberGroup mg in mga)
{
XmlElement e = d.CreateElement("group");
XmlAttribute a = d.CreateAttribute("id");
a.Value = mg.Id.ToString();
e.Attributes.Append(a);
e.InnerText = mg.Text;
g.AppendChild(e);
}
d.AppendChild(g);
return d.CreateNavigator().Select("/groups");
}
public static XPathNodeIterator GetMemberGroupsForMember(int memberId)
{
Member m = new Member(memberId);
XmlDocument d = new XmlDocument();
XmlElement g = d.CreateElement("groups");
foreach (int i in m.Groups.Keys)
{
MemberGroup mg = new MemberGroup(i);
XmlElement e = d.CreateElement("group");
XmlAttribute a = d.CreateAttribute("id");
a.Value = mg.Id.ToString();
e.Attributes.Append(a);
e.InnerText = mg.Text;
g.AppendChild(e);
}
d.AppendChild(g);
return d.CreateNavigator().Select("/groups");
}
#endregion
Getting Members Groups From Member ID in XSLT
Hi,
I have a huge project here.
[Part 1]
The area I am stuck on and can't find any documentation on is how to retrieve what groups a user belongs too.
[Part 2]
When you use Role Based permissions.
Is there a way of iterating through the Node tree and seeing what user groups are set to what node?
I am not sure on how to access this through the membership provider api, but can offer up an xslt extension that will provide a series of member calls.
Some of these are good, others are not so good. Pardon the use of string builder rather than building the xml document directly - something I wrote a long time ago.
GetMembersByGroupName
GetMembersByGroupId
GetMembersAll
GetMemberGroupsAll
GetMemberGroupsForMember
[code]
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;
using System.Xml;
using umbraco.cms.businesslogic.member;
using umbraco;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Net;
using System.Web.Caching;
using System.IO;
using System.Data;
namespace bctllc.xsltext
{
class members
{
#region Member XML Methods
public static XPathNodeIterator GetMembersByGroupName(string groupName)
{
try
{
return GetMembersByGroupId(MemberGroup.GetByName(groupName).Id);
}
catch (Exception ex)
{
XmlDocument xd = new XmlDocument();
xd.LoadXml("");
return xd.CreateNavigator().Select("/response");
}
}
public static XPathNodeIterator GetMembersByGroupId(int id)
{
XmlDocument xd = new XmlDocument();
try
{
DataSet ds = SqlHelper.ExecuteDataset(
new SqlConnection(GlobalSettings.DbDSN),
CommandType.Text,
@"
Select ccx.xml
from cmsContentXml ccx
inner join cmsMember cm
on ccx.nodeId = cm.nodeId
inner join cmsMember2MemberGroup cm2mg
on cm.nodeId = cm2mg.Member
Where cm2mg.MemberGroup = @group
", new SqlParameter("@group", id.ToString()));
StringBuilder sb = new StringBuilder();
sb.AppendLine("");
xd.LoadXml(sb.ToString());
return xd.CreateNavigator().Select("/root");
}
catch (Exception ex)
{
xd.LoadXml("");
return xd.CreateNavigator().Select("/response");
}
}
public static XPathNodeIterator GetMembersAll()
{
XmlDocument xd = new XmlDocument();
try
{
DataSet ds = SqlHelper.ExecuteDataset(
new SqlConnection(GlobalSettings.DbDSN),
CommandType.Text,
@"
Select ccx.xml from cmsContentXml ccx inner join cmsMember cm on ccx.nodeId = cm.nodeId
");
StringBuilder sb = new StringBuilder();
sb.AppendLine("");
xd.LoadXml(sb.ToString());
return xd.CreateNavigator().Select("/root");
}
catch (Exception ex)
{
xd.LoadXml("");
return xd.CreateNavigator().Select("/response");
}
}
public static XPathNodeIterator GetMemberGroupsAll()
{
MemberGroup[] mga = MemberGroup.GetAll;
XmlDocument d = new XmlDocument();
XmlElement g = d.CreateElement("groups");
foreach (MemberGroup mg in mga)
{
XmlElement e = d.CreateElement("group");
XmlAttribute a = d.CreateAttribute("id");
a.Value = mg.Id.ToString();
e.Attributes.Append(a);
e.InnerText = mg.Text;
g.AppendChild(e);
}
d.AppendChild(g);
return d.CreateNavigator().Select("/groups");
}
public static XPathNodeIterator GetMemberGroupsForMember(int memberId)
{
Member m = new Member(memberId);
XmlDocument d = new XmlDocument();
XmlElement g = d.CreateElement("groups");
foreach (int i in m.Groups.Keys)
{
MemberGroup mg = new MemberGroup(i);
XmlElement e = d.CreateElement("group");
XmlAttribute a = d.CreateAttribute("id");
a.Value = mg.Id.ToString();
e.Attributes.Append(a);
e.InnerText = mg.Text;
g.AppendChild(e);
}
d.AppendChild(g);
return d.CreateNavigator().Select("/groups");
}
#endregion
}
}
[/code]
thanx! i was soooo in need of this!
Thanks Casey !
Once again I was stuck when I tried to parse the xml-data, but I figured it out, here's how I got info of the groups:
[code]
[/code]
(First compile the .cs to a class library and save the .dll to the bin-directory and add the extension in the xsltExtensions.config, more about that : http://umbraco.tv/documentation/books/multilingual-11-sites/5)-use-the-dictionary-with-an-xslt-extension)
is working on a reply...