Files
Umbraco-CMS/src/Umbraco.Web/TagQuery.cs

104 lines
4.0 KiB
C#
Raw Normal View History

2018-06-29 19:52:40 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
2019-04-03 10:39:49 +02:00
using Umbraco.Core.Mapping;
2019-04-08 16:38:18 +02:00
using Umbraco.Core.Models;
2018-06-29 19:52:40 +02:00
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.Models;
namespace Umbraco.Web
{
/// <summary>
2018-11-20 13:24:06 +01:00
/// Implements <see cref="ITagQuery"/>.
2018-06-29 19:52:40 +02:00
/// </summary>
public class TagQuery : ITagQuery
{
private readonly ITagService _tagService;
private readonly IPublishedContentQuery _contentQuery;
2019-04-03 10:39:49 +02:00
private readonly UmbracoMapper _mapper;
2018-06-29 19:52:40 +02:00
/// <summary>
2018-11-20 13:24:06 +01:00
/// Initializes a new instance of the <see cref="TagQuery"/> class.
2018-06-29 19:52:40 +02:00
/// </summary>
2019-04-03 10:39:49 +02:00
public TagQuery(ITagService tagService, IPublishedContentQuery contentQuery, UmbracoMapper mapper)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
_tagService = tagService ?? throw new ArgumentNullException(nameof(tagService));
_contentQuery = contentQuery ?? throw new ArgumentNullException(nameof(contentQuery));
2019-04-03 10:39:49 +02:00
_mapper = mapper;
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetContentByTag(string tag, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedContentByTag(tag, group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Content(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetContentByTagGroup(string group, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedContentByTagGroup(group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Content(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetMediaByTag(string tag, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedMediaByTag(tag, group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Media(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<IPublishedContent> GetMediaByTagGroup(string group, string culture = null)
2018-06-29 19:52:40 +02:00
{
2018-11-20 13:24:06 +01:00
var ids = _tagService.GetTaggedMediaByTagGroup(group, culture)
2018-06-29 19:52:40 +02:00
.Select(x => x.EntityId);
return _contentQuery.Media(ids)
.Where(x => x != null);
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2019-04-08 16:38:18 +02:00
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllContentTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2019-04-08 16:38:18 +02:00
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllContentTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllMediaTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2019-04-08 16:38:18 +02:00
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllMediaTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetAllMemberTags(string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2019-04-08 16:38:18 +02:00
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetAllMemberTags(group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2019-04-08 16:38:18 +02:00
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture));
2018-06-29 19:52:40 +02:00
}
2018-11-20 13:24:06 +01:00
/// <inheritdoc />
public IEnumerable<TagModel> GetTagsForEntity(int contentId, string group = null, string culture = null)
2018-06-29 19:52:40 +02:00
{
2019-04-08 16:38:18 +02:00
return _mapper.MapEnumerable<ITag, TagModel>(_tagService.GetTagsForEntity(contentId, group, culture));
2018-06-29 19:52:40 +02:00
}
}
}