From d7f258b83069d5acf8bd83dc8302f40e85451ad9 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Sun, 30 Oct 2011 10:46:16 -0700 Subject: [PATCH] Adding CommentsFilter --HG-- branch : 1.x --- .../Projections/CommentsFilter.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Orchard.Web/Modules/Orchard.Comments/Projections/CommentsFilter.cs diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Projections/CommentsFilter.cs b/src/Orchard.Web/Modules/Orchard.Comments/Projections/CommentsFilter.cs new file mode 100644 index 000000000..9567f65be --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Comments/Projections/CommentsFilter.cs @@ -0,0 +1,39 @@ +using System; +using System.Linq; +using Orchard.ContentManagement; +using Orchard.Events; +using Orchard.Localization; +using Orchard.Comments.Models; + +namespace Orchard.Comments.Projections { + public interface IFilterProvider : IEventHandler { + void Describe(dynamic describe); + } + + public class CommentsFilter : IFilterProvider { + + public CommentsFilter() { + T = NullLocalizer.Instance; + } + + public Localizer T { get; set; } + + public void Describe(dynamic describe) { + describe.For("Comments", T("Comments"), T("Comments")) + .Element("HasComments", T("Has Comments"), T("Commented content items"), + (Action)ApplyFilter, + (Func)DisplayFilter, + null + ); + } + + public void ApplyFilter(dynamic context) { + var query = (IContentQuery)context.Query; + context.Query = query.Where(x => x.CommentPartRecords.Any()); + } + + public LocalizedString DisplayFilter(dynamic context) { + return T("Has comments"); + } + } +} \ No newline at end of file