2016-09-13 4 views
1

나는 Orchard CMS와 협력 중입니다. Super admin에게 메일을 보내는 작업 흐름과 알림으로 블록/뉴스를 만드는 사용자 자신을 만들었습니다.과수원 작업 흐름 - 여러 게시자와 운영자에게 내용 게시/업데이트로 전자 메일 보내기/업데이트

내 CMS에는 관리자와 중재자가 한 명 이상 있습니다. 새로운 블로그/뉴스/기사가 게시되거나 업데이트되는 즉시 모든 사회자와 관리자에게 이메일을 보내고 싶습니다. 지금은 모든 사용자가 아닌 한 명의 관리자 사용자에게만 전송됩니다. 콘텐츠 (뉴스/블로그)가 게시되거나 업데이트되면 모든 관리자와 중재자에게 메일을 보내도록 워크 플로를 어떻게 만들 수 있습니까?

나는 과수원 버전 1.10.0을 연구 중이다.

도움이 되었습니까? 고맙습니다.

+1

지금 보내시겠습니까? 사용자 지정 워크 플로 작업을 작성해야하는 것처럼 들립니다. – rtpHarry

답변

0

여기에는 두 가지 가능성이 있습니다. 사용자 지정 워크 플로 작업과 간단한 토큰입니다.

작업부터 시작하겠습니다. 나는 간단한 데모를 만들었습니다. 여기 코드는 다음과 같습니다 당신은 루프에서받는 사람을 던져, 그리고 그들 각각에 대해 새 이메일을 보내도록 할 수 있습니다

활동/RoleMailerTask.cs

namespace My.Module 
{ 
    using System.Collections.Generic; 
    using System.Linq; 
    using Orchard; 
    using Orchard.ContentManagement; 
    using Orchard.Data; 
    using Orchard.Email.Activities; 
    using Orchard.Email.Services; 
    using Orchard.Environment.Extensions; 
    using Orchard.Localization; 
    using Orchard.Messaging.Services; 
    using Orchard.Roles.Models; 
    using Orchard.Roles.Services; 
    using Orchard.Users.Models; 
    using Orchard.Workflows.Models; 
    using Orchard.Workflows.Services; 

    [OrchardFeature(Statics.FeatureNames.RoleMailerTask)] 
    public class RoleMailerTask : Task 
    { 
     private readonly IOrchardServices services; 
     public const string TaskName = "RoleMailer"; 

     public RoleMailerTask(IOrchardServices services) 
     { 
      this.services = services; 
      this.T = NullLocalizer.Instance; 
     } 

     public Localizer T { get; set; } 

     public override string Name 
     { 
      get { return TaskName; } 
     } 

     public override string Form 
     { 
      get { return TaskName; } 
     } 

     public override LocalizedString Category 
     { 
      get { return this.T("Messaging"); } 
     } 

     public override LocalizedString Description 
     { 
      get { return this.T("Sends mails to all users with this chosen role"); } 
     } 

     public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) 
     { 
      yield return this.T("Done"); 
     } 

     public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) 
     { 
      var recipientsRole = int.Parse(activityContext.GetState<string>("RecipientsRole")); 
      var role = this.services.WorkContext.Resolve<IRoleService>().GetRole(recipientsRole); 

      var userRolesRepo = this.services.WorkContext.Resolve<IRepository<UserRolesPartRecord>>(); 
      var recepientIds = userRolesRepo.Table.Where(x => x.Role.Name == role.Name).Select(x => x.UserId); 

      var recipients = this.services.ContentManager.GetMany<UserPart>(recepientIds, VersionOptions.Published, QueryHints.Empty) 
       .Where(x => !string.IsNullOrEmpty(x.Email)) 
       .Select(x => x.Email); 

      var body = activityContext.GetState<string>("Body"); 
      var subject = activityContext.GetState<string>("Subject"); 

      var replyTo = activityContext.GetState<string>("ReplyTo"); 
      var bcc = activityContext.GetState<string>("Bcc"); 
      var cc = activityContext.GetState<string>("CC"); 

      var parameters = new Dictionary<string, object> { 
       {"Subject", subject}, 
       {"Body", body}, 
       {"Recipients", string.Join(",", recipients)}, 
       {"ReplyTo", replyTo}, 
       {"Bcc", bcc}, 
       {"CC", cc} 
      }; 

      var queued = activityContext.GetState<bool>("Queued"); 

      if (!queued) 
      { 
       this.services.WorkContext.Resolve<IMessageService>().Send(SmtpMessageChannel.MessageType, parameters); 
      } 
      else 
      { 
       var priority = activityContext.GetState<int>("Priority"); 
       this.services.WorkContext.Resolve<IJobsQueueService>().Enqueue("IMessageService.Send", new { type = SmtpMessageChannel.MessageType, parameters = parameters }, priority); 
      } 

      yield return T("Done"); 
     } 
    } 
} 

