views:

884

answers:

3

The only method provided by the DNN framework to get a module by ID also required a tab ID. What can I do if I don't have a tab ID?

+3  A: 

The GetModule method off of the DotNetNuke.Entities.Modules.ModuleController class will accept a "null" value for tab ID if you don't have a tab ID. That is, try the following:

new ModuleController().GetModule(moduleId, DotNetNuke.Common.Utilities.Null.NullInteger)

See also my blog post on the subject.

bdukes
A: 

Brian, I just took a look at the code for GetModule(), and there isn't any specific VB code in the framework that checks for the tabid being null. What's interesting though is that the stored procedure that is part of the SqlDataProvider selects rows from the Modules view that have a matching moduleid, no matter what tabid is...

ALTER PROCEDURE [dbo].[dnn_GetModule]

    @ModuleId int,
    @TabId    int

AS
SELECT  * 
FROM dbo.dnn_vw_Modules
WHERE   ModuleId = @ModuleId
AND     (TabId = @TabId or @TabId is null)

If I understand this correctly, this would return all the rows where moduleid is the one you specified, no matter if @tabid is null or not. That makes the @TabId rather pointless, don't you think?

Rafe
First, in the SqlDataProvider, it calls GetNull() on the TabId parameter, which will translate Null.NullInteger to DBNull
bdukes
Secondly, the where statement returns rows where 1) the module ID's match and 2) either the Tab IDs match or that tab ID is null. Therefore, if you provide a Tab ID, it must match, if you provide null, it returns all rows.
bdukes
You're right. My brain interpreted @TabId for TabId, in the second half of the OR portion of the query.
Rafe
+1  A: 

One thing to watch out for when passing a null TabId to GetModule is that if you have a module that's installed on a number of different tabs, you'll be getting the first one back, so the values for TabId, TabModuleId and ModuleOrder will be based on that first instance, which may or may not be the instance you wanted.

HTH,

Don

Don Worthley