From 9154fad859a4d86d07e6dc0952d6f3612213d94d Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 21 Nov 2016 10:15:05 -0500 Subject: [PATCH] Setting up the shortcode Set up shortcode valid action. Set up the ajax valid action. --- css/front.css | 77 ++++++++++++++++++++++++++++ models/front/coupons/list.php | 94 +++++++++++++++++++++++++++++++++++ setup/shortcodes.php | 19 ++++++- setup/validActions.php | 3 ++ views/front/coupons/list.html | 29 +++++++++++ 5 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 css/front.css create mode 100644 models/front/coupons/list.php create mode 100644 views/front/coupons/list.html diff --git a/css/front.css b/css/front.css new file mode 100644 index 0000000..cafc15a --- /dev/null +++ b/css/front.css @@ -0,0 +1,77 @@ +.coupon-row { + display: block; + width: 100%; +} +.coupon-item { + display: inline-table; + width: 30%; + padding: 0; + margin: 5px; + border: 1px dashed lightgrey; +} +.coupon-item-wrap { + padding: 20px; +} +.coupon-item-wrap h3 { + text-align: center; +} +.coupon-row h2 { + font-size: 1.45rem; +} +.coupon-row h3 { + font-size: 1.3rem; +} +.coupon-expires { + margin: 20px 5px 5px 0; + float: right; + font-size: .8rem; +} +.coupon-descr { + font-size: .9rem; +} +.coupon-url { + float: left; + font-size: .8rem; + margin: 20px 0 5px 5px; +} +.coupon-select { + background-color: lightgrey; + width: 100%; + height: 40px; + padding: 10px; +} +.glm_coupon_search_select, .glm_coupon_search_submit { + width: 45%; + margin-left: 0 !important;; +} +.glm_coupon_print { + width: 25%; + float: left; + margin-left: 20px !important; +} +/* small */ +@media screen and (max-width: 40em) { + .coupon-item { + width: 100%; + } + .glm_coupon_search_select, .glm_coupon_search_submit { + width: 100%; + margin-left: 0 !important;; + } + .glm_coupon_print { + width: 100%; + float: none; + margin-left: 0 !important;; + } +} +/* medium */ +@media screen and (min-width: 40.63em) and (max-width: 64em) { + .coupon-item { + width: 45%; + } + .glm_coupon_print { + width: 45%; + float: none; + margin-left: 0 !important;; + } +} diff --git a/models/front/coupons/list.php b/models/front/coupons/list.php new file mode 100644 index 0000000..b9b4b6b --- /dev/null +++ b/models/front/coupons/list.php @@ -0,0 +1,94 @@ + + * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt} + */ +class GlmMembersFront_coupons_list extends GlmDataCoupons +{ + + public $wpdb; + public $config; + + /** + * __construct + * + * @param mixed $wpdb The main Word Press DB Object + * @param mixed $config The main Config + * + * @access public + * @return void + */ + public function __construct($wpdb, $config) + { + $this->wpdb = $wpdb; + $this->config = $config; + + parent::__construct(false, false); + } + + /** + * modelAction + * + * @param bool $actionData Action Data passed to the modelAction + * + * @access public + * @return void + */ + public function modelAction( $actionData = false ) + { + $action = ''; + $view = 'list.html'; + $coupons = $categories = array(); + + // Need to only pull in active coupons that have the start_date and + // end_date within the current_date + $where = "current_date BETWEEN T.start_date AND T.end_date AND T.status = 10"; + + $coupons = $this->getList( $where ); + + // Arrange the $coupons so they're grouped by the categories. + if ( is_array( $coupons ) && !empty( $coupons ) ) { + foreach ( $coupons as $coupon ) { + if ( is_array( $coupon['categories'] ) && !empty( $coupon['categories'] ) ) { + foreach ( $coupon['categories'] as $category ) { + $categories[$category['name']][] = $coupon; + } + } + } + } + + + // Compile template data + $templateData = array( + 'coupons' => $coupons, + 'categories' => $categories, + 'imgUrl' => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/small/', + ); + error_reporting(E_ALL ^ E_NOTICE); + return array( + 'status' => $status, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'front/coupons/' . $view, + 'data' => $templateData, + 'settings' => $settings, + ); + } + +} diff --git a/setup/shortcodes.php b/setup/shortcodes.php index d7ba3ca..580c3ee 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -85,9 +85,24 @@ * * */ - $glmMembersCouponsShortcodes = array( + 'glm-members-coupons-list' => array( + 'plugin' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, + 'menu' => 'coupons', + 'action' => 'list', + 'table' => false, + 'attributes' => array( + ), + ), ); -$glmMembersCouponsShortcodesDescription = ''; +$glmMembersCouponsShortcodesDescription = ' + + [glm-members-coupons-list] +   + + Show the Coupons + + +'; diff --git a/setup/validActions.php b/setup/validActions.php index 1716329..954aa2f 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -32,6 +32,9 @@ $glmMembersCouponsAddOnValidActions = array( 'adminActions' => array( + 'ajax' => array( + 'pdfOutput' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, + ), 'coupons' => array( 'index' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, 'list' => GLM_MEMBERS_COUPONS_PLUGIN_SLUG, diff --git a/views/front/coupons/list.html b/views/front/coupons/list.html new file mode 100644 index 0000000..cfac1b6 --- /dev/null +++ b/views/front/coupons/list.html @@ -0,0 +1,29 @@ +
+

List Coupons

+
+ + + {if $categories} + {foreach $categories as $catName => $coupons} +

{$catName}

+
+ {if $coupons} + {foreach $coupons as $coupon} +
+
+
+ {if $coupon.glm_coupons_member}

{$coupon.glm_coupons_member}

{/if} +

{$coupon.name}

+ {if $coupon.image}{/if} +
{$coupon.descr}
+ {if $coupon.url}{/if} +
Expires: {$coupon.expire.timestamp|date_format:"%m/%d/%Y"}
+
+
+ {/foreach} + {/if} + {/foreach} +
+ {/if} +
+
-- 2.17.1