Adding some fields to the events array for templates
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 11 Mar 2016 17:44:16 +0000 (12:44 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 11 Mar 2016 17:44:16 +0000 (12:44 -0500)
Ongoing flag from the event times. - will need more work if the event
has multiple schedules

adding starting_date and ending_date to event array

classes/data/dataEvents.php
classes/data/dataTimes.php
models/front/events/baseAction.php
views/front/events/dashboard.html
views/front/events/detail.html
views/front/events/list.html

index b1b7486..2a2fab3 100644 (file)
@@ -337,19 +337,21 @@ class GlmDataEvents extends GlmDataAbstract
         $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A);
 
         if ($this->postAddTimes) {
-            $sql = "
-            SELECT ET.*
-              FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
-             WHERE ET.start_time >= now()
-               AND ET.active
-               AND ET.event = {$r['id']}
-            ORDER BY ET.start_time";
-            $times = $this->wpdb->get_results($sql, ARRAY_A);
+            include_once  GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataTimes.php';
+            $timeData = new GlmDataEventsTimes( $this->wpdb, $this->config );
+            $where = "
+                T.start_time >= now()
+            AND T.active
+            AND T.event = {$r['id']}
+                ";
+            $order = "T.start_time";
+            $times = $timeData->getList( $where, $order );
             $r['times'] = $times;
             // get the first element of times array
             if ( !empty( $times ) ) {
-                 $r['starting_date'] = $times[0]['start_time'];
-                 $r['ending_date'] = $times[count($times) - 1]['end_time'];
+                 $r['starting_date'] = $times[key($times)]['start_time']['datetime'];
+                 end($times);
+                 $r['ending_date'] = $times[key($times)]['end_time']['datetime'];
             }
         }
 
index d8205a8..5640df8 100644 (file)
@@ -157,6 +157,17 @@ class GlmDataEventsTimes extends GlmDataAbstract
                 'use' => 'glei'
             ),
 
