2011-03-16 98 views
3

我使用的是Umbraco 4.6.2,需要擴展它提供的默認通知。爲了這個問題,我們假設我正在嘗試添加「取消發佈」通知。Umbraco - 如何添加自定義通知?

\umbraco\presentation\umbraco\dialogs\notifications.aspx.cs它構建了從上下文菜單中打開「通知」對話框時顯示給用戶的checkbx項目列表。

我看到每個Action都有一個ShowInNotifier屬性 - 如何將UnPublish操作的值設置爲true? 這是否需要修改核心代碼庫,還是有一個好方法可以優雅地擴展Umbraco?

所以在我添加這個之後,用戶可以訂閱UnPublish通知(我錯過了這裏的任何步驟?)。 這會自動發送通知嗎?

我猜沒有,所以我做的下一件事掛在取消發佈事件:

public class CustomEvents : ApplicationBase 
{ 
    public CustomEvents() 
    { 
     Document.AfterUnPublish += new Document.UnPublishEventHandler(Document_AfterUnPublish); 
    } 

    void Document_AfterUnPublish(Document sender, umbraco.cms.businesslogic.UnPublishEventArgs e) 
    { 
     var user = User.GetCurrent(); 

     if (!string.IsNullOrEmpty(user.Email) && user.GetNotifications(sender.Path).Contains("UnPublish")) 
     { 
      //Send a notification here using default Umbraco settings, or, construct email and send manually: 
      string umbracoNotificationSenderAddress = ""; //How to get the address stored in umbracoSettings.config -> <notifications> -> <email> 

      //How to use the same subject/message formats used for other notifications? With the links back to the content? 
      string subject = "Notification of UnPublish performed on " + MyUtilities.GetFriendlyName(sender.Id); 
      string message = MyUtilities.GetFriendlyName(sender.Id) + " has just been unpublished."; 

      umbraco.library.SendMail(umbracoNotificationSenderAddress, user.Email, subject, message, true); 
     } 
    } 
} 

因此,該代碼是不是真正的比特/我需要一些指點:

  • 這是檢查用戶是否訂閱特定通知的正確方法嗎?

  • 如何使用默認的umbraco設置發送通知? (如生成電子郵件就像其他通知)

如果這是不可能的,我必須構建自己的郵箱:

  • 如何獲取存儲在umbracoSettings的電子郵件地址中。配置

  • 如何複製默認Umbraco通知使用的格式?我應該手動複製它還是有更好的方式來做到這一點(以編程方式)。

任何幫助(甚至只是鏈接到相關實例)的讚賞:>

回答

0

我的同事得到了這個工作。

創建一個覆蓋您希望收到通知的操作的類。 你可以看到/umbraco/cms/Actions

public class ActionUnPublishOverride : umbraco.BusinessLogic.Actions.ActionUnPublish, IAction 
{ 
    ... see what the other actions look like to find out what to put in here! 

所有的動作在重寫的類,你將有一個public char Letter。設置此項以匹配要掛入的事件。你可以找到每個事件在數據庫中的字母。

public bool ShowInNotifier設置爲true。

就是這樣!

0

我已經在Umbraco 4上工作了。7使用UmbracoSettings類:

http://www.java2s.com/Open-Source/CSharp/Content-Management-Systems-CMS/umbraco/umbraco/businesslogic/UmbracoSettings.cs.htm

umbraco.library.SendMail(umbraco.UmbracoSettings.NotificationEmailSender, newMember.Email, "email subject", "email body", false); 
+0

對,所以這只是讓你發送電子郵件,但它不使用一把umbraco系統通知。也就是說,它不會讓用戶「訂閱」某些事件。我在我的問題中已經有了這個確切的線:) – elwyn 2011-04-16 00:29:10