* @access public
* @return array events
*/
- public function getModelEventsData( $categoryId = null, $limit = null, $memberId = null )
+ public function getModelEventsData( $categoryId = null, $limit = null, $memberId = null, $amenityId = null )
{
$this->postAddTimes = true;
$where .= "T.ref_type = ".$this->config['ref_type_numb']['Member']." and T.ref_dest = $memberId AND ";
}
+ if ( $amenityId = filter_var( $amenityId, FILTER_VALIDATE_INT ) ) {
+ $where = "
+ T.id IN (
+ SELECT event
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "amenity_event
+ WHERE amenity = {$amenityId}
+ AND event IN (
+ SELECT event
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
+ WHERE status = " . $this->config['status_numb']['Active'] . "
+ AND " . $this->dateRange . "
+ )
+ )";
+ }
+
// If a category ID is supplied
- if ($catId = filter_var( $categoryId, FILTER_VALIDATE_INT )) {
- $events = $this->getEventsByCategory( $catId, $limit );
+ if ( $catId = filter_var( $categoryId, FILTER_VALIDATE_INT ) ) {
+ //$events = $this->getEventsByCategory( $catId, $limit );
+ $where = "
+ T.id IN (
+ SELECT event
+ FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+ WHERE category = {$catId}
+ AND event IN (
+ SELECT event
+ FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
+ WHERE status = " . $this->config['status_numb']['Active'] . "
+ AND " . $this->dateRange . "
+ )
+ )
+ ";
+ $order = "T.id";
+ if ( $limit = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
+ $order .= " LIMIT {$limit} OFFSET 0";
+ }
// Else if a event name is supplied
- } else if ($term = filter_var( $categoryId, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES )) {
+ } else if ( $term = filter_var( $categoryId, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) ) {
$searchTerm = $this->wpdb->esc_like( stripslashes( $term ) );
$where .= "T.name like '%" . $term . "%'
AND T.status = " . $this->config['status_numb']['Active'] . "
";
$order = "T.id";
$order .= " LIMIT 2 OFFSET 0";
- $events = $this->getList( $where, $order );
} else if ( $limit = filter_var( $limit, FILTER_VALIDATE_INT ) ) {
// Need to get the event id's for the next $limit number of events.
$where .= "T.id
)
";
$order = "T.id";
- $events = $this->getList( $where, $order );
// Otherwise get all categories
} else {
$where .= "T.status = " . $this->config['status_numb']['Active'] . "
AND " . $this->dateRange . "
)
";
- $events = $this->getList( $where );
}
+ $events = $this->getList( $where, $order );
+
if ( !empty( $events ) ) {
foreach ( $events as &$event ) {
// grab the first from times and see if it's ongoing or not
if ( isset( $actionData['request']['member'] ) ) {
$memberId = $actionData['request']['member'] - 0;
}
- if ($memberId == 0) {
+ if ( $memberId == 0 ) {
$memberId = null;
}
if ( isset( $actionData['request']['limit'] ) ) {
WHERE DATE(start_time) >= '{$from}')";
}
- if (isset($_REQUEST['event_name'])
+ if ( isset( $_REQUEST['event_name'] )
&& $eventNameSearch = filter_var($_REQUEST['event_name'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) {
$search = true;
$action = 'event-list-name';
$events = $this->getModelEventsData( $categoryId, $limit );
break;
case 'event-list-name':
- $events = $this->getModelEventsData( $eventNameSearch );
+ $events = $this->getModelEventsData( $eventNameSearch, null, $memberId, $amenityId );
if ( !$view ) {
$view = 'agenda.html';
}
break;
case 'event-list':
$this->postAddRecurrences = true;
- $events = $this->getModelEventsData( $categoryId, null, $memberId );
+ $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId );
if ( !$view ) {
$view = 'agenda.html';
}
include_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/SetaPDF/Autoload.php';
$this->postAddLocations = true;
$this->postAddRecurrences = true;
- $events = $this->getModelEventsData( $categoryId );
+ $events = $this->getModelEventsData( $categoryId, null, $memberId, $amenityId );
$this->postAddLocations = false;
$this->postAddRecurrences = false;