Forum statistics
The forums provide statistics about the following:
- Last post in a forum/thread
- Last user that has posted in a forum/thread
- Count of posts in a thread/forum
- Amount of views of a thread
The statistics can be accessed through the respective properties of the For developers: Forums and the For developers: Forum threads object.
These statistics get automatically updated upon creating, modifying or deleting threads or posts.
Manual statistics calculation
If you are importing large set of data through the Forums API, you can suppress the automatic calculation and execute it manually after the data import is done. To do this you must perform the following:
-
Get the manager.
Get an instance of theForumsManagerobject. -
Create the forums data.
-
Suppress the automatic calculation.
To suppress the automatic calculation, call theSuppresStatisticsCalculationmethod of the manager before calling theSaveChangesmethod. -
Save the changes.
Save the changes to the manager. -
Update the statistics.
To update the statistics, you call the staticRecalculateAllForumStatisticsmethod of theForumsManagerclass. This call will cause the statistics for all forums and threads to get updated.NOTE: If you want to update the statistics only for a specific forum or thread, you call the
UpdateForumStatisticsmethod or theUpdateThreadStatisticsmethod of theForumsManagerinstance and pass the respective forum or thread ID as an argument. Note that when calling one of these methods, you must save the changes at the end.
Here is a code example for the RecalculateAllForumStatistics method:
using System;
using Telerik.Sitefinity.Forums;
namespace SitefinityWebApp
{
public class ForumStatistics_UpdateForumStatistics
{
public void UpdateForumStatuistics(Guid forumId)
{
ForumsManager forumManager = ForumsManager.GetManager();
forumManager.UpdateForumStatistics(forumId);
forumManager.SaveChanges();
}
public void UpdateThreadStatuistics(Guid threadId)
{
ForumsManager forumManager = ForumsManager.GetManager();
forumManager.UpdateThreadStatistics(threadId);
forumManager.SaveChanges();
}
}
}