From: Steve Sutton Date: Thu, 24 Sep 2015 16:30:22 +0000 (-0400) Subject: Update for coupons X-Git-Tag: v0.0.2^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=a024eb13f8c0a1ae08330d7e4dff856a48ea5c73;p=WP-Plugins%2Fglm-coupons.git Update for coupons Tying coupons into the Gaslight Media Member DB Plugin. if they have the member plugin it will output a list of the members for the coupon edit page to choose from. --- diff --git a/controllers/front.php b/controllers/front.php index 8b04abb..87b6c21 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -102,11 +102,16 @@ class glm_coupon_front $coupons = get_posts($args); foreach ($coupons as $coupon) { $custom = get_post_custom($coupon->ID); + if ($custom['glm_coupons_member'][0]) { + $member_data = $this->_getMemberData($custom['glm_coupons_member'][0]); + } $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]; + $coupon->glm_coupons_url = preg_replace('/http:\/\//i', '', $coupon->glm_coupons_url); + $coupon->glm_coupons_member = ($member_data['member_name']) ? $member_data['member_name'] : ''; + $coupon->glm_coupons_address = ($member_data['address']) ? $member_data['address'] : ''; $coupon->glm_coupons_thumb = get_the_post_thumbnail($coupon->ID, 'thumbnail', array('class' => 'aligncenter')); $post_categories = wp_get_object_terms( $coupon->ID, @@ -132,4 +137,42 @@ class glm_coupon_front return; } + private function _getMemberData($id) + { + global $wpdb; + $data = array(); + if (!filter_var($id, FILTER_VALIDATE_INT)) { + return false; + } + if ( !defined( 'GLM_MEMBERS_PLUGIN_DB_PREFIX' ) ) { + return false; + } else { + $sql = " + SELECT m.member_name, addr1,c.name as city,state,zip + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info m + LEFT OUTER JOIN " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities c ON (c.id = m.city) + WHERE m.id = {$id}"; + $results = $wpdb->get_results($sql, ARRAY_A); + if ($results[0]) { + $address = array(); + if ($results[0]['addr1']) { + $address[] = $results[0]['addr1']; + } + if ($results[0]['city']) { + $address[] = $results[0]['city']; + } + if ($results[0]['state']) { + $address[] = $results[0]['state']; + } + if ($results[0]['zip']) { + $address[] = $results[0]['zip']; + } + $data = array( + 'member_name' => $results[0]['member_name'], + 'address' => implode(',', $address) + ); + } + return $data; + } + } } diff --git a/css/front/coupons.css b/css/front/coupons.css index 66746f6..cafc15a 100644 --- a/css/front/coupons.css +++ b/css/front/coupons.css @@ -12,6 +12,9 @@ .coupon-item-wrap { padding: 20px; } +.coupon-item-wrap h3 { + text-align: center; +} .coupon-row h2 { font-size: 1.45rem; } diff --git a/models/coupon.php b/models/coupon.php index e432b50..849b0f7 100644 --- a/models/coupon.php +++ b/models/coupon.php @@ -19,7 +19,6 @@ class glm_coupons_coupon */ public function __construct($path) { -// global $typenow; $this->pluginDirName = $path; add_action('init', array($this, 'addPostTypes')); add_action('init', array($this, 'createCouponTaxonomy')); @@ -38,15 +37,12 @@ class glm_coupons_coupon add_action('restrict_manage_posts', array($this, 'taxonomy_filter_restrict_manage_posts')); add_filter('parse_query', array($this, 'couponFilter')); -// var_dump($typenow); -// add_filter('user_row_actions', array($this, 'remove_row_actions')); } // Filter the request to just give posts for the given taxonomy, if applicable. function taxonomy_filter_restrict_manage_posts() { global $typenow; -// var_dump($typenow); if ($typenow == GLM_COUPON_POST_TYPE) { $filters = get_object_taxonomies(GLM_COUPON_POST_TYPE); @@ -63,10 +59,7 @@ class glm_coupons_coupon 'hide_empty' => true )); } - } - - - + } } function taxonomy_filter_post_type_request($query) @@ -74,11 +67,8 @@ class glm_coupons_coupon global $pagenow, $typenow; if ('edit.php' == $pagenow && $typenow == GLM_COUPON_POST_TYPE) { $filters = get_object_taxonomies(GLM_COUPON_POST_TYPE); -// var_dump($filters); foreach ($filters as $tax_slug) { $var = &$query->query_vars[$tax_slug]; -// var_dump($var); -// var_dump($tax_slug); if (isset($var)) { $term = get_term_by('id', $var, $tax_slug); var_dump($term); @@ -134,11 +124,9 @@ class glm_coupons_coupon if (isset($qv[GLM_COUPON_TAX_CATEGORIES]) && $qv[GLM_COUPON_TAX_CATEGORIES] != 0) { $term = get_term_by('id', $qv[GLM_COUPON_TAX_CATEGORIES], GLM_COUPON_TAX_CATEGORIES); $qv[GLM_COUPON_TAX_CATEGORIES] = $term->slug; - if (isset($query->tax_query)) { $tax_query =& $query->tax_query; $queries =& $tax_query->queries; -// echo '
'.print_r($queries, true).'
'; foreach ($queries as $key => &$qs) { if ($qs['taxonomy'] == GLM_COUPON_TAX_CATEGORIES) { $qs['terms'][$key] = $term->slug; @@ -147,13 +135,8 @@ class glm_coupons_coupon } } - if ($qv['post_type'] == GLM_COUPON_POST_TYPE) { -// echo '
'.print_r($qv, true).'
'; - } -// echo '
'.print_r($query, true).'
'; } - return $query; } } @@ -218,13 +201,41 @@ class glm_coupons_coupon $clean_ed = date('D, M d, Y', $meta_ed); $clean_ex = date('D, M d, Y', $meta_ex); - $glm_coupon_url = (isset($glm_coupon_url)) - ? $glm_coupon_url + $glm_coupons_url = (isset($custom['glm_coupons_url'])) + ? $custom['glm_coupons_url'][0] + : ''; + + // if they have member db plugin get a list of the members + $glm_coupons_member = (isset($custom['glm_coupons_member'])) + ? $custom['glm_coupons_member'][0] : ''; + + $memberList = $this->_getMemberList(); + include $this->pluginDirName . 'views/admin/coupon_meta.php'; } + private function _getMemberList() + { + global $wpdb; + $members = array(); + if ( !defined( 'GLM_MEMBERS_PLUGIN_DB_PREFIX' ) ) { + return false; + } else { + $sql = " + SELECT id,member_name as name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info + WHERE status = 10 + ORDER BY member_name"; + $results = $wpdb->get_results($sql, ARRAY_A); + foreach ($results as $row) { + $members[] = $row; + } + } + return $members; + } + /** * Save the coupon meta data * @@ -268,6 +279,8 @@ class glm_coupons_coupon update_post_meta($post->ID, 'glm_coupons_expdate', $updateexpd); update_post_meta($post->ID, 'glm_coupons_url', $_POST['glm_coupons_url']); + + update_post_meta($post->ID, 'glm_coupons_member', $_POST['glm_coupons_member']); } /** @@ -294,13 +307,12 @@ class glm_coupons_coupon 'menu_name' => 'Coupons' ); $args = array( -// 'label' => __('Coupons'), 'labels' => $labels, 'description' => 'Stores Coupons and Coupon data', 'public' => true, 'can_export' => true, 'menu_position' => 21, - 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author'), + 'supports' => array('title', 'editor', 'thumbnail', 'author'), 'has_archive' => true, 'menu_icon' => 'dashicons-products', 'capability_type' => 'post', diff --git a/views/admin/coupon_meta.php b/views/admin/coupon_meta.php index b8f51f0..998d586 100644 --- a/views/admin/coupon_meta.php +++ b/views/admin/coupon_meta.php @@ -11,6 +11,16 @@ value="" />
diff --git a/views/front/couponList.php b/views/front/couponList.php index 63fbdac..d599397 100644 --- a/views/front/couponList.php +++ b/views/front/couponList.php @@ -20,13 +20,16 @@
+ glm_coupons_member) : ?> +

glm_coupons_member;?>

+

post_title;?>

glm_coupons_thumb) : ?> glm_coupons_thumb;?>
post_content;?>
glm_coupons_url) :?> - +
Expires: glm_coupons_expdate);?>
diff --git a/views/front/couponPrint.php b/views/front/couponPrint.php index 08cbc84..65573bf 100644 --- a/views/front/couponPrint.php +++ b/views/front/couponPrint.php @@ -93,8 +93,8 @@ foreach ($coupons as $coupon) { $pdf->ezSetY($y); $y = $pdf->ezText("\n".$header, 12, $header_options); $y = $pdf->ezText($descr, 10, $options); - if ($memberAddress) { - $y = $pdf->ezText($memberAddress, 9, $header_options); + if ($coupon->glm_coupons_address) { + $y = $pdf->ezText($coupon->glm_coupons_address, 9, $header_options); } if ($phone) { $y = $pdf->ezText($phone, 9, $header_options);