WIP for pending and approval notices
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Dec 2016 16:22:08 +0000 (11:22 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Dec 2016 18:27:29 +0000 (13:27 -0500)
Admin gets notified when member submits the coupon.
Member will be notified when admin approves the coupon.

classes/helper/notification.php
models/admin/coupons/list.php
views/admin/coupons/memberEmail.html [new file with mode: 0644]
views/admin/coupons/ownerEmail.html [new file with mode: 0644]
views/front/coupons/ownerEmail.html [deleted file]

index 1d99fa6..f8cb44c 100644 (file)
@@ -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()
     {
index 05276e7..57d4b5c 100644 (file)
@@ -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 (file)
index 0000000..228ae88
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    </head>
+    <body>
+        <h1 id="title"> Coupon Approval Notification</h1>
+
+        <div style="width: 500px">
+            <p> Your coupon has been approved! </p>
+        </div>
+
+        <table cellspacing="0" cellpadding="0" width="500" style="background: lightgrey;border:1px solid #ccc;border-collapse:collapse;">
+            <tr>
+                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Coupon Name:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$name}</td>
+            </tr>
+        </table>
+
+        <div id="emailFooter">
+            <p style="margin-bottom: 0px;">A Coupon has been approved.</p>
+            <p style="margin-top: 0px;">To view it, please go to the <a style="color: rgb(5, 104, 179);" href="{$pendingCoupons}"> coupons </a> page in your admin.</p>
+        </div>
+    </body>
+</html>
diff --git a/views/admin/coupons/ownerEmail.html b/views/admin/coupons/ownerEmail.html
new file mode 100644 (file)
index 0000000..f591448
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    </head>
+    <body>
+        <h1 id="title"> Coupon Submission Notification</h1>
+
+        {if $notify_message}
+        <div style="width: 500px">
+            <p> {$notify_message} </p>
+        </div>
+        {/if}
+
+        <table cellspacing="0" cellpadding="0" width="500" style="background: lightgrey;border:1px solid #ccc;border-collapse:collapse;">
+            <tr>
+                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Member Name:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$member.name}</td>
+            </tr>
+            <tr>
+                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Coupon Name:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$name}</td>
+            </tr>
+            <tr>
+                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Coupon Start Date: </td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;"> {$start_date.timestamp|date_format:"%D"} </td>
+            </tr>
+            <tr>
+                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;" >Coupon End Date:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$end_date.timestamp|date_format:"%D"}</td>
+            </tr>
+            <tr>
+                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;" >Coupon Expire Date:</td>
+                <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$expire.timestamp|date_format:"%D"}</td>
+            </tr>
+        </table>
+
+        <div id="emailFooter">
+            <p style="margin-bottom: 0px;">A new Coupon has been added to your Website from your &quot;{$location}&quot; page.</p>
+            <p style="margin-top: 0px;">To approve it, please go to the <a style="color: rgb(5, 104, 179);" href="{$pendingCoupons}"> coupons </a> page in your admin.</p>
+        </div>
+    </body>
+</html>
diff --git a/views/front/coupons/ownerEmail.html b/views/front/coupons/ownerEmail.html
deleted file mode 100644 (file)
index f591448..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <meta http-equiv="content-type" content="text/html;charset=utf-8">
-    </head>
-    <body>
-        <h1 id="title"> Coupon Submission Notification</h1>
-
-        {if $notify_message}
-        <div style="width: 500px">
-            <p> {$notify_message} </p>
-        </div>
-        {/if}
-
-        <table cellspacing="0" cellpadding="0" width="500" style="background: lightgrey;border:1px solid #ccc;border-collapse:collapse;">
-            <tr>
-                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Member Name:</td>
-                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$member.name}</td>
-            </tr>
-            <tr>
-                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Coupon Name:</td>
-                <td style="width:200px;padding:5px;border:1px solid #ccc;">{$name}</td>
-            </tr>
-            <tr>
-                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;">Coupon Start Date: </td>
-                <td style="width:200px;padding:5px;border:1px solid #ccc;"> {$start_date.timestamp|date_format:"%D"} </td>
-            </tr>
-            <tr>
-                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;" >Coupon End Date:</td>
-                <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$end_date.timestamp|date_format:"%D"}</td>
-            </tr>
-            <tr>
-                <td style="font-weight:bold;width:200px;padding:5px;border:1px solid #ccc;" >Coupon Expire Date:</td>
-                <td style="width:200px;padding:5px;border:1px solid #ccc;" >{$expire.timestamp|date_format:"%D"}</td>
-            </tr>
-        </table>
-
-        <div id="emailFooter">
-            <p style="margin-bottom: 0px;">A new Coupon has been added to your Website from your &quot;{$location}&quot; page.</p>
-            <p style="margin-top: 0px;">To approve it, please go to the <a style="color: rgb(5, 104, 179);" href="{$pendingCoupons}"> coupons </a> page in your admin.</p>
-        </div>
-    </body>
-</html>