Support

Home Forums Event Espresso Premium Handling Filters on the event list admin page

Handling Filters on the event list admin page

Posted: October 30, 2018 at 9:11 am

Viewing 9 reply threads


ARAGATO

October 30, 2018 at 9:11 am

In regard to this post:
https://eventespresso.com/topic/hook-into-ee4-event-list-view-add-columnsfilters/

I have added a a custom meta field to events…
http://uploads.aragato-server.net/screenshots/20181030229ddd69bb.png

as well as a custum column and filter to show/filter based on the value.
http://uploads.aragato-server.net/screenshots/20181030b1fdd93eec.png

However, I am stuck now and do not know how to acutally apply the filter when click on the “Filter” button. It does not save the selection nor does it filter by the selection.

How did I create the filter: I used the list_table_functions in Extend_Events_Admin_Page.core.php as a foundation and added it via a filter:
add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'acms_list_table_filters'), 10, 2);

Now,I try to actually apply the filter and save the selection. But I do not know how to do it. I found a filter 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data'
but I am not sure if it is the right one and more specifically how to use it correctly. Please help.


Tony

  • Support Staff

October 30, 2018 at 1:22 pm

Hi there,

However, I am stuck now and do not know how to acutally apply the filter when click on the โ€œFilterโ€ button. It does not save the selection nor does it filter by the selection.

This may seem nit-picky, but you don’t save the selection, when you select a filter and click to submit, it POST’s back to the server with your selection and for it to show the current selection you just made, you’ll need to add logic that checks for your post var and displays the current selection.

That’s all separate from the filtering of events based on the selection so I’d start with figuring out how to filter the events based on your selection and work from there.

The filters you mentioned above are incorrect, you’ll need to filter the query used to pull in the events for that section, so you’ll need:

FHEE__Events_Admin_Page__get_events__where

Which is passed the $where params and $req_data containing the current request data.

What you do from there depends on where/how you are storing the data, but as an example if you store the day of the week in post_meta with the key ‘day_of_the_week’ and the value is Monday you’d have something like this:

add_filter('FHEE__Events_Admin_Page__get_events__where', 'tw_Events_Admin_Page_get_events_where', 10, 2);
function tw_Events_Admin_Page_get_events_where($where, $req_data){
    $where['AND'] = array(
        'Post_Meta.meta_key' => 'day_of_the_week',
        'Post_Meta.meta_value' => 'Monday'
    );
    return $where;
}

Although you’ll want to pull the value from $req_data so that it uses the selected value rather than hard-coding it into the filter.

If your not using post meta, you’ll need to post your code to either a Gist os PasteBin so we can view it.


ARAGATO

October 31, 2018 at 6:49 am

Thanks Tony, I will check it out asap.

Meanwhile, in my table content call back, which I added like this:
add_action('AHEE__EE_Admin_List_Table__column_event_day__toplevel_page_espresso_events', array( $this, 'add_event_day_table_content' ), 10, 2);

…I am trying to call _get_first_related, but it returns an error:

    public function add_event_day_table_content($event, $screen)
    {
        if (! $event instanceof EE_Event) {
            return '';
        }

        //Get event day from first event day in this particular event
        $event->_get_first_related('Datetime');

Error:
http://uploads.aragato-server.net/screenshots/201810317e5632144d.png

It says _get_first_related does not exist in EE_Event. However, it should exist since it is derived from EE_Base_Class:: too, isn’t it? What am I missing.

Basically what I am trying to do is to select the first datetime of that event in order to extract that day. What would be the best approach?


Josh

  • Support Staff

October 31, 2018 at 6:59 am

Hi,

It looks like you’ll need to remove the leading underscore e.g.
_get_first_related
should actually be:
get_first_related


ARAGATO

October 31, 2018 at 8:33 am

Well, that worked great. Noob I am. ๐Ÿ˜€

Now I am stuck at another, probably trivial problem.
I would like to retreive all events for a given event category.
I look into the EEM_Event Model, but were unable to find anything related to categories. There is also no helper method in Event class that would help like get_all_events_from_given_category($cat) ๐Ÿ˜‰

Any tips appreciated. Thanks.


ARAGATO

November 1, 2018 at 3:32 am

Ok, found it. It was “hidden” in the taxonomy term. This works.

        //Get all events from given event category
        $events = EEM_Event::instance()->get_all(
        array(
            array(
                'Term_Taxonomy.taxonomy' => 'espresso_event_categories',
                'Term_Taxonomy.Term.slug' => 'badminton'
                )
            )
        );


ARAGATO

November 1, 2018 at 8:34 am

@Toni,I checked your post and I got it working.
It filters the event list. However, I do not get the select box to keep the selected value after the roundtrip.

I have posted the whole class in pastebin: https://pastebin.com/RqEQcsxQ

The problem is, that in the function acms_espresso_event_days_dropdown the value of the current req_data is missing/protected.
I provide the list_table_obj which would have the required data, but I cannot access req_data since it is protected and there is no getter function.

This leads to the problem that I cannot provide the current filter selections to
acms_generate_event_months_dropdown($cur_date, $status, $category, $active_status, $event_day); and therefor the selection cannot be “restored”.

How to get the data to restore the selection values? Or is the way I coded it totally broken and wrong? How to code it more elegantly and the way it works?


ARAGATO

November 1, 2018 at 8:34 am

sorry, I meant @Tony ๐Ÿ˜‰


Tony

  • Support Staff

November 1, 2018 at 2:34 pm

I provide the list_table_obj which would have the required data, but I cannot access req_data since it is protected and there is no getter function.

Pull the current admin page object from the list table, that object has a get_request_data() method.

So something like:

$admin_page = $list_table_obj->get_admin_page();
if( $admin_page instanceof EE_Admin_page ) {
    $req_data = $admin_page->get_request_data();
    //You now have $req_data.
}

Or pull the data directly from $_GET or $_REQUEST if you need to, but the above should work fine.


ARAGATO

November 2, 2018 at 3:12 pm

My man! Great stuff. Works and issue resolved. Thanks a lot.

Viewing 9 reply threads

The support post ‘Handling Filters on the event list admin page’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso