diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index f24ab9c863..526d8a4886 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -280,11 +280,24 @@ namespace Umbraco.Core.Services return contents; } + /// + /// Checks whether an item has any children + /// + /// Id of the + /// True if the content has any children otherwise False + public bool HasChildren(int id) + { + var repository = _contentRepository; + var query = Query.Builder.Where(x => x.ParentId == id); + int count = repository.Count(query); + return count > 0; + } + /// /// Checks whether an item has any published versions /// /// Id of the - /// True if the content has any published versiom otherwise False + /// True if the content has any published version otherwise False public bool HasPublishedVersion(int id) { var repository = _contentRepository; diff --git a/src/Umbraco.Core/Services/ContentTypeService.cs b/src/Umbraco.Core/Services/ContentTypeService.cs index bfd786d8db..044c2895cc 100644 --- a/src/Umbraco.Core/Services/ContentTypeService.cs +++ b/src/Umbraco.Core/Services/ContentTypeService.cs @@ -99,6 +99,19 @@ namespace Umbraco.Core.Services return contentTypes; } + /// + /// Checks whether an item has any children + /// + /// Id of the + /// True if the content type has any children otherwise False + public bool HasChildren(int id) + { + var repository = _contentTypeRepository; + var query = Query.Builder.Where(x => x.ParentId == id); + int count = repository.Count(query); + return count > 0; + } + /// /// Saves a single object /// @@ -297,6 +310,19 @@ namespace Umbraco.Core.Services return contentTypes; } + /// + /// Checks whether an item has any children + /// + /// Id of the + /// True if the media type has any children otherwise False + public bool MediaTypeHasChildren(int id) + { + var repository = _mediaTypeRepository; + var query = Query.Builder.Where(x => x.ParentId == id); + int count = repository.Count(query); + return count > 0; + } + /// /// Saves a single object /// diff --git a/src/Umbraco.Core/Services/IContentService.cs b/src/Umbraco.Core/Services/IContentService.cs index d94df5ebdf..c4d58dc4bb 100644 --- a/src/Umbraco.Core/Services/IContentService.cs +++ b/src/Umbraco.Core/Services/IContentService.cs @@ -261,7 +261,7 @@ namespace Umbraco.Core.Services /// Cheacks whether an item has any published versions /// /// Id of the - /// True if the content has any published versiom otherwise False + /// True if the content has any published version otherwise False bool HasPublishedVersion(int id); /// @@ -292,5 +292,12 @@ namespace Umbraco.Core.Services /// item to retrieve Descendants from /// An Enumerable list of objects IEnumerable GetDescendants(IContent content); + + /// + /// Checks whether an item has any children + /// + /// Id of the + /// True if the content has any children otherwise False + bool HasChildren(int id); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/IContentTypeService.cs b/src/Umbraco.Core/Services/IContentTypeService.cs index 0a53c2b1bb..de948fdc21 100644 --- a/src/Umbraco.Core/Services/IContentTypeService.cs +++ b/src/Umbraco.Core/Services/IContentTypeService.cs @@ -147,5 +147,19 @@ namespace Umbraco.Core.Services /// /// The DTD as a string string GetContentTypesDtd(); + + /// + /// Checks whether an item has any children + /// + /// Id of the + /// True if the content type has any children otherwise False + bool HasChildren(int id); + + /// + /// Checks whether an item has any children + /// + /// Id of the + /// True if the media type has any children otherwise False + bool MediaTypeHasChildren(int id); } } \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs index cd3e7d2b3f..77657e104b 100644 --- a/src/umbraco.cms/businesslogic/web/Document.cs +++ b/src/umbraco.cms/businesslogic/web/Document.cs @@ -495,7 +495,10 @@ namespace umbraco.cms.businesslogic.web /// public static Document[] GetChildrenForTree(int NodeId) { - var tmp = new List(); + var children = ServiceContext.Current.ContentService.GetChildren(NodeId); + var list = children.Select(x => new Document(x.Id)); + return list.ToArray(); + /*var tmp = new List(); 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 GetChildrenBySearch(int NodeId, string searchString) diff --git a/src/umbraco.cms/businesslogic/web/DocumentType.cs b/src/umbraco.cms/businesslogic/web/DocumentType.cs index c874220361..a0aaa6757a 100644 --- a/src/umbraco.cms/businesslogic/web/DocumentType.cs +++ b/src/umbraco.cms/businesslogic/web/DocumentType.cs @@ -209,7 +209,8 @@ namespace umbraco.cms.businesslogic.web { if (!_hasChildrenInitialized) { - HasChildren = SqlHelper.ExecuteScalar("select count(childContentTypeId) as tmp from cmsContentType2ContentType where parentContentTypeId = @id", SqlHelper.CreateParameter("@id", Id)) > 0; + HasChildren = ServiceContext.Current.ContentTypeService.HasChildren(Id); + //HasChildren = SqlHelper.ExecuteScalar("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;