WIP work on notifications
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 13 Mar 2018 21:26:04 +0000 (17:26 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 13 Mar 2018 21:26:04 +0000 (17:26 -0400)
Need to work on the notifications for payments and invoices.

classes/billingSupport.php
classes/notifications.php
views/admin/settings/editNotificationType.html

index 0f70398..923184e 100644 (file)
@@ -19,6 +19,7 @@ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoices.php';
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoiceTypes.php';
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataNotificationTypes.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php';
 
 class GlmBillingSupport
 {
@@ -233,6 +234,7 @@ class GlmBillingSupport
                 '%s',
             )
         );
+
     }
 
     /**
@@ -296,6 +298,28 @@ class GlmBillingSupport
                 '%s'
             )
         );
+
+        // Create Notification Object
+        $Notifications = new GlmNotifications( $this->wpdb, $this->config );
+
+        echo '<pre>$type: ' . print_r( $type, true ) . '</pre>';
+
+        // Trigger sending the email notifications for send by action 'payment received'
+        switch ( $type ) {
+
+        case $this->config['transaction_numb']['Invoice']:
+        case $this->config['transaction_numb']['Payment']:
+            $notices = $Notifications->getNotificationsWithSendByAction( $type );
+            echo '<pre>$notices: ' . print_r( $notices, true ) . '</pre>';
+            foreach ( $notices as $notice ) {
+                $Notifications->sendEmailNotification( $notice['id'], $account );
+            }
+            break;
+        default:
+            break;
+
+        }
+
     }
 
     /**
index b58b5c8..1a625aa 100644 (file)
@@ -88,9 +88,9 @@ class GlmNotifications
         }
 
         // get the Notification type
-        var_dump( $notification_id );
+        // var_dump( $notification_id );
         $notification_type = $this->getNotificationTypeById( $notification_id );
-        echo '<pre>$notification_type: ' . print_r( $notification_type, true ) . '</pre>';
+        // echo '<pre>$notification_type: ' . print_r( $notification_type, true ) . '</pre>';
         if ( !$notification_type ) {
             // If there's no notification type then return false.
             return false;
@@ -124,13 +124,13 @@ class GlmNotifications
                 'phone' => $account['billing_phone'],
             )
         );
-        echo '<pre>$notification_type[message]: ' . print_r( $notification_type['message'], true ) . '</pre>';
+        // echo '<pre>$notification_type[message]: ' . print_r( $notification_type['message'], true ) . '</pre>';
         $notification_message = $this->parseSmartyTemplateString(
             $account_data,
             wpautop( $notification_type['message'] )
         );
-        echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
-        echo '<pre>$notification_message: ' . print_r( $notification_message, true ) . '</pre>';
+        // echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
+        // echo '<pre>$notification_message: ' . print_r( $notification_message, true ) . '</pre>';
         // exit;
 
         $smarty->templateAssign( 'title', $notification_type['subject'] );
@@ -284,7 +284,7 @@ class GlmNotifications
                    FROM "  . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX .  "notification_types
                   WHERE send_by_action
                     AND send_action = %d",
-                $this->config['send_action_numb'][$type]
+                $this->config['send_action'][$type]
             ),
             ARRAY_A
         );
index b71f269..c52b7e6 100644 (file)
@@ -15,6 +15,7 @@
         <input type="hidden" name="option" value="insert">
     {/if}
 
+{debug}
     <table class="glm-admin-table glm-event-table">
 
         <tr>
@@ -66,7 +67,7 @@
             <td>
                 <select name="send_action">
                     {foreach $send_action as $id => $val}
-                        <option value="{$id}">{$val}</option>
+                        <option value="{$id}"{if $id == $notification.fieldData.send_action} selected{/if}>{$val}</option>
                     {/foreach}
                 </select>
             </td>