Adding class for notices
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 21 Nov 2016 21:45:37 +0000 (16:45 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 21 Nov 2016 21:45:37 +0000 (16:45 -0500)
To notify admin when member updates or adds coupon.

classes/helper/notification.php [new file with mode: 0644]
models/admin/coupons/list.php

diff --git a/classes/helper/notification.php b/classes/helper/notification.php
new file mode 100644 (file)
index 0000000..fc13911
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Coupon Member Notification
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Steve Sutton <steve@gaslightmedia.com>
+ * @license  http://www.galightmedia.com Gaslightmedia
+ * @release  1
+ */
+
+// Load the Member Data class
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMembers.php';
+
+// Extend the member class
+class GlmMembersAdmin_coupon_notification extends GlmDataMembers
+{
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This constructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object Word Press database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        /*
+         * Run constructor for the Coupons class
+         */
+        parent::__construct($wpdb, $config);
+    }
+
+
+    /**
+     * Send the member a notice
+     */
+    public function sendMemberNotice()
+    {
+
+    }
+
+    /**
+     * Send the admin user a notice
+     */
+    public function sendAdminNotice( $memberId )
+    {
+        echo '<pre>$memberId: ' . print_r( $memberId, true ) . '</pre>';
+        $member = $this->getEntry( $memberId );
+        echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
+        $settings       = $this->config['settings'];
+        $notify_to      = $settings['notify_to'];
+        $notify_from    = $settings['notify_from'];
+        $notify_message = $settings['notify_message'];
+    }
+}
index 1900c33..cc95829 100644 (file)
@@ -135,6 +135,9 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
         $namesList         = false;
         $enable_members    = $this->config['settings']['enable_members'];
 
+        include_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH . '/helper/notification.php';
+        $notification = new GlmMembersAdmin_coupon_notification( $this->wpdb, $this->config );
+
         // Check if there's a logged in user who is locked to their own entity
         $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
         if ($lockedToMember) {
@@ -261,6 +264,12 @@ class GlmMembersAdmin_coupons_list extends GlmDataCoupons
                 break;
 
             case 'update':
+                // test conditions for sending out notice need to be setup here
+                // True if the member is editing the record and the status
+                // turns to pending
+                if ( isset( $_REQUEST['ref_dest'] ) && $member_id = filter_var( $_REQUEST['ref_dest']) ) {
+                    $notification->sendAdminNotice( $member_id );
+                }
                 // Get the original Coupon Status. Before the update.
                 $old_coupon_status = $this->wpdb->get_var(
                     $this->wpdb->prepare(