Adding HasChildren check to ContentService and ContentTypeService.

Correcting an issue with loading of template ids in DocumentType class.
This commit is contained in:
Morten Christensen
2012-12-11 14:27:18 -01:00
parent 64b91ae1e4
commit 1eaa117883
6 changed files with 75 additions and 6 deletions

View File

@@ -280,11 +280,24 @@ namespace Umbraco.Core.Services
return contents;
}
/// <summary>
/// Checks whether an <see cref="IContent"/> item has any children
/// </summary>
/// <param name="id">Id of the <see cref="IContent"/></param>
/// <returns>True if the content has any children otherwise False</returns>
public bool HasChildren(int id)
{
var repository = _contentRepository;
var query = Query<IContent>.Builder.Where(x => x.ParentId == id);
int count = repository.Count(query);
return count > 0;
}
/// <summary>
/// Checks whether an <see cref="IContent"/> item has any published versions
/// </summary>
/// <param name="id">Id of the <see cref="IContent"/></param>
/// <returns>True if the content has any published versiom otherwise False</returns>
/// <returns>True if the content has any published version otherwise False</returns>
public bool HasPublishedVersion(int id)
{
var repository = _contentRepository;

View File

@@ -99,6 +99,19 @@ namespace Umbraco.Core.Services
return contentTypes;
}
/// <summary>
/// Checks whether an <see cref="IContentType"/> item has any children
/// </summary>
/// <param name="id">Id of the <see cref="IContentType"/></param>
/// <returns>True if the content type has any children otherwise False</returns>
public bool HasChildren(int id)
{
var repository = _contentTypeRepository;
var query = Query<IContentType>.Builder.Where(x => x.ParentId == id);
int count = repository.Count(query);
return count > 0;
}
/// <summary>
/// Saves a single <see cref="IContentType"/> object
/// </summary>
@@ -297,6 +310,19 @@ namespace Umbraco.Core.Services
return contentTypes;
}
/// <summary>
/// Checks whether an <see cref="IMediaType"/> item has any children
/// </summary>
/// <param name="id">Id of the <see cref="IMediaType"/></param>
/// <returns>True if the media type has any children otherwise False</returns>
public bool MediaTypeHasChildren(int id)
{
var repository = _mediaTypeRepository;
var query = Query<IMediaType>.Builder.Where(x => x.ParentId == id);
int count = repository.Count(query);
return count > 0;
}
/// <summary>
/// Saves a single <see cref="IMediaType"/> object
/// </summary>

View File

@@ -261,7 +261,7 @@ namespace Umbraco.Core.Services
/// Cheacks whether an <see cref="IContent"/> item has any published versions
/// </summary>
/// <param name="id">Id of the <see cref="IContent"/></param>
/// <returns>True if the content has any published versiom otherwise False</returns>
/// <returns>True if the content has any published version otherwise False</returns>
bool HasPublishedVersion(int id);
/// <summary>
@@ -292,5 +292,12 @@ namespace Umbraco.Core.Services
/// <param name="content"><see cref="IContent"/> item to retrieve Descendants from</param>
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
IEnumerable<IContent> GetDescendants(IContent content);
/// <summary>
/// Checks whether an <see cref="IContent"/> item has any children
/// </summary>
/// <param name="id">Id of the <see cref="IContent"/></param>
/// <returns>True if the content has any children otherwise False</returns>
bool HasChildren(int id);
}
}

View File

@@ -147,5 +147,19 @@ namespace Umbraco.Core.Services
/// </summary>
/// <returns>The DTD as a string</returns>
string GetContentTypesDtd();
/// <summary>
/// Checks whether an <see cref="IContentType"/> item has any children
/// </summary>
/// <param name="id">Id of the <see cref="IContentType"/></param>
/// <returns>True if the content type has any children otherwise False</returns>
bool HasChildren(int id);
/// <summary>
/// Checks whether an <see cref="IMediaType"/> item has any children
/// </summary>
/// <param name="id">Id of the <see cref="IMediaType"/></param>
/// <returns>True if the media type has any children otherwise False</returns>
bool MediaTypeHasChildren(int id);
}
}

View File

@@ -495,7 +495,10 @@ namespace umbraco.cms.businesslogic.web
/// <returns></returns>
public static Document[] GetChildrenForTree(int NodeId)
{
var tmp = new List<Document>();
var children = ServiceContext.Current.ContentService.GetChildren(NodeId);
var list = children.Select(x => new Document(x.Id));
return list.ToArray();
/*var tmp = new List<Document>();
using (IRecordsReader dr =
SqlHelper.ExecuteReader(
string.Format(m_SQLOptimizedMany.Trim(), "umbracoNode.parentID = @parentId", "umbracoNode.sortOrder"),
@@ -510,7 +513,7 @@ namespace umbraco.cms.businesslogic.web
}
}
return tmp.ToArray();
return tmp.ToArray();*/
}
public static List<Document> GetChildrenBySearch(int NodeId, string searchString)

View File

@@ -209,7 +209,8 @@ namespace umbraco.cms.businesslogic.web
{
if (!_hasChildrenInitialized)
{
HasChildren = SqlHelper.ExecuteScalar<int>("select count(childContentTypeId) as tmp from cmsContentType2ContentType where parentContentTypeId = @id", SqlHelper.CreateParameter("@id", Id)) > 0;
HasChildren = ServiceContext.Current.ContentTypeService.HasChildren(Id);
//HasChildren = SqlHelper.ExecuteScalar<int>("select count(childContentTypeId) as tmp from cmsContentType2ContentType where parentContentTypeId = @id", SqlHelper.CreateParameter("@id", Id)) > 0;
}
return _hasChildren;
}
@@ -487,7 +488,12 @@ namespace umbraco.cms.businesslogic.web
protected override void setupNode()
{
_contentType = ServiceContext.Current.ContentTypeService.GetContentType(Id);
_templateIds = new ArrayList { _contentType.AllowedTemplates.Select(x => x.Id) };
foreach (var template in _contentType.AllowedTemplates)
{
_templateIds.Add(template.Id);
}
if(_contentType.DefaultTemplate != null)
_defaultTemplate = _contentType.DefaultTemplate.Id;