2009-04-17 25 views
1

Publishingサイトでは、オーディエンスターゲティングフィールドを持つリストのニュースアイテムを表示するWebパーツがあります。私は最後のニュース項目の少数を取得するためにCAMLクエリを使用しています。SharePoint 2007 PublishingサイトとWebパーツのオーディエンスターゲティング

CAMLクエリでターゲットオーディエンスを指定することはできますか?そうでなければ、どうすればいいですか?すべての結果を取得し、ループ内でフィルタを適用するよりも?

私は実質的にコンテンツクエリWebパーツを複製しており、カスタムWebパーツにオーディエンスターゲティングが必要です。

答えて

1

いいえ、CAMLクエリでオーディエンスターゲティングを指定することはできません。私はこれがWSSのCAMLクエリと、MOSS共有サービスのオーディエンスであると考えています。あなたは、視聴者フィールドをCAMLクエリに含めます。つまり、< FieldRef Name = 'Target_x0020_Audiences'/>をSPQuery.ViewFieldsプロパティに追加することです。次に、各リスト項目のオーディエンスによって結果コードを賢明にフィルタリングします。現在のユーザーがオーディエンスのメンバーであるかどうかをテストするには、AudienceManagerクラスを使用します。

0

この問題の回避策が見つかったのは、現在のユーザーが特定の公開ページの聴衆のメンバーで、その聴衆の名前が何であるかをチェックしようとするときに問題が発生していたことです。ここで私が思い付いた回避策です。


// Run through the pages building the list items 
foreach (SPListItem li in pages) 
{ 
    // Get a reference to the publishing page 
    PublishingPage p = PublishingPage.GetPublishingPage(li); 

    // Make sure the page has been approved 
    if (li.ModerationInformation.Status == SPModerationStatusType.Approved) 
    { 
    // Check if this page has an audience 
    if (string.IsNullOrEmpty(p.Audience)) 
     // Add to everyone list 
    else 
    { 
     // Split the audiences 
     string[] Audiences = p.Audience.Split(';'); 

     // Check each audience to see if this user can see it 
     foreach (string audPart in Audiences) 
     { 
     AudienceManager audienceManager = new AudienceManager(); 

     // Get a reference to the audience 
     // IsGuid is an extenstion method i wrtoe 
     if (audPart.IsGuid()) 
     { 
      if (audienceManager.Audiences.AudienceExist(new Guid(audPart))) 
      aud = audienceManager.Audiences[new Guid(audPart)]; 
     } 
     else 
     { 
      if (audienceManager.Audiences.AudienceExist(audPart)) 
      aud = audienceManager.Audiences[audPart]; 
     } 

     // Ensure we have a reference to the audience 
     if (aud != null) 
     { 

      // store the item in the temp variables 
      switch (aud.AudienceName) 
      { 
      case "All site users": 
       // Add to everyone list 
       break; 

      case "Some List": 
       if (audienceManager.IsMemberOfAudience(web.CurrentUser.LoginName, aud.AudienceID)) 
       { 
       // Add to other list 
       } 
       break; 

      case "Other List": 
       if (audienceManager.IsMemberOfAudience(web.CurrentUser.LoginName, aud.AudienceID)) 
       { 
       // Add to other list 
       } 
       break; 
      } 

     } 
     } 
    } 
    } 
} 

あなたは観客がAudienceManager.Audiences.AudienceExistを使用して存在し、かどうかをチェックするのにその実際には母校を見ることができるようにちょうどAudienceManager.Audiences accesorデフォルトを使用して、それへの参照を取得[GUID]。

関連する問題