From 10c8e5d5200663152b8182cdfaa506d5d388153d Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 7 Dec 2016 17:11:51 -0500 Subject: [PATCH] Working on the member detail page for the member coupons Adding args to shortcode for the member id to go through. Adding the member id to the pdf generator. Adding styles for the image to be centered in each coupon. --- css/front.css | 11 ++++ models/admin/ajax/pdfCoupons.php | 4 ++ models/front/coupons/list.php | 19 +++++++ setup/frontHooks.php | 9 ++++ setup/shortcodes.php | 2 + views/front/coupons/list.html | 42 ++++++++-------- views/front/coupons/memberDetail.html | 72 +++++++++++++++++++++++++++ 7 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 views/front/coupons/memberDetail.html diff --git a/css/front.css b/css/front.css index cafc15a..a0f1263 100644 --- a/css/front.css +++ b/css/front.css @@ -1,3 +1,7 @@ +#glm-member-detail-coupons-container { + display: none; + padding: 10px; +} .coupon-row { display: block; width: 100%; @@ -9,6 +13,13 @@ margin: 5px; border: 1px dashed lightgrey; } +.coupon-item img { + margin: 0 auto; + display: block; +} +.member-detail .coupon-item { + width: 48%; +} .coupon-item-wrap { padding: 20px; } diff --git a/models/admin/ajax/pdfCoupons.php b/models/admin/ajax/pdfCoupons.php index c4611f4..71f1490 100644 --- a/models/admin/ajax/pdfCoupons.php +++ b/models/admin/ajax/pdfCoupons.php @@ -71,6 +71,10 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons $where = "current_date BETWEEN T.start_date AND T.end_date AND T.status = 10"; + if ( isset( $_REQUEST['member'] ) && $memberId = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ) ) { + $where .= " AND T.ref_dest = " . $_REQUEST['member']; + } + $coupons = $this->getList( $where ); if ( isset( $coupons ) && !empty( $coupons ) ) { diff --git a/models/front/coupons/list.php b/models/front/coupons/list.php index 279a5ad..889c31e 100644 --- a/models/front/coupons/list.php +++ b/models/front/coupons/list.php @@ -52,6 +52,9 @@ class GlmMembersFront_coupons_list extends GlmDataCoupons */ public function modelAction( $actionData = false ) { + $memberId = false; + + //echo '
$actionData: ' . print_r( $actionData, true ) . '
'; $action = ''; $view = 'list.html'; $coupons = $categories = array(); @@ -60,6 +63,10 @@ class GlmMembersFront_coupons_list extends GlmDataCoupons // end_date within the current_date $where = "current_date BETWEEN T.start_date AND T.end_date AND T.status = 10"; + if ( isset( $actionData['request']['member'] ) && $memberId = filter_var( $actionData['request']['member'], FILTER_VALIDATE_INT ) ) { + $where .= " AND T.ref_dest = " . $actionData['request']['member']; + } + $coupons = $this->getList( $where ); // Arrange the $coupons so they're grouped by the categories. @@ -77,9 +84,21 @@ class GlmMembersFront_coupons_list extends GlmDataCoupons // sort them by category name ksort( $categories ); + // check the $actionData for a template argument + if ( isset( $actionData['request']['template'] ) && $actionData['request']['template'] ) { + switch ( $actionData['request']['template'] ) { + case 'member-detail': + $view = 'memberDetail.html'; + break; + default: + $view = 'list.html'; + break; + } + } // Compile template data $templateData = array( + 'member_id' => $memberId, 'coupons' => $coupons, 'categories' => $categories, 'imgUrl' => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/small/', diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 2285c70..b3784a4 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -25,3 +25,12 @@ * * *** Also note that parameters will be in the context of the main front controller constructor. *** */ +// Add content to member detail page - Get it from the existing coupon shortcode +add_filter('glm-member-db-front-members-detail-descriptionAfter', function($content, $id) { + $eventData = do_shortcode('[glm-members-coupons-list member='.$id.' template="member-detail"]'); + $content .= $eventData; + return $content; + }, + 10, + 2 +); diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 580c3ee..e637273 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -92,6 +92,8 @@ $glmMembersCouponsShortcodes = array( 'action' => 'list', 'table' => false, 'attributes' => array( + 'member' => false, + 'template' => false, ), ), ); diff --git a/views/front/coupons/list.html b/views/front/coupons/list.html index 5168b36..8152ceb 100644 --- a/views/front/coupons/list.html +++ b/views/front/coupons/list.html @@ -2,33 +2,33 @@

List Coupons

- + {if $categories} - {foreach $categories as $catName => $coupons} - {if $catName != '1-category'} -

{$catName}

- {else} -
- {/if} + {foreach $categories as $catName => $coupons} + {if $catName != '1-category'} +

{$catName}

+ {else} +
+ {/if}
- {if $coupons} - {foreach $coupons as $coupon} -
-
-
- {if $coupon.ref_dest}

{$coupon.ref_dest}

{/if} -

{$coupon.name}

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

{$coupon.ref_dest}

{/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} -
+
+ {/foreach} {/if}
diff --git a/views/front/coupons/memberDetail.html b/views/front/coupons/memberDetail.html new file mode 100644 index 0000000..8ed9fba --- /dev/null +++ b/views/front/coupons/memberDetail.html @@ -0,0 +1,72 @@ +
Coupons
+
+
+ + + + {if $categories} + {foreach $categories as $catName => $coupons} + {if $catName != '1-category'} +

{$catName}

+ {else} +
+ {/if} +
+ {if $coupons} + {foreach $coupons as $coupon} +
+
+
+ {if $coupon.ref_dest}

{$coupon.ref_dest}

{/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} +
+
+{literal} + +{/literal} -- 2.17.1