From 5628c19f19477a6f889cac8fdc92b3c2032c4fe8 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 21 Nov 2016 16:45:37 -0500 Subject: [PATCH] Adding class for notices To notify admin when member updates or adds coupon. --- classes/helper/notification.php | 98 +++++++++++++++++++++++++++++++++ models/admin/coupons/list.php | 9 +++ 2 files changed, 107 insertions(+) create mode 100644 classes/helper/notification.php diff --git a/classes/helper/notification.php b/classes/helper/notification.php new file mode 100644 index 0000000..fc13911 --- /dev/null +++ b/classes/helper/notification.php @@ -0,0 +1,98 @@ + + * @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 '
$memberId: ' . print_r( $memberId, true ) . '
'; + $member = $this->getEntry( $memberId ); + echo '
$member: ' . print_r( $member, true ) . '
'; + $settings = $this->config['settings']; + $notify_to = $settings['notify_to']; + $notify_from = $settings['notify_from']; + $notify_message = $settings['notify_message']; + } +} diff --git a/models/admin/coupons/list.php b/models/admin/coupons/list.php index 1900c33..cc95829 100644 --- a/models/admin/coupons/list.php +++ b/models/admin/coupons/list.php @@ -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( -- 2.17.1