2014-02-13 2 views
2

움 브라 코 6.1.6의 개발자 섹션에는 관계 유형 노드가 있습니다.움 브라 코 관계 유형

관계 유형이 무엇인지 설명하고 실용적인 응용 프로그램이 있는지 설명 할 수 있습니다. 나는 어떤 문서를 보았지만, 나는 왜 그것들을 사용해야 할 지 확신 할 수 없다.

v6 및 v7과 여전히 관련이 있습니까?

답변

5

저는 최근에 Relations Service을 문서화하기 시작했습니다. Relations Service은 사용자가 할 수있는 것에 대한 통찰력을 제공해야합니다. 콘텐츠 트리의 노드 간 관계를 유지하기 위해 때때로 사용합니다.

Umbraco에서 노드를 복사 한 경우 "문서 복사 관련 문서"라는 관계 유형을 사용하는 원본 노드에 새 노드를 연결하는 옵션이 제공됩니다. 예를 들어, 관계가있는 상태에서 저장 이벤트와 같은 이벤트에 연결할 수 있으며 부모가 업데이트 될 때 관련 자식 노드를 업데이트 할 수도 있습니다. 이 기술은 때로는 각 언어별로 콘텐츠를 동기화하려는 다중 언어 사이트에서 사용됩니다.

다음은 반복 일정을 만들 수있는 최근 프로젝트의 축약 된 예입니다. 우리는 연재에서 첫 번째 사건과 사건의 모든 후속 사건 (어린이들)을 알아야합니다.

public class Events : ApplicationEventHandler 
    { 
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) 
    { 
     ContentService.Saved += ContentServiceSaved; 
    } 

    private void ContentServiceSaved(IContentService sender, SaveEventArgs<IContent> e) 
    { 
     var rs = ApplicationContext.Current.Services.RelationService; 
     var relationType = rs.GetRelationTypeByAlias("repeatedEventOccurence"); 

     foreach (IContent content in e.SavedEntities) 
     { 
      var occurences = rs.GetByParentId(content.Id).Where(r => r.RelationType.Alias == "repeatedEventOccurence"); 
      bool exists = false; 

      foreach (var doc in occurences.Select(o => sender.GetById(o.ChildId))) 
      { 
       // Check if there is already an occurence of this event with a matching date 
      } 

      if (!exists) 
      { 
       var newDoc = sender.Copy(content, eventsDoc.Id, true, User.GetCurrent().Id); 

       // Set any properties you need to on the new node 
       ... 

       rs.Relate(content, newDoc, relationType); 
      }  
     } 
    } 
} 
관련 문제