Implements the retrieval of ancestors, children, descendats and parent IContent in the ContentService and as extensions to IContent.
Corresponds to the IContent implementation of U4-1638.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
@@ -18,6 +19,46 @@ namespace Umbraco.Core.Models
|
||||
{
|
||||
public static class ContentExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a list of the current contents ancestors, not including the content itself.
|
||||
/// </summary>
|
||||
/// <param name="content">Current content</param>
|
||||
/// <returns>An enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public static IEnumerable<IContent> Ancestors(this IContent content)
|
||||
{
|
||||
return ApplicationContext.Current.Services.ContentService.GetAncestors(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of the current contents children.
|
||||
/// </summary>
|
||||
/// <param name="content">Current content</param>
|
||||
/// <returns>An enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public static IEnumerable<IContent> Children(this IContent content)
|
||||
{
|
||||
return ApplicationContext.Current.Services.ContentService.GetChildren(content.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of the current contents descendants, not including the content itself.
|
||||
/// </summary>
|
||||
/// <param name="content">Current content</param>
|
||||
/// <returns>An enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public static IEnumerable<IContent> Descendants(this IContent content)
|
||||
{
|
||||
return ApplicationContext.Current.Services.ContentService.GetDescendants(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the parent of the current content.
|
||||
/// </summary>
|
||||
/// <param name="content">Current content</param>
|
||||
/// <returns>An <see cref="IContent"/> object</returns>
|
||||
public static IContent Parent(this IContent content)
|
||||
{
|
||||
return ApplicationContext.Current.Services.ContentService.GetById(content.ParentId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set property values by alias with an annonymous object
|
||||
/// </summary>
|
||||
|
||||
@@ -228,7 +228,32 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> objects, which are ancestors of the current content.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to retrieve ancestors for</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetAncestors(int id)
|
||||
{
|
||||
var content = GetById(id);
|
||||
return GetAncestors(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> objects, which are ancestors of the current content.
|
||||
/// </summary>
|
||||
/// <param name="content"><see cref="IContent"/> to retrieve ancestors for</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetAncestors(IContent content)
|
||||
{
|
||||
var ids = content.Path.Split(',').Where(x => x != "-1" && x != content.Id.ToString()).Select(int.Parse).ToArray();
|
||||
using (var repository = _repositoryFactory.CreateContentRepository(_uowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetAll(ids);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> objects by Parent Id
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the Parent to retrieve Children from</param>
|
||||
@@ -289,6 +314,27 @@ namespace Umbraco.Core.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of the current content as an <see cref="IContent"/> item.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to retrieve the parent from</param>
|
||||
/// <returns>Parent <see cref="IContent"/> object</returns>
|
||||
public IContent GetParent(int id)
|
||||
{
|
||||
var content = GetById(id);
|
||||
return GetParent(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of the current content as an <see cref="IContent"/> item.
|
||||
/// </summary>
|
||||
/// <param name="content"><see cref="IContent"/> to retrieve the parent from</param>
|
||||
/// <returns>Parent <see cref="IContent"/> object</returns>
|
||||
public IContent GetParent(IContent content)
|
||||
{
|
||||
return GetById(content.ParentId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the published version of an <see cref="IContent"/> item
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to retrieve version from</param>
|
||||
|
||||
@@ -287,5 +287,33 @@ namespace Umbraco.Core.Services
|
||||
/// <param name="content"><see cref="IContent"/> to check if anscestors are published</param>
|
||||
/// <returns>True if the Content can be published, otherwise False</returns>
|
||||
bool IsPublishable(IContent content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> objects, which are ancestors of the current content.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to retrieve ancestors for</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
IEnumerable<IContent> GetAncestors(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent"/> objects, which are ancestors of the current content.
|
||||
/// </summary>
|
||||
/// <param name="content"><see cref="IContent"/> to retrieve ancestors for</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
IEnumerable<IContent> GetAncestors(IContent content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of the current content as an <see cref="IContent"/> item.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent"/> to retrieve the parent from</param>
|
||||
/// <returns>Parent <see cref="IContent"/> object</returns>
|
||||
IContent GetParent(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of the current content as an <see cref="IContent"/> item.
|
||||
/// </summary>
|
||||
/// <param name="content"><see cref="IContent"/> to retrieve the parent from</param>
|
||||
/// <returns>Parent <see cref="IContent"/> object</returns>
|
||||
IContent GetParent(IContent content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user