From 10487eeb63b074c558505e3055a954ee95872d80 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 16 Nov 2016 10:40:55 -0500 Subject: [PATCH] WIP for setup of first model and view Remove Ultisnip directory --- index.php | 2 +- models/admin/coupons/index.php | 159 +++++++++++++++++++ setup/databaseScripts/UltiSnips/sql.snippets | 9 -- setup/validActions.php | 5 +- views/admin/coupons/index.html | 107 +++++++++++++ 5 files changed, 271 insertions(+), 11 deletions(-) create mode 100644 models/admin/coupons/index.php delete mode 100644 setup/databaseScripts/UltiSnips/sql.snippets create mode 100644 views/admin/coupons/index.html diff --git a/index.php b/index.php index 83193e5..f28eda8 100644 --- a/index.php +++ b/index.php @@ -108,7 +108,7 @@ function glmMembersCouponsPluginRequired() { '; } -$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 index 0000000..ab6c37d --- /dev/null +++ b/models/admin/coupons/index.php @@ -0,0 +1,159 @@ + + * @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 index 864ce4e..0000000 --- a/setup/databaseScripts/UltiSnips/sql.snippets +++ /dev/null @@ -1,9 +0,0 @@ -snippet ctable --- $1 -CREATE TABLE \{prefix\}$2 ( - id INT NOT NULL AUTO_INCREMENT, - $0, - PRIMARY KEY (id) -); - -endsnippet diff --git a/setup/validActions.php b/setup/validActions.php index 9ab8b83..396bd6c 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -59,9 +59,12 @@ $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 index 0000000..eb39bf6 --- /dev/null +++ b/views/admin/coupons/index.html @@ -0,0 +1,107 @@ +{include file='admin/coupons/header.html'} + +{if apply_filters('glm_members_permit_admin_coupons_index_add_coupon', true)} + Add A New Event +{/if} + + + + + + + {if apply_filters('glm_members_permit_admin_coupons_index_coupon_config_warning', true)} + {if !$haveCategories} + + + + + {/if} + {/if} + +{if $numbEvents == 0} + + + + + +{/if} +
+ + Events Search: +
You do not have any Events Categories setup.Click here to add Event Categories.
 
You do not have any coupons listed.Click here to create your first coupon.
+ + + + +
Number of Events Listed: {$numbEvents}
Number Pending: {$numbPending}
+ +{if $pending} +

 
Events Pending Review

+ + + + + + + + + {assign var="i" value="0"} + {foreach $pending as $p} + {if $i++ is odd by 1} + + {else} + + {/if} + + + {/foreach} + +
Event Name
+ {$p.name} +
+{/if} + +{if $namesList} + +{/if} + +{include file='admin/footer.html'} + -- 2.17.1