+            // Ongoing
+            'ongoing' => array(
+                'field'    => 'recur_id',
+                'as'       => 'ongoing',
+                'type'     => 'pointer',
+                'p_table'  => GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'recurrences',
+                'p_field'  => 'all_dates',
+                'p_static' => true,
+                'use'      => 'gle'
+            ),
+
             // Active Flag
             'active' => array (
                 'field' => 'active',
index 68b104a..fd985c4 100644 (file)
@@ -51,16 +51,41 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
 
     public function getModelEventsData($categoryId = null, $limit = null)
     {
+        $this->postAddTimes = true;
         if ($categoryId) {
-            return $this->getEventsByCategory( $categoryId, $limit );
+            $events = $this->getEventsByCategory( $categoryId, $limit );
         } else {
-            return $this->getList();
+            $events = $this->getList();
         }
+        foreach ( $events as &$event ) {
+            // grab the first from times and see if it's ongoing or not
+            if ($event['times']) {
+                reset($event['times']);
+                $firstKey = key($event['times']);
+                $event['ongoing'] = $event['times'][$firstKey]['ongoing'];
+                reset($event['times']);
+            }
+            $event['dates'] = $this->getEventDate(
+                strtotime($event['starting_date']),
+                strtotime($event['ending_date']),
+                'timestamp'
+            );
+        }
+        $this->postAddTimes = false;
+        return $events;
     }
 
     public function getModelEventData($eventId)
     {
-        return $this->getEntry($eventId);
+        $this->postAddTimes = true;
+        $event = $this->getEntry($eventId);
+        $event['dates'] = $this->getEventDate(
+            strtotime($event['starting_date']),
+            strtotime($event['ending_date']),
+            'timestamp'
+        );
+        $this->postAddTimes = false;
+        return $event;
     }
 
     /**
@@ -73,4 +98,94 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents
      */
     abstract public function modelAction($actionData = false);
 
+    /**
+     * get_event_date: make the event date human readable
+     *
+     * @param string  $sdate       start date
+     * @param string  $edate       end date
+     * @param string  $dateType    dateType Postgres,etc
+     * @param boolean $microFormat use microformating on output
+     *
+     * @return string
+     * @access public
+     */
+    function getEventDate(
+        $sdate,
+        $edate,
+        $dateType,
+        $microFormat = false
+    ) {
+        switch($dateType) {
+            case "Postgres":
+            $postgresPattern = "/([0-9]{1,2})[/-]([0-9]{1,2})[/-]([0-9]{4})/";
+            if (preg_match($postgresPattern, $sdate, $spt)) {
+                    $mon = $spt[1];
+                    $day = $spt[2];
+                    $yr = $spt[3];
+                }
+
+            if (preg_match($postgresPattern, $edate, $ept)) {
+                    $mon2 = $ept[1];
+                    $day2 = $ept[2];
+                    $yr2 = $ept[3];
+                }
+                break;
+        case "eventstamp":
+            case "timestamp":
+                $mon = date("m",$sdate);
+                $day = date("d",$sdate);
+                $yr = date("Y",$sdate);
+                $mon2 = date("m",$edate);
+                $day2 = date("d",$edate);
+                $yr2 = date("Y",$edate);
+                break;
+        }
+
+        $start = mktime(0,0,0,$mon,$day,$yr);
+        $end = mktime(0,0,0,$mon2,$day2,$yr2);
+        if ($day == $day2 && $mon == $mon2 && $yr == $yr2) {
+            $dateparam = "M j, Y";
+            $dateBegin = date($dateparam, $start) ;
+            $dateEnd   = "";
+        } elseif ($day == $day2 AND $mon == $mon2 AND $yr != $yr2) {
+            $dateparam1 = "M j, Y -";
+            $dateparam2 = "Y";
+            $dateBegin  = date($dateparam1, $start);
+            $dateEnd    = date($dateparam2, $end);
+        } elseif ($day != $day2 AND $mon == $mon2 AND $yr == $yr2) {
+            $dateparam1 = "M j -";
+            $dateparam2 = "j, Y";
+            $dateBegin  = date($dateparam1, $start);
+            $dateEnd    = date($dateparam2, $end);
+        } elseif ($day != $day2 AND $mon == $mon2 AND $yr != $yr2) {
+            $dateparam1 = "M j, Y -";
+            $dateparam2 = "M j, Y";
+            $dateBegin = date($dateparam1, $start);
+            $dateEnd = date($dateparam2, $end);
+        } elseif ($yr == $yr2) {
+            $dateparam1 = "M j -";
+            $dateparam2 = "M j, Y";
+            $dateBegin  = date($dateparam1, $start);
+            $dateEnd    = date($dateparam2, $end);
+        } else {
+            $dateparam1 = "M j, Y -";
+            $dateparam2 = "M j, Y";
+            $dateBegin  = date($dateparam1, $start);
+            $dateEnd    = date($dateparam2, $end);
+        }
+        if ($microFormat) {
+            $dateBegin = '<span class="dtstart">
+                <span class="value" title="'.date('Y-m-d', $start).'">' .
+                $dateBegin . '</span>
+                </span>';
+            $dateEnd
+                = ($dateEnd)
+                ? '<span class="dtend">
+                <span class="value" title="'.date('Y-m-d', $end).'">' .
+                $dateEnd . '</span>
+                </span>'
+                : '';
+        }
+        return $dateBegin." ".$dateEnd;
+    }
 }
index 51ab291..a53bc76 100644 (file)
@@ -20,7 +20,7 @@
                         {break}
                     {/if}
                 <li class="description text-left">
-                    {$event.starting_date|date_format}<br>
+                    {$event.dates}<br>
                     <a href="{$siteBaseUrl}event-detail/{$event.name_slug}/">
                     {$event.name}
                     </a>
index dffdfdd..0245cc7 100644 (file)
@@ -18,7 +18,7 @@
                 </div>
                 <div class="small-7 column">
                     <div class="row">
-                        <div class="small-12 column"><strong>{$event.starting}</strong></div>
+                        <div class="small-12 column"><strong>{$event.dates}</strong></div>
                         <div class="small-12 column">
                             {$event.street}<br>
                             {$event.city}, {$event.state} {$event.zip}
index 1d4eeff..6b21f1a 100644 (file)
@@ -7,11 +7,20 @@
         {foreach $events as $event}
         <div class="small-12 columns">
             <div class="row">
-                <div class="small-6 medium-2 columns">{$event.starting}</div>
-                <div class="small-6 medium-10 columns">
-                    {$categories[$event.category].name}<br>
+                <div class="small-6 medium-3 columns">{$event.dates}</div>
+                <div class="small-6 medium-6 columns">
+                    {foreach $event.categories as $cat}
+                        {$cat.name}:<br>
+                    {/foreach}
                     <a href="{$siteBaseUrl}event-detail/{$event.name_slug}/">{$event.name}</a>
                 </div>
+                <div class="small-6 medium-3 columns">
+                    {if $event.ongoing}
+                    Ongoing Event
+                    {else}
+                    Repeating Event
+                    {/if}
+                </div>
             </div>
             <hr>
         </div>