bumping version number to 1.6.19, fixing front page event widget to
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 6 Mar 2017 16:01:53 +0000 (11:01 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 6 Mar 2017 16:01:53 +0000 (11:01 -0500)
update the header dates after changing months, replaced the date line
with the time of the event.

index.php
models/admin/ajax/eventsCalMonthAJAX.php
views/front/events/sidebarEvents.html

index 5a70df9..4d17e00 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Members Database Events
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Members Database.
- * Version: 1.6.18
+ * Version: 1.6.19
  * Author: Chuck Scott
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -20,7 +20,7 @@
  * @package glmMembersDatabaseEventsAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.6.18
+ * @version 1.6.19
  */
 
 /*
@@ -38,7 +38,7 @@
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
  */
-define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.18');
+define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.6.19');
 define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.1.1');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index 21f1d4a..17561de 100644 (file)
@@ -81,12 +81,6 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes
      * from within a given date range. Left out of the where statement because it is
      * already performed by $this->dateRange
      */
-    //                AND ET.id IN (
-    //                    SELECT event
-    //                    FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS DTR
-    //                    WHERE active
-    //                    AND " . $this->dateRange . "
-    //                )
     public function getModelTimesData(  )
     {
         $this->postAddTimes = true;
@@ -132,147 +126,116 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes
         $event_data = [];
 
         // this section is for a sidebar events widget, typically on a front page
-        if( isset( $_REQUEST['date_string'] ) || isset($_REQUEST['all_events'] ) ){
+        if( isset( $_REQUEST['date_string'] ) ){
             $image_url = GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/small/';
+        
+            $date = date_parse($_REQUEST['date_string']);
+            $month = $date['month'];
+            $year  = $date['year'];
 
-            if(isset($_REQUEST['date_string'])){
-                $date = date_parse($_REQUEST['date_string']);
-                $month = $date['month'];
-                $year  = $date['year'];
+            $from     = date('Y-m-01', strtotime($year.'-'.$month."-01"));
+            $to   = date('Y-m-t', strtotime($year.'-'.$month."-01"));
 
+            $this->dateRangeTimes = "start_time BETWEEN CAST('{$from}' AS DATE) AND CAST('{$to}' as DATE) AND end_time >= CURDATE() ORDER BY start_time LIMIT 3";
 
-                $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."events WHERE status = 10 AND id IN (SELECT event FROM ";
-                $sql .= GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE YEAR(start_time) = $year AND MONTH(start_time) = $month AND active = 1 AND end_time >= CURDATE() ORDER BY start_time)  LIMIT 3; ";
-                $events = $wpdb->get_results($sql);
-
-
-            } else if(isset($_REQUEST['all_events'])){
-
-//                $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX ."events WHERE status = 10 AND id IN (SELECT event FROM ";
-//                $sql .= GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times ORDER BY start_time) LIMIT 3";
-                $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE end_time >= CURDATE() GROUP BY event ORDER BY start_time LIMIT 3;";
-//                $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times ORDER BY start_time LIMIT 3;";
-                $events_times = $wpdb->get_results($sql);
-
-                foreach($events_times as $times){
-                    $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $times->event.";";
-                    $event[] = $wpdb->get_results($sql);
-                }
-                foreach($event as $ev){
-                    foreach($ev as $e){
-                        $events[] = $e;
-                    }
-
-                }
-            }
+            $events = $this->getModelTimesData();
+    
+            $datesArray = array();
             foreach($events as $event){
-                $sql = "SELECT start_time, end_time, event FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE event = " . $event->id;
+//            
+                $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $event['event'];
 
-                if($event->image !== ''){
-                    $image = $image_url . $event->image;
+                $event_recur = $wpdb->get_results($sql);
+        
+                if($event_recur[0]->image !== ''){
+                    $image = $image_url . $event_recur[0]->image;
                 } else {
                     $image = "none";
                 }
 
-                $date = $wpdb->get_results($sql);
-//                $dates[] = $date;
-                if(count($date) > 1){
-                    $end_date = date('M d', strtotime(end($date)->end_time));
-                } else {
-                    $end_date = '';
-                }
-
-                $start_date = date('M d', strtotime($date[0]->start_time));
+                $time_of_day = date('g:i A', strtotime($event['start_time']['datetime']));
+                $start_date = date('M d', strtotime($event['start_time']['datetime']));
                 $start_timestamp = strtotime($start_date);
                 $end_timestamp = strtotime($end_date);
 
                 if($start_timestamp < $end_timestamp){
                     $start_date = $start_date . " - " . $end_date;
                 }
-                $sidebar_events[$event->id] =
-                    array(
+                
+                if(count($event['start_time']['datetime']) > 1){
+                    $end_date = date('M d', strtotime(end($event['end_time']['datetime'])->end_time));
+                } else {
+                    $end_date = '';
+                }
+                
+                $event_data[] = array(
                         "start_date" => $start_date,
                         "end_date"   => $end_date,
-                        "name"       => $event->name,
-                        "content"    => $event->intro,
+                        "name"       => $event_recur[0]->name,
+                        "content"    => $event_recur[0]->intro,
                         'image'      => $image,
                         'id'         => $event->id,
+                        'time'       => $time_of_day,
                         'timestamp'  => $start_timestamp,
                         'slug'       => $event->name_slug,
-                        'url'        => GLM_MEMBERS_EVENTS_SITE_BASE_URL . 'event-detail/' . $event->name_slug
+                        'url'        => GLM_MEMBERS_EVENTS_SITE_BASE_URL . 'event-detail/' . $event_recur[0]->name_slug
                     );
-//               $events_date[$start_date] = array();
-//               $arrayDates[date('F d D', strtotime($start_date))]  = array();
-                $arrayDates[$start_timestamp]  = array();
+                
+                $datesArray[$event['start_time']['timestamp']][] = $event_data;
             }
 
-            function sortFunction( $event1, $event2 ) {
-                return strtotime($event1['start_date']) - strtotime($event2["start_date"]);
-            }
-            usort($sidebar_events, "sortFunction");
+   // end section for front page events widget data
+        } else if( isset($_REQUEST['month']) ){
 
-            foreach($arrayDates as $key=>$date){
-                foreach($sidebar_events as $event){
-                    if($event['timestamp'] === $key){
-                        array_push($arrayDates[$key], $event);
-                    }
-                }
-            }
 
-            ksort($arrayDates);
-        }
-        // end section for front page events widget data
+            $month = filter_var_array(
+                $_REQUEST['month'],
+                array(
+                    'start' => FILTER_SANITIZE_STRING,
+                    'last'  => FILTER_SANITIZE_STRING
+                )
+            );
+            $start = preg_replace( '%\(.*\)%', '', $month['start'] );
+            $last  = preg_replace( '%\(.*\)%', '', $month['last'] );
 
-        $month = filter_var_array(
-            $_REQUEST['month'],
-            array(
-                'start' => FILTER_SANITIZE_STRING,
-                'last'  => FILTER_SANITIZE_STRING
-            )
-        );
-        $start = preg_replace( '%\(.*\)%', '', $month['start'] );
-        $last  = preg_replace( '%\(.*\)%', '', $month['last'] );
+            $from = date('Y-m-d', strtotime($start));
+            $to   = date('Y-m-d', strtotime($last));
 
-        $from = date('Y-m-d', strtotime($start));
-        $to   = date('Y-m-d', strtotime($last));
+            $this->dateRangeTimes = "start_time BETWEEN CAST('{$from}' AS DATE) AND CAST('{$to}' as DATE)";
+            $this->dateRange = "id IN (
+                SELECT id
+                  FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+                  WHERE DATE(start_time) BETWEEN '{$from}' AND '{$to}'
 
-        $this->dateRangeTimes = "start_time BETWEEN CAST('{$from}' AS DATE) AND CAST('{$to}' as DATE)";
-        $this->dateRange = "id IN (
-            SELECT id
-              FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
-              WHERE DATE(start_time) BETWEEN '{$from}' AND '{$to}'
+            )";
 
-        )";
+            $times = $this->getModelTimesData();
 
-        $times = $this->getModelTimesData();
-//        var_dump($events);
+            foreach ($times as $e=>$val){
+                $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $val['event'];
+                $info[$e] = $wpdb->get_results($sql);
+                $event_slugs[$e] = $info[$e][0]->name_slug;
+                $event_data[$e]['title'] = html_entity_decode($val['event_name']);
 
-        foreach ($times as $e=>$val){
-            $sql = "SELECT * FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events WHERE id = " . $val['event'];
-            $info[$e] = $wpdb->get_results($sql);
-            $event_slugs[$e] = $info[$e][0]->name_slug;
-            $event_data[$e]['title'] = html_entity_decode($val['event_name']);
+                $start = date('Y-m-d H:i:s', strtotime($val['start_time']['datetime']));
+                $last = date('Y-m-d H:i:s', strtotime($val['end_time']['datetime']));
 
-            $start = date('Y-m-d H:i:s', strtotime($val['start_time']['datetime']));
-            $last = date('Y-m-d H:i:s', strtotime($val['end_time']['datetime']));
+                $all_day = $val['all_day']['value'];
 
-            $all_day = $val['all_day']['value'];
-
-            $event_data[$e]['all_day'] = ($all_day === "0" ? false : true);
-            $event_data[$e]['start'] = ($start);
-            $event_data[$e]['last'] = ($last);
-            $event_data[$e]['slug'] = $event_slugs[$e];
-            $slug = $event_slugs[$e];
-//            $slug = sanitize_title( $val['event_name'] );
-            $event_data[$e]['url'] = GLM_MEMBERS_EVENTS_SITE_BASE_URL . "event-detail/" . $slug . "/";
+                $event_data[$e]['all_day'] = ($all_day === "0" ? false : true);
+                $event_data[$e]['start'] = ($start);
+                $event_data[$e]['last'] = ($last);
+                $event_data[$e]['slug'] = $event_slugs[$e];
+                $slug = $event_slugs[$e];
+                $event_data[$e]['url'] = GLM_MEMBERS_EVENTS_SITE_BASE_URL . "event-detail/" . $slug . "/";
+            }
         }
 
         $return = array(
 //            'status' => false,       // Assume nothing works
             'events'          => $event_data  ,    // Where our events list will go
-            'message'         => $info,
-            'sidebar_events'  => $sidebar_events,
-            'array_dates'     => $arrayDates,
+            'message'         => $datesArray,
+            'array_dates'     => $datesArray,
 //            'event'           => $dates
         );
 
@@ -280,4 +243,4 @@ class GlmMembersAdmin_ajax_eventsCalMonthAJAX extends GlmDataEventsTimes
         echo json_encode($return);
         wp_die();
     }
-}
+}
\ No newline at end of file
index 4c06396..6b8ca6d 100644 (file)
@@ -1,4 +1,3 @@
-
     <h1>Upcoming Events </h1>
     <div id="sidebar-date-select" class="sidebar-datepicker"></div>
     <div class="sidebar-events">
                     $('.date-overlay').hide();
                 },
                 success: function(data){
-                
-                      if(data.array_dates !== null){
+                      if( !$.isEmptyObject(data.array_dates) ){
                         var num = 0;
+                        var count = 0;
                         $.each(data.array_dates, function(index, value){
-          
+                           
                             var date = new Date(index * 1000);
-                            date.setDate(date.getDate() + 1);
-                            
-                            var month = date.toString('MMMM')
+                            date.setDate(date.getDate());
+                          
+                            var month = date.toString('MMMM');
                             var day = date.toString('dd');
                             var weekday = date.toString('dddd');
 
                             var container = $('<div id="group-' + num + '"></div>');
 
                             $.each(value, function(i, v){
-                                if(v.image !== 'none'){
-                                    var image = "<a href='" + v.url + "'><div style='background-image: url("+ v.image +");' class='sidebar-event-image'> </div></a>";
+    
+                                if(v[count].image !== 'none'){
+                                    var image = "<a href='" + v[count].url + "'><div style='background-image: url("+ v[count].image +");' class='sidebar-event-image'> </div></a>";
                                 } else {
                                     image = "<div class='no-image'></div>";
                                 }
                                 
-                                var event = $("<div id='" + v.id + "' class='sidebar-event group-" + num + "'>" + image + "<div class='sidebar-event-info-container'> <div class='sidebar-event-name'><a class='sidebar-url' href='"+v.url + "'>" + v.name  + "</a></div> <div class='sidebar-event-date'>" + v.start_date +  "</div> <div class='sidebar-event-desc'>" + v.content + "</div></div></div>");
+                                var event = $("<div id='" + v[count].id + "' class='sidebar-event group-" + num + "'>" + image + "<div class='sidebar-event-info-container'> <div class='sidebar-event-name'><a class='sidebar-url' href='"+v[count].url + "'>" + v[count].name  + "</a></div> <div class='sidebar-event-date'>" + v[count].time +  "</div> <div class='sidebar-event-desc'>" + v[count].content + "</div></div></div>");
                                  container.append(event);
+                                 count++;
                             });
                             
                             $(container).prepend(header);
@@ -91,7 +92,7 @@
         var dat = {
                 action: 'glm_members_admin_ajax',
                 glm_action: 'eventsCalMonthAJAX',
-                all_events: 'true'
+                date_string: date_string
         };
         ajaxEvents(dat);