2018-06-29 19:52:40 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2021-02-09 10:22:42 +01:00
|
|
|
|
using Umbraco.Cms.Core.Mapping;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
2021-02-15 13:14:07 +01:00
|
|
|
|
namespace Umbraco.Cms.Core
|
2018-06-29 19:52:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <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;
|
2021-04-20 19:34:18 +02:00
|
|
|
|
private readonly IUmbracoMapper _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>
|
2021-04-20 19:34:18 +02:00
|
|
|
|
public TagQuery(ITagService tagService, IPublishedContentQuery contentQuery, IUmbracoMapper 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 />
|
2022-02-22 13:35:32 +01:00
|
|
|
|
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 />
|
2021-12-16 13:44:20 +01:00
|
|
|
|
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 />
|
2022-02-22 13:35:32 +01:00
|
|
|
|
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 />
|
2021-12-16 13:44:20 +01:00
|
|
|
|
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 />
|
2022-02-24 10:22:20 +01:00
|
|
|
|
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 />
|
2022-02-24 10:22:20 +01:00
|
|
|
|
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 />
|
2022-02-24 10:22:20 +01:00
|
|
|
|
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 />
|
2022-02-24 10:22:20 +01:00
|
|
|
|
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 />
|
2022-02-24 10:22:20 +01:00
|
|
|
|
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 />
|
2022-02-24 10:22:20 +01:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|