Setup the next 5 events.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 8 Sep 2016 12:52:59 +0000 (08:52 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 8 Sep 2016 12:52:59 +0000 (08:52 -0400)
Order by the status so pending is on top and then sorting by start and
end dates.

models/admin/dashboard/events.php
views/admin/dashboard/events.html

index 37b4591..42b4e22 100644 (file)
@@ -104,35 +104,27 @@ class GlmMembersAdmin_dashboard_events extends GlmDataEvents
         if ( isset( $this->config['loggedInUser']['contactUser']['ref_dest'] )
             && $memberID = filter_var( $this->config['loggedInUser']['contactUser']['ref_dest'], FILTER_VALIDATE_INT)
         ) {
+            // Get the last 5 recent Events.
             $events = $this->wpdb->get_results(
                 $this->wpdb->prepare(
-                    "SELECT id,name,status,approved
-                       FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
-                      WHERE ref_dest = %d
-                        AND id IN (
-                        SELECT event
-                          FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
-                         WHERE active
-                    )",
+                    "SELECT E.id,E.name,E.status,E.approved,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
+                      WHERE E.ref_dest = %d
+                        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 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)
+                     ORDER BY E.status DESC,end DESC,start DESC
+                     LIMIT 5
+                     OFFSET 0",
                     $memberID
                 ),
                 ARRAY_A
             );
+
             foreach ( $events as &$event ) {
                 // set the status
                 $event['status'] = $this->config['status'][$event['status']];
-                // set the start and end times
-                $event_times = $this->wpdb->get_results(
-                    $this->wpdb->prepare(
-                        "SELECT MIN(start_time) as start, MAX(end_time) as end
-                           FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
-                          WHERE event = %d",
-                        $event['id']
-                    ),
-                    ARRAY_A
-                );
-                $event['start'] = strtotime( $event_times[0]['start'] );
-                $event['end']   = strtotime( $event_times[0]['end'] );
             }
         }
 
index 14f0934..9a2afe1 100644 (file)
@@ -1,7 +1,7 @@
 <div class="glm-widget-container">
     <div class="glm-widget">
         <h2>
-            <span>Events</span>
+            <span>Events (5 most recent)</span>
         </h2>
         <div class="glm-widget-content">
             <a class="glm-right" href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=events&option=add&member={$memberID}">