From d2e46d4acd03669379ced879aea14a0daf079294 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 2 Dec 2016 11:22:08 -0500 Subject: [PATCH] WIP for pending and approval notices Admin gets notified when member submits the coupon. Member will be notified when admin approves the coupon. --- classes/helper/notification.php | 40 +++++++++++++------ models/admin/coupons/list.php | 3 ++ views/admin/coupons/memberEmail.html | 25 ++++++++++++ .../{front => admin}/coupons/ownerEmail.html | 0 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 views/admin/coupons/memberEmail.html rename views/{front => admin}/coupons/ownerEmail.html (100%) diff --git a/classes/helper/notification.php b/classes/helper/notification.php index 1d99fa6..f8cb44c 100644 --- a/classes/helper/notification.php +++ b/classes/helper/notification.php @@ -14,6 +14,9 @@ // Load the Member Data class require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMembers.php'; +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php'; +require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH . '/data/dataContacts.php'; + // Extend the member class class GlmMembersAdmin_coupon_notification extends GlmDataMembers @@ -33,7 +36,7 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers */ public $config; - /* + /** * Constructor * * This constructor performs the work for this model. This model returns @@ -75,15 +78,25 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers /** - * Send the member a notice + * Send the member a notice. + * + * This will be the primary contact email if found. + * If not found use the member info record email. + * If nothing in either one then return. */ public function sendMemberNotice( $memberId, $coupon ) { $member = $this->getEntry( $memberId ); // find notify_to - // This will be the primary contact email if found - // if not found use the member info record email - // if nothing in either one then return. + // See if there's a primary member contact for this member + $notify_to = apply_filters( 'glm-member-db-admin-get-member-primary-email', '', $memberId ); + if ( !$notify_to ) { + return false; + } + + $memberInfoData = new GlmDataMemberInfo( $this->wpdb, $this->config ); + $memberInfo = $memberInfoData->getActiveInfoForMember( $memberId ); + // get settings $settings = $this->config['settings']; $notify_from = $settings['notify_from']; @@ -94,10 +107,9 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers // Add standard parameters require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; - $viewFile = 'front/coupons/ownerEmail.html'; + $viewFile = 'admin/coupons/memberEmail.html'; - $couponList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-coupons-list"; - $smarty->templateAssign( 'notify_message', $notify_message); + $couponList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-coupons-list&glm_action=list"; $smarty->templateAssign( 'location', 'Member Coupons' ); $smarty->templateAssign( 'name', $coupon['fieldData']['name'] ); $smarty->templateAssign( 'pendingCoupons', $couponList ); @@ -117,7 +129,7 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers // Send confirmation email, set the content type to allow html by using this filter add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) ); - $subject = 'Coupon Form Submission'; + $subject = 'Coupon Approved'; $message = $htmlMessage; $header[] = 'From:' . $notify_from; $header[] = 'Reply-To:' . $notify_from; @@ -129,7 +141,9 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers } /** - * Send the admin user a notice + * Send the admin user a notice. + * + * Sending email notice to the Admin user setting form Coupon Management. */ public function sendAdminNotice( $memberId, $coupon ) { @@ -146,7 +160,7 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers // Add standard parameters require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; - $viewFile = 'front/coupons/ownerEmail.html'; + $viewFile = 'admin/coupons/ownerEmail.html'; $couponList = GLM_MEMBERS_EVENTS_PLUGIN_ADMIN_URL ."?page=glm-members-admin-menu-coupons-list"; $smarty->templateAssign( 'notify_message', $notify_message); @@ -185,7 +199,9 @@ class GlmMembersAdmin_coupon_notification extends GlmDataMembers } /** - * Set content type of the email + * Set content type of the email. + * + * Used as filter for the wp_mail_content_type */ function set_content_type() { diff --git a/models/admin/coupons/list.php b/models/admin/coupons/list.php index 05276e7..57d4b5c 100644 --- a/models/admin/coupons/list.php +++ b/models/admin/coupons/list.php @@ -298,6 +298,9 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons if ( $old_coupon_status == 20 && $new_status == 10 ) { // Update approved timestamp. $this->updateTimestamp('approved', $this->couponID); + if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest']) ) { + $notification->sendMemberNotice( $member_id, $coupon); + } } else if ( $lockedToMember && $old_coupon_status == 10 && $new_status == 20 ) { // Here the status is changing from active to pending. (member edit) // Send notice to admin user diff --git a/views/admin/coupons/memberEmail.html b/views/admin/coupons/memberEmail.html new file mode 100644 index 0000000..228ae88 --- /dev/null +++ b/views/admin/coupons/memberEmail.html @@ -0,0 +1,25 @@ + + + + + + +

Coupon Approval Notification

+ +
+

Your coupon has been approved!

+
+ + + + + + +
Coupon Name:{$name}
+ +
+

A Coupon has been approved.

+

To view it, please go to the coupons page in your admin.

+
+ + diff --git a/views/front/coupons/ownerEmail.html b/views/admin/coupons/ownerEmail.html similarity index 100% rename from views/front/coupons/ownerEmail.html rename to views/admin/coupons/ownerEmail.html -- 2.17.1