Events+: PHP Classes crash course needed

Right, I have no idea what I'm doing. Not really familiar with classes in php at all.

I need to be able to do the following with the Events+ plugin:

1. Query non-recurring events and then order them by soonest first
2. Query recurring events and only display one instance of them
3. Query and format the start times of events
4. Extract other information such as number of attendees/event capacity etc for use in PHP.

The plugin seems to have its own set of functions and seems to create its own object for this which appears to follow different rules from the usual WP_Query object.

Obviously I don't expect help with all the things I need to do but if someone could point me in the direction of the following, that would be awesome:

1. Somewhere I can find a list of useful functions used by the Events+ plugin, especially for querying different things about the events.
2. A decent crash course in PHP classes that would be relevant to what I need to do.

Many thanks!

  • Jack Kitterhing

    Hi there @Jonathan,

    Hope you're well today and thanks for your question.

    For the recurring they are a bit different and in general we'll need to use the events class for this, in lib/class_eab_collection.php you could use

    Eab_CollectionFactory::get_upcoming_events() to get the upcoming events and then use

    is_recurring to check if the event is recurring.

    This is quite a good overview of classes here http://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762 :slight_smile:

    And I'll include one of our developers @Hoang Ngo to see if he can also provide his valuable input here.

    Thank you!

    Kind Regards
    Jack.

  • Hoang Ngo

    Hi @Jonathan,

    1. Query non-recurring events and then order them by soonest first

    The Events is custom post type, so we can get it just by native wordpress.

    $wp_query = new WP_Query( array(
    		'post_status' => 'publish',
    		'nopaging'    => true,
    		'post_type'   => 'incsub_event',
    		'order'       => 'DESC',
    		'meta_query'  => array(
    			array(
    				'key'     => 'eab_event_recurring',
    				'value'   => '',
    				'compare' => '='
    			)
    		)
    	) );
    	$events=$wp_query->posts;

    2. Query recurring events and only display one instance of them

    Similar to the above, we can do this

    $wp_query = new WP_Query( array(
    		'post_status' => 'publish',
    		'nopaging'    => true,
    		'post_type'   => 'incsub_event',
    		'order'       => 'DESC',
    		'meta_query'  => array(
    			array(
    				'key'     => 'eab_event_recurring',
    				'value'   => '',
    				'compare' => '!='
    			)
    		)
    	) );
    	$events=$wp_query->posts;

    I have check the function
    Eab_CollectionFactory::get_upcoming_events()
    But can't find anyway to inject the param to return single/recurring only :slight_frown:.
    Fortunately, we can get the event model by this
    $event= new Eab_EventModel($post);
    So you can get the details of an event easily.

    3. Query and format the start times of events

    I assume you already have the event model, so for getting the start time, just do something like this
    $start_time = $event->get_start_date()

    Extract other information such as number of attendees/event capacity etc for use in PHP.

    Once again, the event model is our friends:
    $bookings = $event->get_bookings()
    You can check the file
    /wp-content/plugins/events-and-bookings/lib/class_eab_event_model.php
    For more ideal how to get data from an event :slight_smile:

    1. Somewhere I can find a list of useful functions used by the Events+ plugin, especially for querying different things about the events.

    I do apologize for this, but unfortunately, we don't have the detail document for now. But if you have any issue, please don't hesitate to let us know so we can assist :slight_smile:

    Best Regards,
    Hoang