From 866279ed588a9194409a22bfbfd5262d647e5c36 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 24 Aug 2015 16:19:18 -0400 Subject: [PATCH] Add front controller functionality Output Coupons --- controllers/admin.php | 4 +- controllers/front.php | 104 +++++++++++++++++++++++++++++++++++++ models/coupon.php | 2 +- views/front/couponList.php | 12 +++++ 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 views/front/couponList.php diff --git a/controllers/admin.php b/controllers/admin.php index b8b4391..b005903 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -1,8 +1,8 @@ pluginDirName = $path; + $this->wpdb = $wpdb; + $coupons = new glm_coupons_coupon($path); + add_shortcode('glmcoupons', array($this, 'glm_coupon_shortcode')); + $this->viewDir = $this->pluginDirName . self::FORM_VIEW_DIR; + $this->frontViewDir = $this->viewDir . '/front'; + } + + public function glm_coupon_shortcode($atts) + { + extract(shortcode_atts( + array('category' => '-1'), $atts, 'glmcoupons') + ); + + $output = 'do short code'; + $output = 'glmcoupons category=' . $atts['category']; + $output .= '
' . print_r($atts, true) . '
'; + ob_start(); + $this->list_coupons(); + $output = ob_get_contents(); + ob_end_clean(); + + return $output; + } + + public function search_form() + { + $data = array(); + // use smarty template to output the form + } + + public function list_coupons() + { + global $wpdb, $wp; + + $glm_couponscategory = (isset($_REQUEST['glm_couponscategory'])) + ? filter_var($_REQUEST['glm_couponscategory']) + : false; + + $midnight = strtotime(date('Y-m-d',time()).' 00:00:00'); + $args = array( + 'post_type' => GLM_COUPON_POST_TYPE, + 'meta_query' => array( + array( + 'key' => 'glm_coupons_enddate', + 'value' => $midnight, + 'compare' => '>=' + ), + array( + 'key' => 'glm_coupons_startdate', + 'value' => $midnight, + 'compare' => '<=' + ) + ) + ); + if ($glm_couponscategory) { + $args['tax_query'] = array( + 'relation' => 'AND' + ); + if ($glm_couponscategory) { + $args['tax_query'][] = array( + 'taxonomy' => 'glm_couponscategory', + 'field' => 'id', + 'terms' => $glm_couponscategory + ); + } + } + $coupons = get_posts($args); + $totalCoupons = count($coupons); + $current_url = esc_url(add_query_arg($wp->query_string, '', home_url($wp->request))); + $iterator = 1; + foreach ($coupons as $coupon) { + $custom = get_post_custom($coupon->ID); + $coupon->end = false; + $coupon->glm_coupons_startdate = $custom['glm_coupons_startdate'][0]; + $coupon->glm_coupons_enddate = $custom['glm_coupons_enddate'][0]; + $coupon->glm_coupons_expdate = $custom['glm_coupons_expdate'][0]; + $coupon->glm_coupons_url = $custom['glm_coupons_url'][0]; + if ($iterator == $totalCoupons) { + $coupon->end = true; + } + ++$iterator; + } + include $this->frontViewDir . '/couponList.php'; + return; + } + +} diff --git a/models/coupon.php b/models/coupon.php index b7b7551..db720f0 100644 --- a/models/coupon.php +++ b/models/coupon.php @@ -300,7 +300,7 @@ class glm_coupons_coupon 'menu_position' => 21, 'supports' => array('title', 'editor'), 'has_archive' => true, - 'menu_icon' => 'dashicons-businessman', + 'menu_icon' => 'dashicons-products', 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'coupons'), diff --git a/views/front/couponList.php b/views/front/couponList.php new file mode 100644 index 0000000..68f74d7 --- /dev/null +++ b/views/front/couponList.php @@ -0,0 +1,12 @@ +
+

List Coupons

+
+ +
+

post_title;?>

+
post_content;?>
+
Expires: glm_coupons_expdate);?>
+
+ +
+
-- 2.17.1