WIP for setup of first model and view
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 16 Nov 2016 15:40:55 +0000 (10:40 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 16 Nov 2016 15:40:55 +0000 (10:40 -0500)
Remove Ultisnip directory

index.php
models/admin/coupons/index.php [new file with mode: 0644]
setup/databaseScripts/UltiSnips/sql.snippets [deleted file]
setup/validActions.php
views/admin/coupons/index.html [new file with mode: 0644]

index 83193e5..f28eda8 100644 (file)
--- a/index.php
+++ b/index.php
@@ -108,7 +108,7 @@ function glmMembersCouponsPluginRequired() {
         </div>
     ';
 }
-$plugin_name = 'glm-member-db/index.php';
+$plugin_name = 'glm-member-db-coupons/index.php';
 $is_active = is_plugin_active($plugin_name);
 if ($is_active != '1') {
     add_action( 'admin_notices', 'glmMembersCouponsPluginRequired' );
diff --git a/models/admin/coupons/index.php b/models/admin/coupons/index.php
new file mode 100644 (file)
index 0000000..ab6c37d
--- /dev/null
@@ -0,0 +1,159 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Coupons Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Coupons data abstract
+//require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCoupons.php';
+
+class GlmMembersAdmin_coupons_index
+    // extends GlmDataCoupons
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Coupon ID
+     *
+     * @var $couponID
+     * @access public
+     */
+    public $couponID = false;
+
+    /**
+     * 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 WordPress 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 data class
+         *
+         * Note, the third parameter is a flag that indicates to the Contacts
+         * data class that it should flag a group of fields as 'view_only'.
+         */
+        parent::__construct(false, false, true);
+
+    }
+
+    public function modelAction($actionData = false)
+    {
+
+        $memberID       = false;
+        $lockedToMember = false;
+        $lockedWhereT   = 'true';
+        $lockedWhere    = 'true';
+        $numbCoupons     = 0;
+        $numbPending    = 0;
+        $namesList      = false;
+        $haveCategories = 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;
+            $lockedToMember = $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;
+        }
+
+        // Check for required Coupon Categories
+        require_once GLM_MEMBERS_COUPONS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
+        $CouponCategories = new GlmDataCouponsCategories($this->wpdb, $this->config);
+        $couponCategoriesStats = $CouponCategories->getStats();
+        if ($couponCategoriesStats && $couponCategoriesStats > 0) {
+            $haveCategories = true;
+        }
+
+        // Get full list of names matching this where clause for search box
+        $namesList = $this->getIdName($lockedWhereT);
+
+        // Get number of coupons
+        $numbCoupons = $this->getStats($lockedWhere);
+
+        // I know this is awkward, but we if there's anything that follows these we need " AND " appended.
+        if ($lockedWhereT != '') {
+            $lockedWhereT .= ' AND ';
+        }
+        if ($lockedWhere != '') {
+            $lockedWhere .= ' AND ';
+        }
+
+        // Get number of coupons pending
+        $numbPending = $this->getStats($lockedWhere.' status = '.$this->config['status_numb']['Pending']);
+
+        // Get list of Pending Coupons
+        $pending = $this->getIdName($lockedWhereT.' T.status = '.$this->config['status_numb']['Pending']);
+
+
+        // Compile template data
+        $templateData = array(
+            'lockedToMember' => $lockedToMember,
+            'numbCoupons'    => $numbCoupons,
+            'pending'        => $pending,
+            'namesList'      => $namesList,
+            'numbPending'    => $numbPending,
+            'haveCategories' => $haveCategories
+        );
+             // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => 'admin/coupons/index.html',
+            'data'          => $templateData
+        );
+
+    }
+
+
+}
diff --git a/setup/databaseScripts/UltiSnips/sql.snippets b/setup/databaseScripts/UltiSnips/sql.snippets
deleted file mode 100644 (file)
index 864ce4e..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-snippet ctable
--- $1
-CREATE TABLE \{prefix\}$2 (
-    id INT NOT NULL AUTO_INCREMENT,
-    $0,
-    PRIMARY KEY (id)
-);
-
-endsnippet
index 9ab8b83..396bd6c 100644 (file)
 
 $glmMembersCouponsAddOnValidActions = array(
     'adminActions' => array(
+        'coupons' => array(
+            'coupons' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG
+        )
     ),
     'frontActions' => array(
     )
 );
 
