Looking for DNN Object Model
Last Post 06/06/2015 2:58 PM by Joseph Craig. 5 Replies.
Author Messages
Scott
Nuke Newbie
Nuke Newbie
Posts:7


--
06/03/2015 9:10 PM  
I need to build a "Member Spotlight" module that will rotate a member each day.
Is there a simple doc that has the object model so I can figure out how to call pictures, extended profile, roles, role expiration and other basic user attributes?

Thanks!
Joseph Craig
DNN MVP
Posts:11667


--
06/03/2015 10:19 PM  
I have done something like what I think you are describing several times. Back then I used the Razor Host module. Doing it now, I would use 2sxc (sexycontent.docdplex.com).

Basically you want to get a list of users, choose the user you want to spotlight and then get that user's profile. Your module would then use whatever profile properties you plan to use for the display.

Take a look at the home page of www.investedinc.org. You will see a rotating display of people under the "Featured Board Member" heading. This actually creates a list of people and uses a jquery based rotator to change the display. You'll have to figure out how to get the "user of the day", save their userid and use it to generate the display.

One way to do that would be to store the userid in a module setting, and also store the date that user's spotlight will expire. When the module loads, you'd update an expired id, or keep it if it hasn't expired.

Here is the code that generates the display I mentioned:


@using DotNetNuke.Security.Roles
@using DotNetNuke.Entities.Users
@using DotNetNuke.Common.Utilities
@using DotNetNuke.Common
@using DotNetNuke.Entities.Profile
@using DotNetNuke.Entities.Portals
@using System.Web

@{ 
  var users = (new RoleController()).GetUsersByRoleName(Dnn.Portal.PortalId, "Board");
}

<div class="team-rotate">
	@foreach (UserInfo user in users)
	{
		<div class="teammember">
			<div class="teamheader ">
				<div class="profilephoto">
					<img  src="@GetProfileUrl(user.Profile)" alt="@GetFormattedProfileProperty(user.Profile, "AltTag", @"{0}")" />
				</div>
				<div class="organization">
					<div class="membername">@user.FirstName @user.LastName</div>
					@GetFormattedCityState(user.Profile, "<div class=\"citystate\"> ( {0} )</div>")
					<hr>
					@Server.HtmlDecode(@GetFormattedProfileProperty(user.Profile, "JobTitle", @"<div class=""jobtitle"">{0}</div>"))
				</div>
			</div>			
			@Server.HtmlDecode(@GetFormattedProfileProperty(user.Profile, "BoardBiography", "<div class=\"bio\">{0}</div>"))
            <div style="clear:both; height:0px;"></div>
	  </div>

	}
</div>

@functions {
  public static string GetProfileUrl(UserProfile profile)
  {
    string strPhotoURL = Globals.ApplicationPath + "/images/no_avatar.gif";
    ProfilePropertyDefinition objProperty = profile.GetProperty("Photo");
    if (objProperty != null &amp;&amp;
        string.IsNullOrEmpty(objProperty.PropertyValue) == false )
    {
      DotNetNuke.Services.FileSystem.FileController objFiles = new DotNetNuke.Services.FileSystem.FileController();
      DotNetNuke.Services.FileSystem.FileInfo objFile = objFiles.GetFileById(int.Parse(objProperty.PropertyValue), objProperty.PortalId);

      // There is a bug in the Photo profile property that stores the host photo 
      // in the Current Portal and not in the host portal (-1). To overcome this 
      // bug we just look in the current Portal if we can&#39;t find a photo in the Profile Portal
      if (objFile == null)
      {
        objFile = objFiles.GetFileById(int.Parse(objProperty.PropertyValue), objProperty.PortalId);
      }

      if (objFile != null)
      {
        PortalInfo objPortal = (new PortalController()).GetPortal(objFile.PortalId);
        if (objPortal != null)
        {
          strPhotoURL = string.Format("{0}/{1}/{2}", Globals.ApplicationPath, objPortal.HomeDirectory, objFile.RelativePath);
        }
      }
    }
    return strPhotoURL;
  }

  public static string GetProfileProperty(UserProfile profile, string propertyName)
  {
    ProfilePropertyDefinition objProperty = profile.GetProperty(propertyName);
    if (objProperty == null || string.IsNullOrEmpty(objProperty.PropertyValue)) return string.Empty;

    return objProperty.PropertyValue;
  }

  public static string GetFormattedProfileProperty(UserProfile profile, string propertyName, string tagformat)
  {
    string propertyval = GetProfileProperty(profile, propertyName);
    if (propertyval != string.Empty)
    {
      return string.Format(tagformat, @propertyval);
    }

    return string.Empty;
  }
  
  public static string GetFormattedCityState(UserProfile profile, string tagformat)
  {
    string theCity   = GetProfileProperty(profile, "City");
	string theState  = GetProfileProperty(profile, "Region");
    string theString = string.Empty;
	
	if( theCity != string.Empty )
	{
	  theString = theCity;
      if( theState != string.Empty )
	  {
	     theString += ", " + theState;
	  }
	  else theString = theState;
	}
    
	if (theString != string.Empty)
    {
		return string.Format(tagformat, @theString);
    }
     
    return string.Empty;
  }  
       
}



I stole a lot of this from a blog post written by Joe Brinkman. If you look around on the DNNSoftware.com site, you may be able to find it.

For the DNN API, one of the WROX books (the new DNN 7 version was published last week) might be a good place to start. There is also the "Compiled Help File" that you can download from codeplex.com where you also download DNN.

And ... do look at 2sxc to host the Razor script rather than the plain Razor Host module. It's a much better/more flexible solution.

Joe Craig, Patapsco Research Group
Complete DNN Support
Scott
Nuke Newbie
Nuke Newbie
Posts:7


--
06/04/2015 10:16 AM  
Excellent answer. Thanks very much!

One follow up....Is the DNN object model documented anywhere? It must be, but haven't found it...
Joseph Craig
DNN MVP
Posts:11667


--
06/04/2015 12:02 PM  
If you are looking for the data model for all of the "object" stored relationally in the datatables, I think that the answer is no.

The DNN developers prefer that people use the API as it relates to the business level opjects, and avoid the details in the database. Mainly that is because the business objects are more likely to remain unchanged whereas the data tables are occasionally (at least more than the business objects) reorganized. The business objects may have additional attributes going forward ...

So, if you stick with the DotNetNuke.Entities.XXX namespaces and the classes and methods found there, you're safer ... at least as far as upgrades go. The best documentation for those is in the compiled help files I mentions.

Joe Craig, Patapsco Research Group
Complete DNN Support
Scott
Nuke Newbie
Nuke Newbie
Posts:7


--
06/06/2015 1:28 AM  
Cool, but I've been all over CodePlex and haven't found the Compiled Help File. Do you have a link or hint where it might be?
Thanks
Joseph Craig
DNN MVP
Posts:11667


--
06/06/2015 2:58 PM  
Go to http://dotnetnuke.codeplex.com/, click on the Downloads link, and then select your version of DNN. You will find several downloads with every version of DNN. You want the "Core API Help File."

Joe Craig, Patapsco Research Group
Complete DNN Support


---