Articles

Current Articles | Archives | Search

Wednesday, April 01, 2009
How-To Create a Page Last Updated Plug-In
By itlackey @ 12:41 AM :: 964 Views :: 0 Comments :: Article Rating :: DotNetNuke, How-To's, Products
 

Adding a Plug-In to the Page Last Updated module is a typically a very simple process that only requires a few lines of code. The process may become more complex depending on the module you are interfacing with. For our example we decided to interface with the DotNetNuke Announcements module which turned out to be a very simple process. Though this process does assume that you have a working knowledge of writing custom .Net code. If you do not fall into this category but need to have a module supported that is not currently included please feel free to post a suggestion to include the module in the Feedback section of this site.

There are a few general steps in creating a Page Last Updated Plug-In:

  1. Create a Class Library project.
  2. Reference the ITLackey.Modules.PageLastUpdated.Interfaces.dll that is included in the module install package.
  3. Create a class that implements the IDateCommand interface in that DLL.
  4. Build your class library.
  5. Upload the DLL generated by your project using the "Manage Commands" page within the Page Last Updated module.

Let's look at this process in more detail. Again we are assuming that you have an understanding of how to complete steps one, two and four so we will skip over these steps and begin on to step three.

Step 3. Implementing the IDateCommand interface:

The IDateCommand interface is a very simple interface that contains two members:

The ModuleName property simply returns a hardcoded string that describes the module you are interfacing with. In this case the property looks like this:

All of the magic happens in the GetDate function. In this case we have created a LINQ to SQL diagram that we will be referencing inside of this function. The diagram contains three tables: TabModules, Modules and Announcements. *Please note that you are not required to use LINQ to SQL we just found that it was much easier for us to do so. You may use which ever form of data access code you prefer.

Now we could move on to completing the GetDate function of the IDateCommand interface. Here is what the code looks like:

If you are not familiar with LINQ this may be a little confusing, so we will break it down. Basically we are grabbed all instances of the Annoucements module on the current page (based on the tabId parameter), sorting them in descending order based on the CreatedDate field and selecting the CreatedDate for the top (or newest) record. The query gets a little complex because we have to join the TabModules table to the Annoucements table in order to filter the Annoucements record by TabId. This is due to the underlying DotNetNuke datastructure. You will find that this will be necessary for the majority of the Plug-In's you create. If you do not join the TabModules table you will not be able to filter the modules by the current page. Other than that, the query is pretty simple and the same concept will be used in pretty much all other Plug-In's. Query for all instances on the current page, sort them in descending order based on the "Last Modified" date column and grab the top record. Once you have done that simply return the result. Notice that the return value of the function is a Nullable Date. This means that if you do not find a matching record, you can return "Nothing" and the Page Last Updated module will simply not include it in the calculation.

Step 5. Adding your Plug-In to the Page Last Updated Module

Once you have compiled your project you will need to upload the DLL file in the "Upload Assemblies" section of the "Manage Commands" page of the Page Last Updated Module. To do this, log into the portal using a SuperUser account such as host. Select the "Manage Commands" option from the module menu:

On this page you can browse your local computer for the compiled DLL file and the click the "Upload Assembly" button:

If the DotNetNuke installtion is configured for Full-Trust, the module will automatically find all of the classes that implement the IDateCommand and add them to the configuration for the module. In a Medium-Trust installation you will need to manually add the classes to the configuration. This is done by clicking the "Add Command To Assembly" button under the newly installed assembly. A textbox will appear for you to paste in the "Assembly Qualified Name" of the class that implements the IDateCommand interface. Click the "Add Command" button and you are done!

That is all there is to it, you can intergrate virtually any module into the calculation of the last updated time for any page in your DotNetNuke portal in just a few steps! Obviously this is a feature directed at developers, and was created to allow module developers to include their custom modules into the calculation. We do plan on providing more Plug-In's to cover the majority of the modules provided by the DotNetNuke team and some other popular third-party modules. So keep an eye on our site to stay updated on which Plug-In's we have published. Also, remember if there is a Plug-In you would like to have us create please post a suggestion in the Page Last Updated section of our Feedback page. 

Comments
Only registered users may post comments.
        
Google Ads
        
Terms Of Use|Copyright 2006 by Digital Snap Inc. |Privacy Statement