-?>
\ No newline at end of file
+?>
diff --git a/views/admin/coupons/index.html b/views/admin/coupons/index.html
new file mode 100644 (file)
index 0000000..eb39bf6
--- /dev/null
@@ -0,0 +1,107 @@
+{include file='admin/coupons/header.html'}
+
+{if apply_filters('glm_members_permit_admin_coupons_index_add_coupon', true)}
+    <a href="{$thisUrl}?page={$thisPage}&glm_action=list&option=add" class="button button-primary glm-button glm-right">Add A New Event</a>
+{/if}
+
+<table class="glm-admin-table">
+    <tr>
+        <td colspan="2" align="">
+            <input  id="glmEventsList" type="text" id="autoTest" style="margin-left: 2em;">
+            <span class="glm-left">Events Search:</span>
+        </td>
+    </tr>
+
+    {if apply_filters('glm_members_permit_admin_coupons_index_coupon_config_warning', true)}
+      {if !$haveCategories}
+        <tr>
+            <th><span class="glm-error">You do not have any Events Categories setup.</span></th>
+            <td><a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=couponCategories">Click here to add Event Categories.</a></td>
+        </tr>
+      {/if}
+    {/if}
+
+{if $numbEvents == 0}
+    <tr><td colspan="2">&nbsp;</td></tr>
+    <tr>
+       <th> <span class="glm-error">You do not have any coupons listed.</span></th>
+        <td><a href="{$thisUrl}?page={$thisPage}&glm_action=list&option=add">Click here to create your first coupon.</a></td>
+    </tr>
+{/if}
+</table>
+
+<table class="glm-admin-table">
+    <tr><th>Number of Events Listed: </th><td>{$numbEvents}</td></tr>
+    <tr><th>Number Pending: </th><td>{$numbPending}</td></tr>
+</table>
+
+{if $pending}
+    <h3 class="glm-error">&nbsp;<br>Events Pending Review</h3>
+
+    <table class="wp-list-table widefat fixed posts glm-admin-table"">
+        <thead>
+            <tr>
+                <th>Event Name</th>
+            </tr>
+        </thead>
+        <tbody>
+    {assign var="i" value="0"}
+    {foreach $pending as $p}
+        {if $i++ is odd by 1}
+            <tr>
+        {else}
+            <tr class="alternate">
+        {/if}
+                <td>
+                    <a href="{$thisUrl}?page=glm-members-admin-menu-coupons-list&glm_action=list&option=edit&coupon={$p.id}">{$p.name}</a>
+                </td>
+            </tr>
+    {/foreach}
+        </tbody>
+    </table>
+{/if}
+
+{if $namesList}
+    <script type="text/javascript">
+    jQuery(document).ready(function($) {
+
+        /*
+         * Do autocomplete search for coupon
+         * label: What will be searched
+         * value: What will be displayed when selected
+         * id: Member id added so we can go to the coupon while showing what was selected
+         * Also note that autocomplete does not properly render HTML codes, so we
+         * "unescape" them for HTML in Smarty.
+         */
+        var availableTags = [
+        {foreach $namesList as $e}
+            { label: "{$e.name|replace:'"':"'"}", value: "{$e.name|replace:'"':"'"}", id: '{$e.id}' },
+        {/foreach}
+        ];
+
+        $( "#glmEventsList" ).autocomplete({
+             source: availableTags,
+             html: true,
+             select: function( coupon, ui ) {
+                 var couponID = ui.item.id;
+                    {if $lockedToMember}
+                     window.location.replace("{$adminUrl}?page=glm-members-admin-menu-coupons-list&glm_action=list&option=edit&coupon=" + couponID );
+                    {else}
+                     window.location.replace("{$adminUrl}?page=glm-members-admin-menu-coupons-index&glm_action=list&option=edit&coupon=" + couponID );
+                    {/if}
+                 },
+                 response: function(coupon, ui) {
+                     if (!ui.content.length) {
+                         var noResult = { value:"",label:"No results found" };
+                         ui.content.push(noResult);
+                     }
+                 }
+             });
+
+        });
+
+    </script>
+{/if}
+
+{include file='admin/footer.html'}
+