Search code examples
dotnetnuke2sxc

How can I get a list of pages where a View is in use?


I have a large site using the Content App and we have a wide variety of Views. In both testing and development we increasingly need to know what pages a View is in use. As I said, the site is large, well past 500 pages, knowing what page a View got used on is beyond impossible.

Is there some way to in 2sxc to figure this out? A feature I am not aware of? Debugging? Insights? I am willing to do it in code in a View. I was thinking it could be solved by doing a partial...

if(IsSuperUser(Dnn.User)) {
  @RenderPage("_Debug_ListPagesUsingThisView.cshtml")
}

I am having trouble understand how or where to start. Is there a way to get to the Entity (record) of the View from within a view? Once I have that, is there a path to get to the app's module settings? where is the info actually stored that tells the App what View to use? And can I get to it?

  • DNN 9.03.02
  • 2sxc 10.9.1
  • Content App 3.03.x

ADDITIONS Continuing from the comment chain below...

I can't get any further yet, the Entity I get returned from foreach(... .Parents()) has the following fields: Template, Content, Presentation, ListContent, and ListPresentation ... but I cannot figure out how to get any data or fields out of it. Though myEntity.Content.Count (and .Template.) shows 1, any attempt to access it beyond GetType() (its a list of Dynamic Entities) returns a null. Which seems odd.

Do you know what the Entity type actually is and how to use it? The interesting thing is that the count from .Parents() returns the same number of items as in the Content-Type assigned for this View, but when I look in the (SQL) data, they are a different EntityId than the actual Content (e.g. if I trace parent EntityId 3344 I find that nearby EntityId 3343 is one of the Content-Type records this View is displaying somewhere). So thats an interesting clue. Ideas?


Solution

  • Ok, I finally created my own code - and yes, it was hard!!! Took me at least 5 hours to get everything to work - you owe me a LOT of beers ;)

    I made it as part of the DNN tutorial in a miscellaneous section:

    https://2sxc.org/dnn-tutorials/en/razor/2sa110/page

    have fun!

    here an extract of the code I needed to write - lots of LINQ

    
      // create a map of all blocks to DNN modules
      var block2ModuleMap = contentBlocks.GroupJoin(allMods, 
        cb => cb.EntityGuid,
        m => TryParseGuid(m.ModuleSettings[SettingsCG]),
        (cb, m) => new { 
          Block = cb, 
          Modules = m 
        }
      );
    
      // now map all the template-IDs to the block-module map
      var template2BlockModuleMap = block2ModuleMap.GroupBy(b2m => {
        var templates = AsList(b2m.Block.Template as object);
        return templates.Any() ? templates.First().EntityGuid : null;
      });
    
      var viewsWithBlocks = views.GroupJoin(template2BlockModuleMap,
        v => v.EntityGuid,
        bwm => bwm.Key,
        (v, bwm) => {
          var blockWithMod = bwm.SingleOrDefault();
          return new { 
            View = v, 
            Blocks = blockWithMod,
            ModsCount = blockWithMod != null ? blockWithMod.SelectMany(bmlist => bmlist.Modules).Count() : 0,
          };
        }
      );