From: Steve Sutton Date: Fri, 21 Aug 2015 13:04:17 +0000 (-0400) Subject: Update the post_type for Coupons X-Git-Tag: v0.0.1^2~6 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c4f6a0f439c84d6fb6e7b29504698c32517795a0;p=WP-Plugins%2Fglm-coupons.git Update the post_type for Coupons Has fields for start date, end date, expire date and url. --- diff --git a/controllers/admin.php b/controllers/admin.php index 682d194..b8b4391 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -16,7 +16,19 @@ class glm_coupon_admin { $this->pluginDirName = $path; $this->wpdb = $wpdb; - $coupons = new glm_coupon_coupon($path); + $coupons = new glm_coupons_coupon($path); + } + + /** + * Sets the Plugin Directory + * + * @param type $dir Directory Name + * + * @return void + */ + public function setPluginDir($dir) + { + $this->pluginDirName = $dir; } } diff --git a/index.php b/index.php index e653ca2..158efbe 100644 --- a/index.php +++ b/index.php @@ -24,6 +24,10 @@ require_once 'controllers/admin.php'; require_once 'controllers/front.php'; require_once 'models/coupon.php'; require_once 'models/database.php'; +/** + * The Database Setup + */ +$glm_coupon_db = new glm_coupons_models_database($GLOBALS['wpdb']); /** * Setup class to call in the Controllers * Based on if in admin or front diff --git a/models/coupon.php b/models/coupon.php index e82df92..b7b7551 100644 --- a/models/coupon.php +++ b/models/coupon.php @@ -5,7 +5,7 @@ * Handles also the new fields in * the metaboxes. */ -class glm_coupon_coupon +class glm_coupons_coupon { public $pluginDirName; @@ -31,7 +31,7 @@ class glm_coupon_coupon add_action('manage_posts_custom_column', array($this, 'couponsCustomColumns')); - add_action('admin_init', array($this, 'metaDates')); + add_action('admin_init', array($this, 'metaData')); add_action('save_post', array($this, 'saveCouponMeta')); add_filter('manage_edit-glm_coupons_sortable_columns', array($this, 'sortingColumns')); @@ -72,7 +72,6 @@ class glm_coupon_coupon function taxonomy_filter_post_type_request($query) { global $pagenow, $typenow; -//var_dump($typenow); if ('edit.php' == $pagenow && $typenow == GLM_COUPON_POST_TYPE) { $filters = get_object_taxonomies(GLM_COUPON_POST_TYPE); // var_dump($filters); @@ -113,7 +112,6 @@ class glm_coupon_coupon { $columns['glmcoupons_col_date'] = 'glmcoupons_col_date'; $columns['glmcoupons_col_cat'] = 'glmcoupons_col_cat'; - $columns['glmcoupons_col_dep'] = 'glmcoupons_col_dep'; return $columns; } @@ -147,10 +145,6 @@ class glm_coupon_coupon } } - if (isset($qv[GLM_COUPON_TAX_DEPARTMENTS]) && $qv[GLM_COUPON_TAX_DEPARTMENTS] != 0) { - $term = get_term_by('id', $qv[GLM_COUPON_TAX_DEPARTMENTS], GLM_COUPON_TAX_DEPARTMENTS); - $qv[GLM_COUPON_TAX_DEPARTMENTS] = $term->slug; - } if ($qv['post_type'] == GLM_COUPON_POST_TYPE) { // echo '
'.print_r($qv, true).'
'; } @@ -186,29 +180,15 @@ class glm_coupon_coupon 'show_count' => true, 'hide_empty' => true )); - $tax2 = get_taxonomy(GLM_COUPON_TAX_DEPARTMENTS); - wp_dropdown_categories(array( - 'show_option_all' => __("Show all {$tax2->label}"), - 'taxonomy' => GLM_COUPON_TAX_DEPARTMENTS, - 'name' => GLM_COUPON_TAX_DEPARTMENTS, - 'orderby' => 'name', - 'selected' => (isset($wp_query->query[GLM_COUPON_TAX_DEPARTMENTS]) - ? $wp_query->query[GLM_COUPON_TAX_DEPARTMENTS] - : ''), - 'hierarchical' => true, - 'depth' => 3, - 'show_count' => true, - 'hide_empty' => true - )); } } /** * Add meta box for dates */ - public function metaDates() + public function metaData() { - add_meta_box('glm_coupon_meta', 'Position Information', + add_meta_box('glm_coupon_meta', 'Coupon Details', array($this, 'editCouponMeta'), GLM_COUPON_POST_TYPE); } @@ -227,31 +207,17 @@ class glm_coupon_coupon : time(); $meta_ed = (isset($custom['glm_coupons_enddate'])) ? $custom['glm_coupons_enddate'][0] - : time(); + : time() + 15778476; + $meta_ex = (isset($custom['glm_coupons_expdate'])) + ? $custom['glm_coupons_expdate'][0] + : time() + 15778476; $clean_sd = date('D, M d, Y', $meta_sd); $clean_ed = date('D, M d, Y', $meta_ed); + $clean_ex = date('D, M d, Y', $meta_ex); - $glm_coupons_status = (isset($glm_coupons_status[0])) - ? $glm_coupons_status[0] - : ''; - $glm_coupons_pay_grade = (isset($glm_coupons_pay_grade[0])) - ? $glm_coupons_pay_grade[0] - : ''; - $glm_coupons_shift = (isset($glm_coupons_shift[0])) - ? $glm_coupons_shift[0] - : ''; - $glm_coupons_contact = (isset($glm_coupons_contact[0])) - ? $glm_coupons_contact[0] - : ''; - $glm_coupons_email = (isset($glm_coupons_email[0])) - ? $glm_coupons_email[0] - : ''; - $glm_coupons_comments = (isset($glm_coupons_comments[0])) - ? $glm_coupons_comments[0] - : ''; - $glm_coupons_code = (isset($glm_coupons_code[0])) - ? $glm_coupons_code[0] + $glm_coupon_url = (isset($glm_coupon_url)) + ? $glm_coupon_url : ''; include $this->pluginDirName . 'views/admin/coupon_meta.php'; @@ -293,16 +259,13 @@ class glm_coupon_coupon $updateendd = strtotime($_POST['glm_coupons_enddate']); update_post_meta($post->ID, 'glm_coupons_enddate', $updateendd); - update_post_meta($post->ID, 'glm_coupons_status', $_POST['glm_coupons_status']); - update_post_meta($post->ID, 'glm_coupons_pay_grade', - $_POST['glm_coupons_pay_grade']); - update_post_meta($post->ID, 'glm_coupons_shift', $_POST['glm_coupons_shift']); - update_post_meta($post->ID, 'glm_coupons_contact', - $_POST['glm_coupons_contact']); - update_post_meta($post->ID, 'glm_coupons_email', $_POST['glm_coupons_email']); - update_post_meta($post->ID, 'glm_coupons_comments', - $_POST['glm_coupons_comments']); - update_post_meta($post->ID, 'glm_coupons_code', $_POST['glm_coupons_code']); + if (!isset($_POST['glm_coupons_expdate'])) { + return $post; + } + $updateexpd = strtotime($_POST['glm_coupons_expdate']); + update_post_meta($post->ID, 'glm_coupons_expdate', $updateexpd); + + update_post_meta($post->ID, 'glm_coupons_url', $_POST['glm_coupons_url']); } /** @@ -341,7 +304,7 @@ class glm_coupon_coupon 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'coupons'), - 'taxonomies' => array(GLM_COUPON_TAX_CATEGORIES, GLM_COUPON_TAX_DEPARTMENTS), + 'taxonomies' => array(GLM_COUPON_TAX_CATEGORIES), 'show_in_menu' => true, 'show_ui' => true, 'query_var' => true, @@ -350,8 +313,6 @@ class glm_coupon_coupon register_post_type(GLM_COUPON_POST_TYPE, $args); register_taxonomy_for_object_type(GLM_COUPON_TAX_CATEGORIES, GLM_COUPON_POST_TYPE); - register_taxonomy_for_object_type(GLM_COUPON_TAX_DEPARTMENTS, - GLM_COUPON_POST_TYPE); } /** @@ -435,36 +396,6 @@ class glm_coupon_coupon 'show_admin_column' => true, '_builtin' => true )); - - $labels = array( - 'name' => _x('Departments', - 'taxonomy general name'), - 'singular_name' => _x('Department', - 'taxonomy singular name'), - 'search_items' => __('Search Departments'), - 'popular_items' => __('Popular Departments'), - 'all_items' => __('All Departments'), - 'parent_item' => null, - 'parent_item_colon' => null, - 'edit_item' => __('Edit Department'), - 'update_item' => __('Update Department'), - 'add_new_item' => __('Add New Department'), - 'new_item_name' => __('New Department Name'), - 'separate_items_with_commas' => __('Separate departments with commas'), - 'add_or_remove_items' => __('Add or remove departments'), - 'choose_from_most_used' => __('Choose from the most used departments'), - ); - - register_taxonomy( - GLM_COUPON_TAX_DEPARTMENTS, GLM_COUPON_POST_TYPE, - array( - 'label' => __('Coupon Department'), - 'labels' => $labels, - 'hierarchical' => true, - 'show_ui' => true, - 'query_var' => GLM_COUPON_TAX_DEPARTMENTS, - 'rewrite' => array('slug' => GLM_COUPON_TAX_DEPARTMENTS), - )); } /** @@ -480,7 +411,6 @@ class glm_coupon_coupon "cb" => "", "title" => "Coupon Title", "glmcoupons_col_cat" => "Category", - "glmcoupons_col_dep" => "Department", "glmcoupons_col_date" => "Dates", ); return $columns; @@ -513,27 +443,15 @@ class glm_coupon_coupon ; } break; - case "glmcoupons_col_dep": - // - show taxonomy terms - - $eventcats = get_the_terms($post->ID, "glm_couponsdepartment"); - $eventcats_html = array(); - if ($eventcats) { - foreach ($eventcats as $eventcat) { - array_push($eventcats_html, $eventcat->name); - } - echo implode($eventcats_html, ", "); - } else { - _e('None', 'themeforce'); - ; - } - break; case "glmcoupons_col_date": // - show dates - $startd = $custom['glm_coupons_startdate'][0]; $endd = $custom['glm_coupons_enddate'][0]; + $expd = $custom['glm_coupons_expdate'][0]; $startdate = date("F j, Y", $startd); $enddate = date("F j, Y", $endd); - echo $startdate . '
' . $enddate . ''; + $expdate = date("F j, Y", $expd); + echo '
Start - ' . $startdate . '
End - ' . $enddate . '
Expire - ' . $expdate . '
'; break; } } diff --git a/models/database.php b/models/database.php index e69de29..1bdaaad 100644 --- a/models/database.php +++ b/models/database.php @@ -0,0 +1,68 @@ + + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @version SVN: (0.1) + * @link <> + */ + +/** + * Toolkit_Package_database + * + * Description of database + * + * @category Toolkit + * @package Package + * @author Steve Sutton + * @copyright 2013 Gaslight Media + * @license Gaslight Media + * @release Release: (0.1) + * @link <> + */ +class glm_coupons_models_database +{ + public $wpdb; + + /** + * Clas constructor for the database + * + * @param type $wpdb Wordpress db object + */ + public function __construct($wpdb) + { + $this->wpdb = $wpdb; + register_activation_hook( + GLM_COUPON_PLUGIN_PATH_FILE, + array($this, 'install') + ); + add_action('plugins_loaded', array($this, 'glm_coupon_update_db_check')); + + } + + /** + * Install the database tables needed for jobs + */ + public function install() + { + update_option(GLM_COUPON_VERSION_OPTION_NAME, GLM_COUPON_VERSION); + } + + /** + * DB Version update check to update the database tables + */ + public function glm_coupon_update_db_check() + { + if (GLM_COUPON_VERSION != get_option(GLM_COUPON_VERSION_OPTION_NAME)) { + $this->install(); + } + } + +} diff --git a/views/admin/coupon_meta.php b/views/admin/coupon_meta.php new file mode 100644 index 0000000..0392209 --- /dev/null +++ b/views/admin/coupon_meta.php @@ -0,0 +1,49 @@ + + +
+
    +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
  • + + +
  • +
+
+ + +