1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Aggregating results from multiple modules.

Aggregating results from multiple modules.

4 posts, 0 answered
  1. Jay
    Jay avatar
    2 posts
    Registered:
    09 Oct 2008
    07 May 2009
    Link to this post
    Hello,

    We're considering using sitefinity for a project we are developing.  We've got an initial prototype working pretty well, but my boss requested something I just don't know how to simply implement.    Currently, on our project's front page, we have a BlogsPost aggregating all Blog content.  Unfortunately for me, I need something that aggregates all of everything. The front page is supposed to show the latest happenings anywhere (news, events, blogs).    What is the easiest way to do this?   I understand how to get individual events with the events manager, and I assume the methods are simliar for the news and blog modules.   would I be required to get items from each 3 programmatically?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    07 May 2009
    Link to this post
    Hello Jay,

    There is no method that you can use the get all content items from all providers. There are two possible ways that I could suggest.

    1. Create a user control where you will and NewsView, EventsView, BlogPosts controls. Then on Page_Load call ContentManager for each provider and get the items you want. You can also use sort and fiter expression if you want ot get certain items.

    2. Create a cusotm control where you are creating a list of all items.

    Sample code:

            ContentManager newsManager = new ContentManager("News"); 
            IList listofNewsItems = newsManager.GetContent(); 
            ContentManager eventsManager = new ContentManager("Events"); 
            IList listofEventsItems = eventsManager.GetContent(); 
     
     
            IList allItems = new List<IContent>(); 
            foreach (IContent content in listofNewsItems) 
            { 
                allItems.Add(content); 
            } 
            foreach (IContent content in listofEventsItems) 
            { 
                allItems.Add(content); 
            } 
            foreach (IContent content in allItems) 
            {     
                // sample for demonstration 
                Response.Write(content.UrlWithExtension + "<br />"); 
            } 


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Jay
    Jay avatar
    2 posts
    Registered:
    09 Oct 2008
    08 May 2009
    Link to this post
    Thank you very much with your reply, that did get me started very well!  I now have it grabbing the un-expired items-- published within the last number of days and now-- from any of the thre content providers concerned.  (what a mouthful!)

    However, that only appears to provide me with the Content items and Comments for each Blog Posting, News Item, or Event.  I need the titles of these things as well.  I do see that if you use the EventsManager class in addition to the code you provided me, you can get an Event by its Content ID...  I fail to see how I might obtain the container objects (if that makes any sense??)  the News and Blog posting items...  

    Secondly, I'm wondering, would there be a way to grab these items in batches? I don't want to make too may calls to the SQL database, although given the small timeframe concerned, the small number of actual blog postings, news items, or events we may actually want to display on the page, and page caching, it may not matter that much.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    08 May 2009
    Link to this post
    Hi Jay,

    You can get the titles and IDs of content items using GetMetaData() and content.ID. To access the post items from blogs you can use GetPosts()

    Sample;

    oreach (IBlog blogItem in listOfAllBlogs) 
              if(blogItem.Name == "MyBlog"
                    { 
                        Guid parentId = blogItem.ID; 
                        
                        IList allposts = blogManager.GetPosts(string.Empty, blogItem.ID) 

    Another option is creating a control that inherits from ContentView control and there override CreateDataSource(). By creating a custom datasource you can pass the items from all providers to your custom content view based control.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered