Skip to content

Commit

Permalink
Improve the filtering of group events when viewing calendars.
Browse files Browse the repository at this point in the history
The previous implementation queried for all events, and then filtered out
individual events not belonging to the group using the `intercept_calendar()`
filter on 'eventorganiser_fullcalendar_event'. This technique is inefficent,
especially as the number of group events increases.

The new technique is to detect the 'bp_group_id' param sent with the AJAX
request, and then add a corresponding 'bp_group' param to the event query, using
the new 'eventorganiser_fullcalendar_query' filter in EO. This mirrors the way
user-specific calendar requests are filtered.

See #2, #5, #8.
  • Loading branch information
boonebgorges committed Mar 27, 2015
1 parent 342dd2d commit 4511c52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 55 deletions.
55 changes: 0 additions & 55 deletions bp-event-organiser-eo.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ public function register_hooks() {
// intercept after break occurrence, because a new post is created
//add_action( 'eventorganiser_occurrence_broken', array( $this, 'occurrence_broken' ), 10, 3 );

// intercept calendar display
add_filter( 'eventorganiser_fullcalendar_event', array( $this, 'intercept_calendar' ), 10, 3 );

// intercept post content - try to catch calendar shortcodes
add_filter( 'the_content', array( $this, 'intercept_content' ), 10, 1 );

Expand Down Expand Up @@ -418,58 +415,6 @@ public function get_group_ids() {

//##########################################################################



/**
* @description: intercept display of group calendar
* @param object $post the WP post object
* @param int $post_id the numeric ID of the WP post
* @param int $occurrence_id the numeric ID of the EO occurrence
* @return nothing
*/
public function intercept_calendar( $post, $post_id, $occurrence_id ) {

/*
bp_get_current_group_id() reports incorrect IDs for BP Group Hierarchy
sub groups - it only reports the top level group's ID presumably because
BuddyPress is parsing the URL to get the group ID. As a result, we need to
parse $_GET, which has our injected value.
*/

// init
$group_id = 0;

// Get group ID from $_GET for AJAX requests.
if ( isset( $_GET['bp_group_id'] ) && is_numeric( $_GET['bp_group_id'] ) ) {
$group_id = absint( $_GET['bp_group_id'] );
}

// pass if not in group
if ( 0 == $group_id ) return $post;

// get groups for this post
$groups = $this->get_calendar_groups( $post_id );

// do we show this post?
if ( in_array( $group_id, $groups ) ) {
// this is to avoid requerying the event just for the post slug
$event_url = explode( '/', untrailingslashit( $post['url'] ) );
$post_slug = array_pop( $event_url );

// regenerate the post URL to account for group permalink
$post['url'] = trailingslashit( bpeo_get_group_permalink( $group_id ) . $post_slug );

// --<
return $post;
}

// --<
return null;

}



/**
* @description: get all event groups
* @param int $event_id the numeric ID of the WP post
Expand Down
20 changes: 20 additions & 0 deletions includes/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ function bpeo_filter_query_for_bp_group( $query ) {
}
add_action( 'pre_get_posts', 'bpeo_filter_query_for_bp_group' );

/**
* Catch "fullcalendar" AJAX requests and process 'bp_group' information.
*
* @param array $query Query vars as set up by EO.
*/
function bpeo_add_bp_group_id_to_ajax_query( $query ) {
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
return $query;
}

if ( ! isset( $_REQUEST['bp_group_id'] ) ) {
return $query;
}

$query['bp_group'] = intval( $_REQUEST['bp_group_id'] );

return $query;
}
add_filter( 'eventorganiser_fullcalendar_query', 'bpeo_add_bp_group_id_to_ajax_query' );

/**
* Modify EO capabilities for group membership.
*
Expand Down

0 comments on commit 4511c52

Please sign in to comment.