Skip to content

Commit 6725787

Browse files
committed
Add OCC.ViewCount module
1 parent 7f33b0e commit 6725787

17 files changed

Lines changed: 223 additions & 2 deletions

OrchardCoreContrib.Modules.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCoreContrib.ContentP
7272
EndProject
7373
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCoreContrib.ContentPermissions.Tests", "test\OrchardCoreContrib.ContentPermissions.Tests\OrchardCoreContrib.ContentPermissions.Tests.csproj", "{2E878DD9-9D64-4EDF-A47C-7EBD71377AF0}"
7474
EndProject
75+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCoreContrib.ViewCount", "src\OrchardCoreContrib.ViewCount\OrchardCoreContrib.ViewCount.csproj", "{330877B1-7BE6-4B57-8714-2DADE1C53563}"
76+
EndProject
7577
Global
7678
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7779
Debug|Any CPU = Debug|Any CPU
@@ -186,6 +188,10 @@ Global
186188
{2E878DD9-9D64-4EDF-A47C-7EBD71377AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
187189
{2E878DD9-9D64-4EDF-A47C-7EBD71377AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
188190
{2E878DD9-9D64-4EDF-A47C-7EBD71377AF0}.Release|Any CPU.Build.0 = Release|Any CPU
191+
{330877B1-7BE6-4B57-8714-2DADE1C53563}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
192+
{330877B1-7BE6-4B57-8714-2DADE1C53563}.Debug|Any CPU.Build.0 = Debug|Any CPU
193+
{330877B1-7BE6-4B57-8714-2DADE1C53563}.Release|Any CPU.ActiveCfg = Release|Any CPU
194+
{330877B1-7BE6-4B57-8714-2DADE1C53563}.Release|Any CPU.Build.0 = Release|Any CPU
189195
EndGlobalSection
190196
GlobalSection(SolutionProperties) = preSolution
191197
HideSolutionNode = FALSE
@@ -218,6 +224,7 @@ Global
218224
{BE64AA1E-DDEF-405E-9004-6FF984DA6D71} = {A239BFB0-9BA7-467C-AD41-405D0740633F}
219225
{0BDB5C64-D4C3-454E-A54D-5F5A2169213B} = {C80A325F-F4C4-4C7B-A3CF-FB77CD8C9949}
220226
{2E878DD9-9D64-4EDF-A47C-7EBD71377AF0} = {A239BFB0-9BA7-467C-AD41-405D0740633F}
227+
{330877B1-7BE6-4B57-8714-2DADE1C53563} = {C80A325F-F4C4-4C7B-A3CF-FB77CD8C9949}
221228
EndGlobalSection
222229
GlobalSection(ExtensibilityGlobals) = postSolution
223230
SolutionGuid = {48F73B05-7D3D-4ACF-81AE-A98B2B4EFDB2}

src/OrchardCoreContrib.Modules.Web/OrchardCoreContrib.Modules.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<ProjectReference Include="..\OrchardCoreContrib.Tenants\OrchardCoreContrib.Tenants.csproj" />
3131
<ProjectReference Include="..\OrchardCoreContrib.Themes.Admin\OrchardCoreContrib.Themes.Admin.csproj" />
3232
<ProjectReference Include="..\OrchardCoreContrib.Users\OrchardCoreContrib.Users.csproj" />
33+
<ProjectReference Include="..\OrchardCoreContrib.ViewCount\OrchardCoreContrib.ViewCount.csproj" />
3334
</ItemGroup>
3435

3536
</Project>

src/OrchardCoreContrib.Modules.Web/Recipes/OCC.recipe.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
"OrchardCoreContrib.Html",
2626
"OrchardCoreContrib.HealthChecks",
2727
"OrchardCoreContrib.Liquid",
28-
"OrchardCoreContrib.Users.Impersonation",
2928
"OrchardCore.Roles",
30-
"OrchardCore.Users",
3129
"OrchardCoreContrib.System",
30+
"OrchardCore.Users",
31+
"OrchardCoreContrib.Users.Impersonation",
32+
"OrchardCore.ViewCount",
3233
"TheTheme"
3334
]
3435
},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using OrchardCore.ContentManagement.Display.ContentDisplay;
2+
using OrchardCore.ContentManagement.Display.Models;
3+
using OrchardCore.DisplayManagement.Views;
4+
using OrchardCoreContrib.ViewCount.Models;
5+
using OrchardCoreContrib.ViewCount.Services;
6+
using OrchardCoreContrib.ViewCount.ViewModels;
7+
8+
namespace OrchardCoreContrib.ViewCount.Drivers;
9+
10+
public sealed class ViewCountPartDisplayDriver(IViewCountService viewCountService) : ContentPartDisplayDriver<ViewCountPart>
11+
{
12+
public override IDisplayResult Display(ViewCountPart part, BuildPartDisplayContext context) => Initialize<ViewCountPartViewModel>(GetDisplayShapeType(context),
13+
async model =>
14+
{
15+
await viewCountService.ViewAsync(part.ContentItem);
16+
17+
model.Count = part.Count;
18+
}).Location("Detail", "Content:10");
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace OrchardCoreContrib.ViewCount.Handlers;
2+
3+
public interface IViewCountContentHandler
4+
{
5+
Task ViewingAsync(ViewCountContentContext context);
6+
7+
Task ViewedAsync(ViewCountContentContext context);
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using OrchardCore.ContentManagement.Handlers;
2+
using OrchardCore.ContentManagement;
3+
4+
namespace OrchardCoreContrib.ViewCount.Handlers;
5+
6+
public class ViewCountContentContext(ContentItem contentItem, int count) : ContentContextBase(contentItem)
7+
{
8+
public int Count { get; set; } = count;
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace OrchardCoreContrib.ViewCount.Handlers;
2+
3+
public abstract class ViewCountContentHandlerBase : IViewCountContentHandler
4+
{
5+
public virtual Task ViewingAsync(ViewCountContentContext context) => Task.CompletedTask;
6+
7+
public virtual Task ViewedAsync(ViewCountContentContext context) => Task.CompletedTask;
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using OrchardCore.Modules.Manifest;
2+
using ManifestConstants = OrchardCoreContrib.Modules.Manifest.ManifestConstants;
3+
4+
[assembly: Module(
5+
Name = "View Count",
6+
Author = ManifestConstants.Author,
7+
Website = ManifestConstants.Website,
8+
Version = "1.0.0",
9+
Description = "Allows to count the content item views.",
10+
Dependencies = ["OrchardCore.Contents"],
11+
Category = "Content Management"
12+
)]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using OrchardCore.ContentManagement.Metadata;
2+
using OrchardCore.ContentManagement.Metadata.Settings;
3+
using OrchardCore.Data.Migration;
4+
5+
namespace OrchardCoreContrib.ViewCount;
6+
7+
public class Migrations(IContentDefinitionManager contentDefinitionManager) : DataMigration
8+
{
9+
public async Task<int> CreateAsync()
10+
{
11+
await contentDefinitionManager.AlterPartDefinitionAsync("ViewCountPart", builder => builder
12+
.Attachable()
13+
.WithDescription("Allow to count the view number of your content item."));
14+
15+
return 1;
16+
}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using OrchardCore.ContentManagement;
2+
3+
namespace OrchardCoreContrib.ViewCount.Models;
4+
public class ViewCountPart : ContentPart
5+
{
6+
public int Count { get; set; }
7+
}

0 commit comments

Comments
 (0)