Custom Module - Adding a html module to the database

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
7/7/2010 6:13:07 AM
Gravatar
Total Posts 15

Custom Module - Adding a html module to the database

Hi

I am using Mojo (version 2310) for an online learning resource. One of the activities we want the students to do is to fill out a form and then to post a link to it on a forum to discuss.

I would like to do this by creating a custom module that allows the students to fill out the form, when they submit the form a html module is created and added to the database. I will then have another custom module that will display the html module (based on the module id).

My code to create and submit the html module would be something like:

protected void SubmitBtn_Click(object sender, EventArgs e)
{
   CreateHtmlModule();
}
protected void CreateHtmlModule()
{
  try
  {
    SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();
    // get the moduledefid
    int moduleDefID = 1;
    // get the module definition
    ModuleDefinition moduleDefinition = new ModuleDefinition(moduleDefID);
    // create module
    mod = new Module();
    mod.SiteId = siteSettings.SiteId;
    mod.SiteGuid = siteSettings.SiteGuid;
    mod.ModuleDefId = moduleDefID;
    mod.FeatureGuid = moduleDefinition.FeatureGuid;
    mod.Icon = moduleDefinition.Icon;
    mod.CacheTime = moduleDefinition.DefaultCacheTime;
    mod.ModuleTitle = "Documentation Template";
    mod.PaneName = "contentPane";
    mod.AuthorizedEditRoles = "Admins";
    mod.CreatedByUserId = SiteUtils.GetCurrentSiteUser().UserId;
    mod.Save();
    UpdateModule();
  }
  catch (Exception ex)
  {
    // write out the error
  }
}
protected void UpdateModule()
{
  try
  {
    HtmlContent html = new HtmlContent(mod.ModuleId);
    html.BeginDate = DateTime.UtcNow;
    html.EndDate = DateTime.UtcNow.AddYears(20);
    html.Body = "<p>Hello There</p>";
    html.LastModUserGuid = SiteUtils.GetCurrentSiteUser().UserGuid;
    html.ModuleGuid = mod.ModuleGuid;
    html.LastModUtc = DateTime.UtcNow;
    html.Save();
  }
  catch (Exception ex)
  {
    // write out the error
  }
}

Would this work or will I muck everything up?

Many Thanks

Tracey

7/8/2010 7:08:45 AM
Gravatar
Total Posts 18439

Re: Custom Module - Adding a html module to the database

Hi Tracey,

The only error I see in your code is that you are not assigning a pageid for the module so it will not appear on any page.

I really don't want to forbid you from doing this kind of thing, but I'm not wild about it. I think features should be self contained and not really depend on or orchestrate other features, so I would not be drawn to doing this kind of thing myself, but if it meets your goal and at least your custom code is separate from mojo code then I guess it is ok. But this is not a way the Html module is expected to be used from my point of view.

Best,

Joe

7/8/2010 7:17:13 AM
Gravatar
Total Posts 15

Re: Custom Module - Adding a html module to the database

Hi Joe

Many Thanks for your speedy response. I do see what you mean about keeping features self contained and must admit that doing it this way doesn't sit that well. I just thought it might be neater than creating a new custom table to house the student submissions in. I will have a think.

Thanks again Joe much appreciated 

You must sign in to post in the forums. This thread is closed to new posts.