Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
I havent used page objects if thats what you are doing? But if you are using a regular object stored in DDS you could just fire a LINQ query to get the top 10 ratings (Take(10), orderby).
Hi Niklas!
I depends a little on how you store the ratings. If you use the "PageObjects"-mechanism, then there is currently no easy way to query for pageobjects for a set of pages.
But, if you manage the "connection to the page" yourself, for example by using a PageID property in your Rate-class, then you could use some clever LINQ-queries to retrieve for example the top 5 rated pages.
Consider for example a Rate-class like this:
public class PageRate
{
public int PageID { get; set }
public int Rate { get; set; }
public DateTime Rated { get; set; }
public string RatedBy { get; set; }
}
(Each rating would be stored as a single instance of the above class).
Now, using a groupby-LINQ-query, the top 5 rated pages could be retrieved in "one stroke" like so:
var query = from pageRate in pageRateStore.Items<PageRate>()
group pageRate by pageRate.PageID into g
orderby g.Average(i=>i.Rate) descending
select new { PageID = g.Key, AvgRate = g.Average(i=>i.Rate) };
foreach( var pageRate in query )
{
Response.Write(String.Format("{0}:{1}<br>", pageRate.PageID, pageRate.AvgRate));
}
Unfortunately there is a bug that wont let you add a ".Take(5)" to the groupby-query to just retrieve the top 5
pages, i.e. something like this:
foreach( var pageRate in query.Take(5) )
I'll have a look into this bug, I guess it's quite easy to fix and hopefully will make it into the first servicepack.
Regards,
Johan Olofsson
Thanks alot for an excellent explanation/example! And yes, I was using the PageObject-mechanism.
If I use the Dynamic Data Store to store, lets say, page ratings; is there any way I can retrieve a list of all pages that have been rated (for example, if I wanted to show a "highest rated pages" function? In other words, what I'm looking for is something along the lines of PageDataCollection pdc = EPiServer.Data.Dynamic.InsertMagicClassHere.GetPagesThatReference<MyRatingClass>();
Brgds/Niklas