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,14 +1,42 @@
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;

namespace Umbraco.Cms.Core.Persistence.Repositories
{
public interface ITrackedReferencesRepository
{
IEnumerable<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
IEnumerable<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
IEnumerable<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency,out long totalRecords);
/// <summary>
/// Gets a page of items which are in relation with the current item.
/// Basically, shows the items which depend on the current item.
/// </summary>
/// <param name="id">The identifier of the entity to retrieve relations for.</param>
/// <param name="pageIndex">The page index.</param>
/// <param name="pageSize">The page size.</param>
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
/// <param name="totalRecords">The total count of the items with reference to the current item.</param>
/// <returns>An enumerable list of <see cref="RelationItem"/> objects.</returns>
IEnumerable<RelationItem> GetPagedRelationsForItem(int id, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords);

/// <summary>
/// Gets a page of items used in any kind of relation from selected integer ids.
/// </summary>
/// <param name="ids">The identifiers of the entities to check for relations.</param>
/// <param name="pageIndex">The page index.</param>
/// <param name="pageSize">The page size.</param>
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
/// <param name="totalRecords">The total count of the items in any kind of relation.</param>
/// <returns>An enumerable list of <see cref="RelationItem"/> objects.</returns>
IEnumerable<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords);

/// <summary>
/// Gets a page of the descending items that have any references, given a parent id.
/// </summary>
/// <param name="parentId">The unique identifier of the parent to retrieve descendants for.</param>
/// <param name="pageIndex">The page index.</param>
/// <param name="pageSize">The page size.</param>
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
/// <param name="totalRecords">The total count of descending items.</param>
/// <returns>An enumerable list of <see cref="RelationItem"/> objects.</returns>
IEnumerable<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency, out long totalRecords);
}
}
29 changes: 26 additions & 3 deletions src/Umbraco.Core/Services/ITrackedReferencesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,35 @@ namespace Umbraco.Cms.Core.Services
{
public interface ITrackedReferencesService
{
PagedResult<RelationItem> GetPagedRelationsForItems(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency);

/// <summary>
/// Gets a paged result of items which are in relation with the current item.
/// Basically, shows the items which depend on the current item.
/// </summary>
/// <param name="id">The identifier of the entity to retrieve relations for.</param>
/// <param name="pageIndex">The page index.</param>
/// <param name="pageSize">The page size.</param>
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
/// <returns>A paged result of <see cref="RelationItem"/> objects.</returns>
PagedResult<RelationItem> GetPagedRelationsForItem(int id, long pageIndex, int pageSize, bool filterMustBeIsDependency);

/// <summary>
/// Gets a paged result of the descending items that have any references, given a parent id.
/// </summary>
/// <param name="parentId">The unique identifier of the parent to retrieve descendants for.</param>
/// <param name="pageIndex">The page index.</param>
/// <param name="pageSize">The page size.</param>
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
/// <returns>A paged result of <see cref="RelationItem"/> objects.</returns>
PagedResult<RelationItem> GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency);


/// <summary>
/// Gets a paged result of items used in any kind of relation from selected integer ids.
/// </summary>
/// <param name="ids">The identifiers of the entities to check for relations.</param>
/// <param name="pageIndex">The page index.</param>
/// <param name="pageSize">The page size.</param>
/// <param name="filterMustBeIsDependency">A boolean indicating whether to filter only the RelationTypes which are dependencies (isDependency field is set to true).</param>
/// <returns>A paged result of <see cref="RelationItem"/> objects.</returns>
PagedResult<RelationItem> GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency);
}
}
6 changes: 6 additions & 0 deletions src/Umbraco.Infrastructure/Persistence/NPocoSqlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,12 @@ public static Sql<ISqlContext> SelectDistinct<TDto>(this Sql<ISqlContext> sql, p
return sql;
}

public static Sql<ISqlContext> SelectDistinct(this Sql<ISqlContext> sql, params object[] columns)
{
sql.Append("SELECT DISTINCT " + string.Join(", ", columns));
return sql;
}

//this.Append("SELECT " + string.Join(", ", columns), new object[0]);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,6 @@ public IEnumerable<IUmbracoEntity> GetPagedParentEntitiesByChildId(int childId,
});
}

public IEnumerable<IUmbracoEntity> GetPagedParentEntitiesByChildIds(int[] childIds, long pageIndex, int pageSize, out long totalRecords, int[] relationTypes, params Guid[] entityTypes)
{
return _entityRepository.GetPagedResultsByQuery(Query<IUmbracoEntity>(), entityTypes, pageIndex, pageSize, out totalRecords, null, null, sql =>
{
SqlJoinRelations(sql);

sql.WhereIn<RelationDto>(rel => rel.ChildId, childIds);
sql.WhereAny(s => s.WhereIn<RelationDto>(rel => rel.ParentId, childIds), s => s.WhereNotIn<NodeDto>(node => node.NodeId, childIds));

if (relationTypes != null && relationTypes.Any())
{
sql.WhereIn<RelationDto>(rel => rel.RelationType, relationTypes);
}
});
}

public IEnumerable<IUmbracoEntity> GetPagedChildEntitiesByParentId(int parentId, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
{
return GetPagedChildEntitiesByParentId(parentId, pageIndex, pageSize, out totalRecords, new int[0], entityTypes);
Expand Down Expand Up @@ -241,21 +225,6 @@ public IEnumerable<IUmbracoEntity> GetPagedChildEntitiesByParentId(int parentId,
});
}

public IEnumerable<IUmbracoEntity> GetPagedEntitiesForItemsInRelation(int[] itemIds, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
{
return _entityRepository.GetPagedResultsByQuery(Query<IUmbracoEntity>(), entityTypes, pageIndex, pageSize, out totalRecords, null, null, sql =>
{
SqlJoinRelations(sql);

sql.WhereIn<RelationDto>(rel => rel.ChildId, itemIds);
sql.Where<RelationDto, NodeDto>((rel, node) => rel.ChildId == node.NodeId);
sql.Where<RelationTypeDto>(type => type.IsDependency);
});
}




public void Save(IEnumerable<IRelation> relations)
{
foreach (var hasIdentityGroup in relations.GroupBy(r => r.HasIdentity))
Expand Down Expand Up @@ -475,8 +444,6 @@ internal class RelationItemDto
[Column(Name = "contentTypeName")]
public string ChildContentTypeName { get; set; }



[Column(Name = "relationTypeName")]
public string RelationTypeName { get; set; }

Expand Down
Loading