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'] );
}
}