/// <summary> /// Executes this instance. /// </summary> public void Execute() { using ( var rockContext = new RockContext() ) { var communication = new CommunicationService( rockContext ).Get( CommunicationId ); if ( communication != null && communication.Status == CommunicationStatus.PendingApproval ) { // get notification group var approvers = new GroupService( rockContext ).Get(SystemGuid.Group.GROUP_COMMUNICATION_APPROVERS.AsGuid()); if ( approvers != null ) { var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( null ); string fromName = Rock.Web.Cache.GlobalAttributesCache.Value("OrganizationName"); string fromEmail = Rock.Web.Cache.GlobalAttributesCache.Value( "OrganizationEmail" ); string subject = "Pending Communication Requires Approval"; var appRoot = Rock.Web.Cache.GlobalAttributesCache.Read( rockContext ).GetValue( "PublicApplicationRoot" ); string communicationDetails = string.Empty; string typeName = string.Empty; // get custom details by type switch ( communication.Medium.TypeName ) { case "Rock.Communication.Medium.Email": string emailFromName = communication.GetMediumDataValue( "FromName" ); string emailFromAddress = communication.GetMediumDataValue( "FromAddress" ); communicationDetails = string.Format( @" <strong>From Name:</strong> {0}<br/> <strong>From Address:</strong> {1}<br/> <strong>Subject:</strong> {2}<br/>" , emailFromName , emailFromAddress , communication.Subject ); typeName = "Email"; break; case "Rock.Communication.Medium.Sms": int fromValueId = communication.GetMediumDataValue( "FromValue" ).AsInteger(); var fromValue = new DefinedValueService( rockContext ).Get( fromValueId ); typeName = "SMS"; if ( fromValue != null ) { communicationDetails = string.Format( "<strong>SMS Number:</strong> {0} ({1})<br/>", fromValue.Description, fromValue.Value ); } break; } // create approval link if one was not provided if ( ApprovalPageUrl == null ) { ApprovalPageUrl = string.Format( "{0}Communication/{1}", Rock.Web.Cache.GlobalAttributesCache.Read( rockContext ).GetValue( "InternalApplicationRoot" ), communication.Id ); } foreach ( var approver in approvers.Members ) { string message = string.Format( @" {{{{ 'Global' | Attribute:'EmailHeader' }}}} <p>{0}:</p> <p>A new communication requires approval. Information about this communication can be found below.</p> <p> <strong>From:</strong> {1}<br /> <strong>Type:</strong> {2}<br /> {3} <strong>Recipient Count:</strong> {4}<br /> </p> <p> <a href='{5}'>View Communication</a> </p> {{{{ 'Global' | Attribute:'EmailFooter' }}}}", approver.Person.NickName, communication.SenderPersonAlias.Person.FullName, typeName, communicationDetails, communication.GetRecipientCount(rockContext), ApprovalPageUrl); var recipients = new List<string>(); recipients.Add( approver.Person.Email ); Email.Send( fromEmail, fromName, subject, recipients, message.ResolveMergeFields( mergeFields ), appRoot, string.Empty, null, false ); } } } } }