Setup coupon dashboard
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 21 Nov 2016 15:43:34 +0000 (10:43 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 21 Nov 2016 15:43:34 +0000 (10:43 -0500)
Setup the block for the dashboard.
Has the Current Running Coupons in the list.

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

diff --git a/models/admin/dashboard/coupons.php b/models/admin/dashboard/coupons.php
new file mode 100644 (file)
index 0000000..79ae418
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Members Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @coupon  glmMembersDatabase
+ * @author   Steve Sutton <steve@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php';
+
+/**
+ * Dashboard Class Model
+ *
+ * Each Add-On can have one or more dashboards.
+ */
+
+class GlmMembersAdmin_dashboard_coupons extends GlmDataCoupons
+{
+    /**
+     * 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;
+        $lockedToMember = false;
+
+        // Get list of member coupons.
+        if ( isset( $this->config['loggedInUser']['contactUser']['ref_dest'] )
+            && $memberID = filter_var( $this->config['loggedInUser']['contactUser']['ref_dest'], FILTER_VALIDATE_INT)
+        ) {
+            $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
+            if ($lockedToMember) {
+                $memberID = $lockedToMember;
+                $lockedToMember = $memberID;
+                $memberWhere = "T.id = $memberID";
+                $lockedWhereT = 'T.ref_type = '.$this->config['ref_type_numb']['Member'].' AND T.ref_dest = '.$memberID;
+                $lockedWhere = 'ref_type = '.$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$memberID;
+                $where = '';
+                //$coupons = $this->getList( $lockedWhereT.$where);
+                $coupons = $this->getList( $lockedWhereT.$where, '', true, 'id', 1, 5 );
+                // If we have some, tell the template
+                if ($coupons && count($coupons['list']) > 0) {
+                    $haveCoupons = true;
+                }
+
+            }
+
+        } else {
+            // This should be the Current Coupons that are current running.
+            $where    = 'T.start_date <= now() and T.end_date >= now()';
+            $coupons = $this->getList( $where );
+            // If we have some, tell the template
+            if ($coupons && count($coupons) > 0) {
+                $haveCoupons = true;
+            }
+        }
+        // If we have list entries - even if it's an empty list
+        $success = true;
+        $haveCoupons = false;
+        if ($coupons !== false) {
+
+            $success = true;
+
+            // If we have any entries
+            if (count($coupons) > 0) {
+                $haveCoupons = true;
+            }
+        }
+        // Compile template data.
+        $templateData = array(
+            'lockedToMember' => $lockedToMember,
+            'haveCoupons'    => $haveCoupons,
+            'coupons'        => (isset($coupons['list']) ? $coupons['list']: $coupons),
+            'memberID'       => $memberID,
+        );
+
+        // Return status, suggested view, and data to controller.
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/dashboard/coupons.html',
+            'data'             => $templateData
+        );
+
+    }
+
+}
index 1bb233d..096b6d2 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 ) {
+        $content = $this->controller( 'dashboard', 'coupons', $member );
+        return $content;
+    },
+    14,
+    1
+);
+add_filter(
+    'glm-member-db-dashboard-member-admin-widgets',
+    function ( $member = null ) {
+        $content = $this->controller( 'dashboard', 'coupons', $member );
+        return $content;
+    },
+    14,
+    1
+);
diff --git a/views/admin/dashboard/coupons.html b/views/admin/dashboard/coupons.html
new file mode 100644 (file)
index 0000000..a49ba6c
--- /dev/null
@@ -0,0 +1,54 @@
+<div class="glm-widget-container">
+    <div class="glm-widget">
+        <h2>
+            <a href="{$thisUrl}?page=glm-members-admin-menu-coupons-list">Coupons</a>
+             {if $lockedToMember}
+            <a href="{$thisUrl}?page=glm-members-admin-menu-coupons-list&glm_action=list&option=add" class="button glm-right">&nbsp;Add a New Coupon for this {$terms.term_member_cap}&nbsp;</a>
+            {else}
+            (Current)
+             {/if}
+        </h2>
+        <div class="glm-widget-content">
+            <table class="wp-list-table striped glm-admin-table">
+                <thead>
+                    <tr>
+                        <th>Coupon</th>
+                        <th>Start</th>
+                        <th>End</th>
+                        <th>Expire</th>
+                    </tr>
+                </thead>
+        <tbody>
+  {if $haveCoupons}
+    {foreach $coupons as $p}
+            <tr>
+                <td class="glm-nowrap">
+        {if $p.ref_type.value}
+             {if $lockedToMember}
+                    <a href="{$thisUrl}?page=glm-members-admin-menu-coupons-list&glm_action=list&option=edit&member={$p.ref_dest_id}&coupon={$p.id}">{$p.name}</a>
+             {else}
+                    <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=coupons&option=edit&member={$p.ref_dest_id}&coupon={$p.id}">{$p.name}</a>
+             {/if}
+        {else}
+                    <a href="{$thisUrl}?page={$thisPage}&glm_action=coupons&option=edit&coupon={$p.id}">{$p.name}</a>
+        {/if}
+                </td>
+                <td>
+                    {$p.start_date.date}
+                </td>
+                <td>
+                    {$p.end_date.date}
+                </td>
+                <td>
+                    {$p.expire.date}
+                </td>
+            </tr>
+    {/foreach}
+  {else}
+            <tr class="alternate"><td colspan="5">(no coupons listed)</td></tr>
+  {/if}
+        </tbody>
+            </table>
+        </div>
+    </div>
+</div>