Update the post_type for Coupons
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 21 Aug 2015 13:04:17 +0000 (09:04 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 21 Aug 2015 13:04:17 +0000 (09:04 -0400)
Has fields for
start date, end date, expire date and url.

controllers/admin.php
index.php
models/coupon.php
models/database.php
views/admin/coupon_meta.php [new file with mode: 0644]

index 682d194..b8b4391 100644 (file)
@@ -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;
     }
 
 }
index e653ca2..158efbe 100644 (file)
--- 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
index e82df92..b7b7551 100644 (file)
@@ -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 '<pre>'.print_r($qv, true).'</pre>';
                 }
@@ -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"               => "<input type=\"checkbox\" />",
             "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 . '<br /><em>' . $enddate . '</em>';
+                $expdate   = date("F j, Y", $expd);
+                echo '<div>Start - ' . $startdate . '</div><div>End - ' . $enddate . '</div><div>Expire - ' . $expdate . '</div>';
                 break;
         }
     }
index e69de29..1bdaaad 100644 (file)
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * database.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   Package
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @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 <steve@gaslightmedia.com>
+ * @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 (file)
index 0000000..0392209
--- /dev/null
@@ -0,0 +1,49 @@
+<style>
+    .tf-meta {  }
+    .tf-meta ul li { height: 20px; clear:both; margin: 0 0 15px 0;}
+    .tf-meta ul li label { width: 160px; display:block; float:left; padding-top:4px; text-align: right;padding-right: 20px;}
+    .tf-meta ul li input { width:200px; display:block; float:left; }
+    .tf-meta ul li em { width: 200px; display:block; float:left; color:gray; margin-left:10px; padding-top: 4px}
+</style>
+<input type="hidden"
+       name="glm-coupons-nonce"
+       id="tf-events-nonce"
+       value="<?php echo wp_create_nonce( 'glm-coupons-nonce' );?>" />
+<div class="tf-meta">
+    <ul>
+        <li>
+            <label>Start Date: </label>
+            <input name="glm_coupons_startdate" class="tfdate"
+                   value="<?php echo $clean_sd; ?>" />
+        </li>
+        <li>
+            <label>End Date: </label>
+            <input name="glm_coupons_enddate" class="tfdate"
+                   value="<?php echo $clean_ed; ?>" />
+        </li>
+        <li>
+            <label>Expire Date: </label>
+            <input name="glm_coupons_expdate" class="tfdate"
+                   value="<?php echo $clean_ex; ?>" />
+        </li>
+        <li>
+            <label>Url:</label>
+            <input name="glm_coupon_url"
+                   value="<?php echo $glm_coupon_url; ?>" />
+        </li>
+    </ul>
+</div>
+<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
+<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
+<script>
+    jQuery(document).ready(function (){
+        jQuery(".tfdate").datepicker({
+            dateFormat: 'D, M d, yy',
+            showOn: 'button',
+            buttonImage: 'http://app.gaslightmedia.com/assets/icons/calendar.png',
+            buttonImageOnly: true,
+            numberOfMonths: 1
+
+        });
+    });
+</script>