Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
namespace OrchardCoreContrib.ViewCount.Handlers;

/// <summary>
/// Defines methods for handling view count events for content.
/// </summary>
public interface IViewCountContentHandler
{
/// <summary>
/// Occurs before the content is viewed.
/// </summary>
/// <param name="context">The <see cref="ViewCountContentContext"/> that identifies the content to record the view for. Cannot be
/// <c>null</c>.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
Task ViewingAsync(ViewCountContentContext context);

/// <summary>
/// Occurs after the content is viewed.
/// </summary>
/// <param name="context">The context containing information about the content whose view count should be updated. Must not be
/// <c>null</c>.</param>
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns>
Task ViewedAsync(ViewCountContentContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

namespace OrchardCoreContrib.ViewCount.Handlers;

/// <summary>
/// Represents a content context that includes a count of items within a collection.
/// </summary>
/// <remarks>Use <see cref="ViewCountContentContext"/> to associate a specific item of content with a count value,
/// such as the number of times the content has been viewed or the number of related items.</remarks>
public class ViewCountContentContext(ContentItem contentItem, int count) : ContentContextBase(contentItem)
{
/// <summary>
/// Gets or sets the number of items contained in the collection.
/// </summary>
public int Count { get; set; } = count;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
namespace OrchardCoreContrib.ViewCount.Handlers;

/// <summary>
/// Provides a base implementation for handling view count events for content items.
/// </summary>
public abstract class ViewCountContentHandlerBase : IViewCountContentHandler
{
/// <inheritdoc/>
public virtual Task ViewingAsync(ViewCountContentContext context) => Task.CompletedTask;

/// <inheritdoc/>
public virtual Task ViewedAsync(ViewCountContentContext context) => Task.CompletedTask;
}
9 changes: 9 additions & 0 deletions src/OrchardCoreContrib.ViewCount/Models/ViewCountPart.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
using OrchardCore.ContentManagement;

namespace OrchardCoreContrib.ViewCount.Models;

/// <summary>
/// Represents a content part that tracks the number of times an item has been viewed.
/// </summary>
/// <remarks>Use <see cref="ViewCountPart"/> to associate a view count with content items, enabling features such
/// as analytics or popularity tracking.</remarks>
public class ViewCountPart : ContentPart
{
/// <summary>
/// Gets or sets the number of items contained in the collection.
/// </summary>
public int Count { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Authors>The Orchard Core Contrib Team</Authors>
<Company />
<Description>Allows to count the content item views.</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>BSD-3-Clause</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/OrchardCoreContrib/OrchardCoreContrib.Modules/tree/main/src/OrchardCoreContrib.ViewCount/README.md</PackageProjectUrl>
<RepositoryUrl>https://github.com/OrchardCoreContrib/OrchardCoreContrib.Modules</RepositoryUrl>
Expand All @@ -26,6 +27,7 @@

<ItemGroup>
<None Include="../../images/icon.png" Pack="true" PackagePath="icon.png" />
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
Expand Down
42 changes: 42 additions & 0 deletions src/OrchardCoreContrib.ViewCount/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# View Count Module

This module provides settings and services to send SMS messages using Azure Communication Service.

## Version

1.0.0

## Category

Content Management

## Dependencies

| Product | Module |
|-------------|-----------------------------------|
| OrchardCore | Contents (`OrchardCore.Contents`) |

## Features

| | |
|------------------|--------------------------------------------|
| **Name** | View Count (`OrchardCoreContrib.ViewCount`)|
| **Description** | Allow you to send SMS via ACS SMS service. |
| **Dependencies** | `OrchardCore.Contents` |

## NuGet Packages

| Name | Version |
|---------------------------------------------------------------------------------------------------------|---------|
| [`OrchardCoreContrib.ViewCount`](https://www.nuget.org/packages/OrchardCoreContrib.ViewCount/1.0.0) | 1.0.0 |

## Get Started

1. Install the [`OrchardCoreContrib.ViewCount`](https://www.nuget.org/packages/OrchardCoreContrib.ViewCount/) NuGet package to your Orchard Core host project.
2. Go to the admin site
3. Select **Configuration -> Features** menu.
4. Enable the `View Count` feature.
5. Go to the **Contents -> Content Definitions -> Content Types**
6. Edit the content type that you want to track its number of views.
7. Click the `Add Part` button.
8. Choose `View Count` from the list.
16 changes: 16 additions & 0 deletions src/OrchardCoreContrib.ViewCount/Services/IViewCountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

namespace OrchardCoreContrib.ViewCount.Services;

/// <summary>
/// Defines methods for retrieving and recording view counts for content items.
/// </summary>
/// <remarks>Implementations of this interface provide functionality to track how many times a content item has
/// been viewed and to record new views. This is typically used for analytics, popularity metrics, or display purposes
/// in content management scenarios.</remarks>
public interface IViewCountService
{
/// <summary>
/// Returns the total number of views recorded for the specified content item.
/// </summary>
/// <param name="contentItem">The content item for which to retrieve the view count. Cannot be <c>null</c>.</param>
/// <returns>The number of times the specified content item has been viewed. Returns 0 if no views have been recorded.</returns>
int GetViewsCount(ContentItem contentItem);

/// <summary>
/// Increments the views number for the specified content item asynchronously in the current view context.
/// </summary>
/// <param name="contentItem">The content item to be displayed. Cannot be null.</param>
/// <returns>A task that represents the asynchronous display operation.</returns>
Task ViewAsync(ContentItem contentItem);
}
10 changes: 10 additions & 0 deletions src/OrchardCoreContrib.ViewCount/Services/ViewCountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@

namespace OrchardCoreContrib.ViewCount.Services;

/// <summary>
/// Provides functionality for tracking and updating view counts on content items.
/// </summary>
/// <remarks>The <see cref="ViewCountService"/> enables retrieval and incrementing of view counts for content
/// items. It coordinates with registered <see cref="IViewCountContentHandler"/> instances to allow custom logic to be
/// executed before and after a view is recorded. This service is typically used to monitor content popularity or
/// engagement.
/// </remarks>
public class ViewCountService(
IContentManager contentManager,
IEnumerable<IViewCountContentHandler> handlers,
ILogger<ViewCountService> logger) : IViewCountService
{
/// <inheritdoc/>
public int GetViewsCount(ContentItem contentItem)
{
Guard.ArgumentNotNull(contentItem, nameof(contentItem));
Expand All @@ -21,6 +30,7 @@ public int GetViewsCount(ContentItem contentItem)
return viewCountPart?.Count ?? 0;
}

/// <inheritdoc/>
public async Task ViewAsync(ContentItem contentItem)
{
Guard.ArgumentNotNull(contentItem, nameof(contentItem));
Expand Down
Loading