. 위의 버전으로, 모든 사람이 ... 다른 사람의 메일 주소가 표시됩니다

양식/RoleMailerTaskForm.cs

namespace My.Module 
{ 
    using System; 
    using System.Linq; 
    using System.Web.Mvc; 
    using Activities; 
    using Orchard; 
    using Orchard.ContentManagement; 
    using Orchard.DisplayManagement; 
    using Orchard.Environment.Extensions; 
    using Orchard.Forms.Services; 
    using Orchard.Roles.Services; 

    [OrchardFeature(Statics.FeatureNames.RoleMailerTask)] 
    public class RoleMailerTaskForm : Component, IFormProvider 
    { 
     private readonly IRoleService roleService; 

     public RoleMailerTaskForm(IShapeFactory shapeFactory, IRoleService roleService) 
     { 
      this.roleService = roleService; 
      this.Shape = shapeFactory; 
     } 

     public dynamic Shape { get; set; } 

     public void Describe(DescribeContext context) 
     { 
      Func<IShapeFactory, dynamic> formFactory = shape => 
      { 
       var form = this.Shape.Form(
        Id: RoleMailerTask.TaskName, 
        _Type: this.Shape.FieldSet(
          Title: this.T("Send to"), 
          _RecepientsRole: this.Shape.SelectList(
           Id: "recipientsRole", 
           Name: "RecipientsRole", 
           Title: this.T("Recepient role"), 
           Description: this.T("The role of the users that should be notified"), 
           Items: this.roleService.GetRoles().Select(r => new SelectListItem { Value = r.Id.ToString(), Text = r.Name }) 
          ), 
          _Bcc: this.Shape.TextBox(
           Id: "bcc", 
           Name: "Bcc", 
           Title: this.T("Bcc"), 
           Description: this.T("Specify a comma-separated list of email addresses for a blind carbon copy"), 
           Classes: new[] { "large", "text", "tokenized" }), 
          _CC: this.Shape.TextBox(
           Id: "cc", 
           Name: "CC", 
           Title: this.T("CC"), 
           Description: this.T("Specify a comma-separated list of email addresses for a carbon copy"), 
           Classes: new[] { "large", "text", "tokenized" }), 
          _ReplyTo: this.Shape.Textbox(
           Id: "reply-to", 
           Name: "ReplyTo", 
           Title: this.T("Reply To Address"), 
           Description: this.T("If necessary, specify an email address for replies."), 
           Classes: new[] { "large", "text", "tokenized" }), 
          _Subject: this.Shape.Textbox(
           Id: "Subject", Name: "Subject", 
           Title: this.T("Subject"), 
           Description: this.T("The subject of the email message."), 


       Classes: new[] { "large", "text", "tokenized" }), 
         _Message: this.Shape.Textarea(
          Id: "Body", Name: "Body", 
          Title: this.T("Body"), 
          Description: this.T("The body of the email message."), 
          Classes: new[] { "tokenized" }) 
         )); 

      return form; 
     }; 

     context.Form(RoleMailerTask.TaskName, formFactory); 
    } 
} 

이 당신이 작업을 구성하는 데 필요한 양식입니다. 양식은 Orchard.Email/Forms/EmailForm에서 벗어난 찢어진 것입니다. 내가 변경 한 유일한 것은 양식 상단의 선택 목록입니다.

그리고 그게 전부입니다! 위의 작업에 표시된 것처럼 사용자를 그 역할 이름을 구문 분석하고 얻을 : 토큰 방식에 대한

, 당신은 단지 {TheRoleYouWant RoleRecpients} 같은 토큰을 정의해야합니다.