Adding billing dashboard widget
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 16 Apr 2018 19:51:15 +0000 (15:51 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 16 Apr 2018 19:51:15 +0000 (15:51 -0400)
Billing member dashboard widget.
Gives link to the correct section.
Renewal membership link if pending or expired.
Billing Info if active.

models/admin/dashboard/billing.php [new file with mode: 0644]
setup/adminHooks.php
setup/validActions.php
views/admin/dashboard/billing.html [new file with mode: 0644]

diff --git a/models/admin/dashboard/billing.php b/models/admin/dashboard/billing.php
new file mode 100644 (file)
index 0000000..a3473e1
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Members Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Steve Sutton <steve@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataBilling.php';
+
+/**
+ * Dashboard Class Model
+ *
+ * Each Add-On can have one or more dashboards.
+ */
+
+class GlmMembersAdmin_dashboard_billing //extends GlmDataBilling
+{
+    /**
+     * Word Press Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /**
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        // parent::__construct(false, false);
+
+    }
+
+    /**
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * '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.
+     *
+     */
+    public function modelAction ( $actionData = false )
+    {
+
+        $success        = true;
+        $memberID       = false;
+        $account_status = false;
+        $billing_link   = false;
+        $billing_label  = false;
+
+
+        // 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) {
+            $memberID       = $lockedToMember;
+            $this->memberID = $memberID;
+            $lockedToMember = $memberID;
+            require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
+            $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+            $accountID = $this->wpdb->get_var(
+                $this->wpdb->prepare(
+                    "SELECT id
+                       FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                      WHERE ref_dest = %d",
+                    $this->memberID
+                )
+            );
+            $account_status = apply_filters( 'glm-billing-get-account-status', '', $accountID );
+            switch( $account_status ) {
+            case 'Active':
+                $billing_link  = 'glm_action=billing&member=' . $memberID . '&option=account';
+                $billing_label = 'Billing Account Info';
+                break;
+            case 'Pending':
+                $billing_link = 'glm_action=billing&member=' . $memberID . '&option=renew';
+                $billing_label = 'Renewal Membership';
+                break;
+            case 'Expired':
+                $billing_link = 'glm_action=billing&member=' . $memberID . '&option=renew';
+                $billing_label = 'Renewal Membership';
+                break;
+            default:
+                break;
+            }
+        }
+
+        // Compile template data.
+        $templateData = array(
+            'lockedToMember' => $lockedToMember,
+            'memberID'       => $memberID,
+            'account_status' => $account_status,
+            'billing_link'   => $billing_link,
+            'billing_label'  => $billing_label,
+        );
+
+        // Return status, suggested view, and data to controller.
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/dashboard/billing.html',
+            'data'             => $templateData
+        );
+
+    }
+
+}
index fa09025..cacc7c5 100644 (file)
  *
  *  Also note that parameters will be in the context of the main admin controller constructor.
   */
-
+add_filter(
+    'glm-member-db-dashboard-member-widgets',
+    function( $member = null ){
+        return $this->controller( 'dashboard', 'billing', $member );
+    },
+    9,
+    1
+);
index 4c0975a..2419d94 100644 (file)
@@ -88,6 +88,9 @@ $glmMembersBillingAddOnValidActions = array(
         'member' => array(
             'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
         ),
+        'dashboard' => array(
+            'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+        ),
     ),
     'frontActions' => array(
         'billing' => array(
diff --git a/views/admin/dashboard/billing.html b/views/admin/dashboard/billing.html
new file mode 100644 (file)
index 0000000..cf2da4c
--- /dev/null
@@ -0,0 +1,13 @@
+<div class="glm-widget-container">
+    <div class="glm-widget">
+        <h2>
+        Billing Dashboard
+        </h2>
+        <div class="glm-widget-content">
+            Membership Status: {$account_status}
+            <a href="{$thisUrl}?page={$thisPage}&{$billing_link}">{$billing_label}</a>
+
+        </div>
+    </div>
+</div>
+<br style="clear: both;">