PageType Usage Plugin with Recent Pages for each PageType
To get more insight in the production environment of the client, we needed some information on the usage of PageTypes and the number of pages for each PageType. Further, in case of troubleshooting or support we needed a way to quickly retrieve the URL of a page for a given PageType. The simplest approach was to build a small admin plugin that summarizes this information in an extensive but generic way without the need to look up or manually query for certain pages. This post will show you how the plugin was set up and what the end result looks like.
The main part of the plugin is a GuiPlugin that targets the PlugInArea.AdminMenu. I’ll show you how the page layout was setup and how the code behind looks like. Further we need a few helper classes that retrieve the actual data from the EPiServer database.
Let’s start with the end result. I’ve used the AlloyTech templates for this demo. Below you’ll see two screenshots. The first displays the statistics for each PageType and the second displays the page URLs for each PageType.
Figure 1: Page Type statistics
Figure 2: Recent pages for each PageType
Now you’ve seen the end result, we’ll get into how this plugin is created. We’ll start with the page layout first.
The page layout consists of a TabStrip with two Tabs. We’ll use the first tab for the statistical part and the second tab for the page URLs part. In order to get the Tabs working we’ll need two Panels. The first panel, for our statistical part, uses a GridView with four columns for PageTypeId, PageTypeName, the number of pages, and the number of work pages. Of course the amount of information of each PageType could be extended, but for now this already provides some insight in the way PageTypes are being used in the production environment.
The second part lists the most recent pages for each PageType. We’ll construct the complete listing from code behind which will be places in the PageUrlsLiteral. Building html from a code behind of course is never the best approach, but it’ll do for now. I’ll get into the page URLs in more detail later on.
Plugin code behind
The second part is setting up our code behind for the GuiPlugin.
There is probably more in depth information available on how to set up a GuiPlugin, so I won’t be covering all the basics here but I’ll try to keep this short. Limited to five steps actually.
- First you add the GuiPlugin attribute on the class.
- In the OnPreInit method you assign the correct masterpage.
- In the OnInit method we’ll limit access to the plugin to edit rights.
- The BindPageTypes method is called from the OnLoad method and retrieves the data and assigns the data to the GridView.
- The GetPageUrls method retrieves the data for our second tab, the actual URLs for the pages. This retrieves a collection, iterates over the results and build the html for our list which is then assigned to our literal placeholder.
While our GuiPlugin has been set up with these five steps, we still need to cover the actual retrieval of the data required for the PageType information we want to expose.
Query the database
There are three basic queries needed to retrieve all the information needed. The three queries are mentioned below.
The first query ‘SqlPageTypeUsage’ selects the information from tblPage and tblPageType and groups this on PageType. At this point we have most of the information on the first tab, the statistical information.
Further the information is extended with the number of workPages. The second query ‘SqlCountWorkPages’ will retrieve this information from tblWorkPage.
The third query ‘SqlTop10PagesByPageType’ retrieves the top 10 pages from tblPage on the given PageType. I’ve ordered this on the Page ID, since the most recent pages will have the newest ID. Of course you could order it on change date or publish date of the page version, but at this point ordering on ID gives us a good enough insight in the recent pages.
Next we defined three simple objects to hold the data which we can use in our plugin. These are PageTypeUsage which will hold the statistical tab, PageUrlByPageType and PageUrls to hold the recent pages for each PageType.
Retrieve the data
The next part is the method GetPageTypeUsage which executes the SQL statement and parses en returns the results. We check if the PageType has a filename and exclude the sysrecylebin and sysroot. Further we call the SQL statement to count the number of WorkPages.
Finally to retrieve the pages for each PageType we also execute the SQL statement and return the results. The first is similar to the above code when retrieving the PageTypes. For each PageType we call the GetTop10PagesByPageType method that collects the recent pages for the PageType. For each retrieved Page we also need to construct the absolute URL. In the method ‘GetUrlFromPageId’ we take in a page id and convert that to the absolute URL of the page.
That’s it. In the above post I’ve explained the use of the plugin and how you can develop it. This plugin has proven to be very useful in support for any client question on pages, and for debugging purposes as well. This plugin provides a good insight in the way your editors are using the defined PageTypes and how they use them to create pages. Hopefully this post has helped you to understand the basics and explained the use of it in everyday production environments.