Events for today are now retrieved if one of their TIME records starts and ends on...
authorLaury GvR <laury@gaslightmedia.com>
Thu, 25 Jul 2019 21:37:29 +0000 (17:37 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Thu, 25 Jul 2019 21:37:29 +0000 (17:37 -0400)
setup/routes/dashboard.php

index 5f39c07..e563cc2 100644 (file)
@@ -97,14 +97,18 @@ class GLMA_Dashboard_Rest_Controller
                         //}
 
 
-                        
-                        if ( defined("GLM_MEMBERS_PLUGIN_PATH") ) {
-                            $members = $this->get_members_summary();
-                            //$summary['members'] = $members;
+                        if ( defined("GLM_MEMBERS_EVENTS_PLUGIN_PATH") ) {
+
+                            $config = array();
+                            
+                            $events_summary = $this->get_events_summary( $config );
+                            $summary['events'] = $events_summary;
+
+                            $config['today'] = true;
+                            //$events_today = $this->get_events_summary( $config );
+                            //$summary['events_today'] = $events_today;
                         }
                         if ( defined("GLM_MEMBERS_EVENTS_PLUGIN_PATH") ) {
-                            $events = $this->get_events_summary();
-                            $summary['events'] = $events;
                         }
                         if ( defined("GLM_MEMBERS_COUPONS_PLUGIN_PATH") ) {
                             $summary['coupons'] = $this->get_coupons_summary();
@@ -113,6 +117,11 @@ class GLMA_Dashboard_Rest_Controller
                             $summary['packaging'] =  $this->get_packages_summary();
                         }
 
+                        if ( defined("GLM_MEMBERS_PLUGIN_PATH") ) {
+                            //$members = $this->get_members_summary();
+                            //$summary['members'] = $members;
+                        }
+
                         return rest_ensure_response( get_object_vars ( (object) $summary ) );
                     },
                 )
@@ -353,81 +362,31 @@ class GLMA_Dashboard_Rest_Controller
     }
 
     // Get events
-    public function get_events_summary() {
-        // !!!
-        // WE'LL NEED TO GET EVENT RECURRENCES AS WELL (for start/end date)
-        // !!!
-
-        
-        // $recurrence_fields = "R.id, R.name, R.event, R.start_date, R.start_time, R.end_time, R.from_date, R.to_date";
-        // $recurrence_table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."recurrences AS R, $event_table AS E";
-        // $recurrence_where = "R.event = E.id";
-
-        // $recurrence_fields = "R.id, R.name, R.event, R.start_date, R.start_time, R.end_time, R.from_date, R.to_date";
-        // $recurrence_table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."recurrences AS R";
-        // $recurrence_where = "true";//"R.event = 1";
-        // $recurrence_subquery = "SELECT $recurrence_fields FROM $recurrence_table WHERE $recurrence_where";
-
-        // $event_fields = "id, name, name_slug, descr, image, ($recurrence_subquery) AS recurrences";
-        // $event_table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."events";
-        // $event_where = "status IN (".$this->config['status_numb']['Active'].")";
-
-        
-
-
-        // $event_sql = "
-        //     SELECT $event_fields
-        //     FROM $event_table AS E
-        //     WHERE $event_where;
-        // ";
-
-        // $event_sql = "
-        //     SELECT E.id, E.name, E.name_slug, R.start_date, R.start_time, R.end_time, R.from_date, R.to_date, R.id as recurrence_id
-        //     FROM $event_table AS E
-        //     INNER JOIN $recurrence_table AS R ON (E.id = R.event)
-        //     WHERE $event_where;
-        // ";
+    public function get_events_summary( $config ) {
 
         $limit = 5;
+        $event_fields = "E.id, E.name, E.name_slug, E.descr, E.image";
+        $events_table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events";
+        $times_table = GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times";
+
         $events = $this->wpdb->get_results(
-            $this->wpdb->prepare(
-                "SELECT E.*,T1.start_time as start,T2.end_time as end
-                   FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events E,
-                        " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times T1,
-                        " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times T2
+                "SELECT $event_fields,T.start_time as start,T.end_time as end
+                   FROM $events_table E,
+                        $times_table T
                   WHERE E.status = 10
-                    AND T1.event = E.id AND T1.start_time IN (SELECT MIN(start_time) FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE event = E.id AND end_time <= %s)
-                    AND T2.event = E.id AND T2.end_time IN (SELECT MAX(end_time) FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times WHERE event = E.id AND end_time >= %s)
+                    AND T.event = E.id AND T.start_time IN (SELECT start_time FROM $times_table WHERE event = E.id AND DATE_FORMAT(end_time, '%m-%d-%Y') = DATE_FORMAT(CURDATE(), '%m-%d-%Y') )
+                    AND T.event = E.id AND T.end_time IN (SELECT end_time FROM $times_table WHERE event = E.id AND DATE_FORMAT(end_time, '%m-%d-%Y') = DATE_FORMAT(CURDATE(), '%m-%d-%Y') )
                  ORDER BY start, end
-                 LIMIT %d
-                 OFFSET 0",
-                date( 'Y-m-d' ),
-                date( 'Y-m-d' ),
-                $limit
-            ),
-            ARRAY_A
+                 LIMIT $limit
+                 OFFSET 0"
         );
-          
-        // $event_sql = $recurrence_subquery;
-        // $events = $this->wpdb->get_results( $event_sql );
-
-
-        //$recurrence_sql = "
-        //    SELECT $recurrence_fields
-        //    FROM $recurrence_table
-        //    WHERE $recurrence_where
-        //";
-
-        
-
-        //$recurrences = $this->wpdb->get_results( $recurrence_sql );
-
-        //$events[0]->recurrences = $recurrences;
 
+        if (!$events) {
+            $events = "Empty";
+        }
         return $events;
     }
 
-
     // Get coupons
     public function get_coupons_summary() {
         $fields = "id, name, name_slug, descr, image, start_date, end_date, expire";