2
votes

I have build a module in DotNetNuke 6 that contains multiple module definitions. A module can be added on multiple pages (tabs) and multiple module can be added to one page (tab). Problem is that I can't find an identifier that ties all my module definitions together from one instance.

DesktopModuleId is only unique for every module installed (not per instance and page).

ModuleId is unique for every module instance and definition.

TabModuleId is unique for every module instance and tab and definition.

So what I'm looking for is a way to identify which module definitions belong to each other the moment I put a module on the page.

I found a forum post which explains the same problem and someone suggested to look at the ModuleId for every definition and check if they are sequential. I find that very hackies.

Edit:
The module I'm developing contains a number of different definitions, but let's say we have 3 (view, edit and settings). When I install the module I have to set a category I'm gonna use for the module, say I want it to be a blog module. All 3 definitions will then get data from the database with their same unique id (supposedly). Now I install again the same module, I want to choose another category (portfolio) and only get that data. The way DNN works now, I can't separate my blog items from my portfolio items as there's no way to know that my 3 blog definitions belong to each other and are separate of the other 3 portfolio definitions. I hope this make sense...

3
jerone - Not sure I quite understand. You want to know what the module is or the definition or what?? - braindice
I want the unique id from a module on a page. Problem is that I can't use TabModuleId, because that's unique for every module definition I have. - jerone
I think we're going to need a fuller discussion of what your overall goal is. I'm not seeing the context in which this ID (if it exists) means something, and in what context you'd make use of it. Hope we can help figure out a workable solution for you. - bdukes
@bdukes - Updated post with my current situation. - jerone

3 Answers

1
votes

If DesktopModuleId is separate for each module, then they are in no way related according to DNN. There's a small chance that the PackageId of the DesktopModule would relate them, but I haven't seen a way to install multiple desktop modules in the same package (and package is the highest level of containment for functionality).

It sounds like you want all of your module definitions to be contained in one desktop module. In the manifest used to install the module, make sure there's only one package element and only one component[type="Module"] element. Inside of that component element, have a moduleDefinition for each piece of the module. Then, the single module will be available to be added to the page, and each piece will be included when you do that (you're free to delete any pieces that you don't need).

1
votes

I dont know what you wanna reach exactly. But I got problems, too if I tried to place a module more then one time on the same page and keep it "unique".

In my case I tried to setup different modulesettings and react different on Page_Load() on this settings.

I decided to use a

Session["8400f2b6-d930-47af-a524-fc16721b4591"] = new List<KeyValuePair<int, string>>();

The GUID will help me keeping the Session unique. The List<> will store my special settings with ModuleID, mySpecialSetting.

maybe this will help you getting special module information unique if you place one module more than one time on the same page.

best regards, noone.

0
votes

I solved my own question with the code below. It's not the preferred solution, but I had success using it and it will do until DNN implements a real solution.

All methods from the Controller class connect a custom table in the database. The code checks for all module definitions if they are on the current page (tab) and not already in the db. If not it will add it to the db combined with a new instance id. If 2 or more of the same modules are added to the page and this code runs later (e.g. update), it will only get the module ids that are sequential (the other module ids will be added later).

ModuleInstanceId = Controller.GetModuleInstanceId(TabModuleId);
if (ModuleInstanceId == -1)
{
    Dictionary<Int32, String> ModuleInstanceDefinitions = new Dictionary<Int32, String>();
    Dictionary<String, ModuleDefinitionInfo> ModuleDefinitions = new ModuleController().GetModule(ModuleId).DesktopModule.ModuleDefinitions;
    foreach (ModuleDefinitionInfo ModuleDefinition in ModuleDefinitions.Values)
    {
        List<ModuleInfo> Modules = new ModuleController().GetModulesByDefinition(PortalId, ModuleDefinition.FriendlyName).ToList<ModuleInfo>();
        foreach (ModuleInfo Module in Modules)
        {
            if (Module.TabID == TabId)
            {
                if (Controller.GetModuleInstanceId(Module.TabModuleID) == -1 || Controller.GetModuleInstanceId(ModuleDefinition.FriendlyName) == -1)
                {
                    ModuleInstanceDefinitions.Add(Module.TabModuleID, ModuleDefinition.FriendlyName);
                }
            }
        }
    }

    // Probably shouldn't be more then specified in the manifest;
    // Only situatie this could occure is when the module is added to a page twice at the same page;
    ModuleInstanceDefinitions = ModuleInstanceDefinitions.OrderBy(ModuleDefinition => ModuleDefinition.Key).Take(ModuleDefinitions.Count).ToDictionary(Item => Item.Key, Item => Item.Value);

    ModuleInstanceId = Controller.SetModuleInstances(ModuleInstanceDefinitions);
}

Hopefully someone will find this useful or DNN will add it in the source :)