WIP Front end work
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 25 Aug 2015 18:06:31 +0000 (14:06 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 25 Aug 2015 18:06:31 +0000 (14:06 -0400)
Group the coupons by category
adding style to them

controllers/front.php
css/front/coupons.css
models/coupon.php
views/admin/coupon_meta.php
views/front/couponList.php

index 66ac6ed..0fc7df5 100644 (file)
@@ -20,6 +20,7 @@ class glm_coupon_front
         add_shortcode('glmcoupons', array($this, 'glm_coupon_shortcode'));
         $this->viewDir = $this->pluginDirName . self::FORM_VIEW_DIR;
         $this->frontViewDir = $this->viewDir . '/front';
+        add_action('wp_enqueue_scripts', array($this, 'load_stylesheet'));
     }
 
     public function glm_coupon_shortcode($atts)
@@ -45,6 +46,17 @@ class glm_coupon_front
         // use smarty template to output the form
     }
 
+    public function load_stylesheet()
+    {
+        wp_enqueue_style(
+            'glm-coupons',
+            plugins_url('glm-coupons/css/front/coupons.css' , $this->pluginDirName),
+            array(),
+            '0.0.1',
+            'all'
+        );
+    }
+
     public function list_coupons()
     {
         global $wpdb, $wp;
@@ -81,9 +93,10 @@ class glm_coupon_front
                 );
             }
         }
+        $categories   = array();
         $coupons      = get_posts($args);
-        $totalCoupons = count($coupons);
-        $iterator     = 1;
+        //$totalCoupons = count($coupons);
+        //$iterator     = 1;
         foreach ($coupons as $coupon) {
             $custom = get_post_custom($coupon->ID);
             $coupon->end                   = false;
@@ -91,10 +104,23 @@ class glm_coupon_front
             $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;
+            $coupon->glm_coupons_thumb     = get_the_post_thumbnail($coupon->ID, 'thumbnail', array('class' => 'aligncenter'));
+            $post_categories               = wp_get_object_terms(
+                $coupon->ID,
+                GLM_COUPON_TAX_CATEGORIES,
+                array('fields' => 'names')
+            );
+            //var_dump($post_categories);
+            foreach ($post_categories as $category) {
+                //$cat = get_category($c);
+                $coupon->categoryName = $category;
+                $categories[$category][] = $coupon;
             }
-            ++$iterator;
+
+            //if ($iterator == $totalCoupons) {
+                //$coupon->end = true;
+            //}
+            //++$iterator;
         }
         include $this->frontViewDir . '/couponList.php';
         return;
index e69de29..347c645 100644 (file)
@@ -0,0 +1,50 @@
+.coupon-row {
+    display: block;
+    width: 100%;
+}
+.coupon-item {
+    display: inline-table;
+    width: 30%;
+    padding: 0;
+    margin: 5px;
+    border: 1px dashed lightgrey;
+}
+.coupon-item-wrap {
+    padding: 20px;
+}
+.coupon-row h2 {
+    font-size: 1.45rem;
+}
+.coupon-row h3 {
+    font-size: 1.3rem;
+}
+.coupon-expires {
+    margin: 20px 5px 5px 0;
+    float: right;
+    font-size: .8rem;
+}
+.coupon-descr {
+    font-size: .9rem;
+}
+.coupon-url {
+    float: left;
+    font-size: .8rem;
+    margin: 20px 0 5px 5px;
+}
+.coupon-select {
+    background-color: lightgrey;
+    width: 100%;
+    height: 40px;
+    padding: 10px;
+}
+
+@media screen and (max-width: 40em) {
+    .coupon-item {
+        width: 100%;
+    }
+}
+@media screen and (min-width: 40.63em) and (max-width: 64em) {
+    .coupon-item {
+        width: 45%;
+    }
+}
index b247167..e432b50 100644 (file)
@@ -300,7 +300,7 @@ class glm_coupons_coupon
             'public'          => true,
             'can_export'      => true,
             'menu_position'   => 21,
-            'supports'        => array('title', 'editor'),
+            'supports'        => array('title', 'editor', 'excerpt', 'thumbnail', 'author'),
             'has_archive'     => true,
             'menu_icon'       => 'dashicons-products',
             'capability_type' => 'post',
index 0392209..b8f51f0 100644 (file)
@@ -28,8 +28,8 @@
         </li>
         <li>
             <label>Url:</label>
-            <input name="glm_coupon_url"
-                   value="<?php echo $glm_coupon_url; ?>" />
+            <input name="glm_coupons_url"
+                   value="<?php echo $glm_coupons_url[0]; ?>" />
         </li>
     </ul>
 </div>
index 47960b8..f4247cc 100644 (file)
@@ -1,12 +1,24 @@
 <div>
     <h1>List Coupons</h1>
+    <?php if ($categories) : foreach ($categories as $catName => $coupons) :?>
+    <h2><?php echo $catName;?></h2>
     <div class="coupon-row">
         <?php if ($coupons): foreach($coupons as $coupon) :?>
-        <div class="<?php if ($coupon->end){ echo ' end';}?> coupon-item">
-            <h2><?php echo $coupon->post_title;?></h2>
-            <div><?php echo $coupon->post_content;?></div>
-            <div><b>Expires:</b> <?php echo date('F d,Y', $coupon->glm_coupons_expdate);?></div>
+            <div class="<?php if ($coupon->end){ echo ' end';}?> coupon-item">
+                <div class="coupon-select"><label><input type="checkbox" name="coupon-id-<?php echo $coupon->ID;?>"> Select this coupon</label></div>
+                <div class="coupon-item-wrap">
+                    <h3><?php echo $coupon->post_title;?></h3>
+                    <?php if ($coupon->glm_coupons_thumb) : ?>
+                    <?php echo $coupon->glm_coupons_thumb;?>
+                    <?php endif;?>
+                    <div class="coupon-descr"><?php echo $coupon->post_content;?></div>
+                    <?php if ($coupon->glm_coupons_url) :?>
+                    <div class="coupon-url"><a href="<?php echo date('F d,Y', $coupon->glm_coupons_url);?>">Web Site</a></div>
+                    <?php endif;?>
+                    <div class="coupon-expires"><b>Expires:</b> <?php echo date('m/d/Y', $coupon->glm_coupons_expdate);?></div>
+                </div>
+            </div>
+            <?php endforeach; endif;?>
         </div>
         <?php endforeach; endif;?>
-    </div>
 </div>