Events Made Easy Forums How do I … No Double Registration for recurring events

Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #56278
    Anonymous
    Inactive

    Hey everybody,
    I´m searching for a code, which prohibits registration for an single event from a event-series, if the user already registered for an other date of the event series.

    For Example:
    BCourse: 27.04
    BCourse: 28.09
    BCourse: 30.10

    When the user books 27th April, he should not be able to book the other two events of the series.

    Thank you very much for your help!

    #56280
    Franky
    Keymaster

    Using eme_eval_booking_form_post_filter this is possible, together with this function to get all events id based on the current event id:

    eme_get_recurrence_eventids($event[‘recurrence_id’]);

    #56281
    Anonymous
    Inactive

    Thank you very Much for your Advice!

    I tried to programm this code, following your adivce, quite able to book multiple dates

    add_filter(’eme_eval_booking_form_post_filter’,’do_my_filterss’);
    function do_my_filterss($event) {
    $event_id=$event[‘event_id’];
    $already_registered=0;
    $event_ids = eme_get_recurrence_eventids($event[‘recurrence_id’]);

    // get all attendees
    $attendees = eme_get_attendees_for($event_ids);
    $booker = eme_get_person_by_post();
    if (!empty($booker)) {
    foreach ($attendees as $attendee) {
    if ($attendee[‘person_id’]==$booker[‘person_id’])
    $already_registered=1;
    }
    }

    if (!$already_registered) {
    // eval is success
    return array(0=>1,1=>”);
    } else {
    // bad form entry
    return array(0=>0,1=>’Already registered’);
    }
    }

    #56282
    Franky
    Keymaster

    eme_get_attendees_for expects only 1 event id, so you should loop there …
    But this little extra will help you (allows eme_get_attendees_for to accept an array of event ids too):
    https://plugins.trac.wordpress.org/changeset/1689243/

    #56283
    Anonymous
    Inactive

    Thank you!

    So finally I already edited functions.php (WordPress Theme)

    /* ————————————————
    Doppelte Kursanmeldungen filtern
    ———————————————— */

    add_filter(’eme_eval_booking_form_post_filter’,’do_my_filterss’);
    function do_my_filterss($event) {
    $event_id=$event[‘event_id’];
    $already_registered=0;
    $event_ids = eme_get_recurrence_eventids($event[‘recurrence_id’]);

    // get all attendees
    $attendees = eme_get_attendees_for($event_ids);
    $booker = eme_get_person_by_post();
    if (!empty($booker)) {
    foreach ($attendees as $attendee) {
    if ($attendee[‘person_id’]==$booker[‘person_id’])
    $already_registered=1;
    }
    }

    if (!$already_registered) {
    // eval is success
    return array(0=>1,1=>”);
    } else {
    // bad form entry
    return array(0=>0,1=>’Already registered’);
    }
    }

    and now

    function eme_get_attendees_for($event_id,$pending_approved=0,$only_unpaid=0) {
    global $wpdb;
    $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
    if (is_array($event_id) && eme_array_integers($event_id)) {
    $sql = “SELECT DISTINCT person_id FROM $bookings_table WHERE event_id IN (“.join(“,”,$event_id).”)”;
    } else {
    $sql = $wpdb->prepare(“SELECT DISTINCT person_id FROM $bookings_table WHERE event_id = %d”,$event_id);
    }

    But still not working.

    I think there is a conflict between $event_id, because event_ids is the multiple ID array, and rsvp.php defines event_id as array ?
    Sorry, I´m a php Beginner.

    #56284
    Anonymous
    Inactive

    Thank you!

    So finally I already edited functions.php (WordPress Theme)

    /* ————————————————
    Doppelte Kursanmeldungen filtern
    ———————————————— */

    add_filter(’eme_eval_booking_form_post_filter’,’do_my_filterss’);
    function do_my_filterss($event) {
    $event_id=$event[‘event_id’];
    $already_registered=0;
    $event_ids = eme_get_recurrence_eventids($event[‘recurrence_id’]);

    // get all attendees
    $attendees = eme_get_attendees_for($event_ids);
    $booker = eme_get_person_by_post();
    if (!empty($booker)) {
    foreach ($attendees as $attendee) {
    if ($attendee[‘person_id’]==$booker[‘person_id’])
    $already_registered=1;
    }
    }

    if (!$already_registered) {
    // eval is success
    return array(0=>1,1=>”);
    } else {
    // bad form entry
    return array(0=>0,1=>’Already registered’);
    }
    }

    and now

    function eme_get_attendees_for($event_id,$pending_approved=0,$only_unpaid=0) {
    global $wpdb;
    $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
    if (is_array($event_id) && eme_array_integers($event_id)) {
    $sql = “SELECT DISTINCT person_id FROM $bookings_table WHERE event_id IN (“.join(“,”,$event_id).”)”;
    } else {
    $sql = $wpdb->prepare(“SELECT DISTINCT person_id FROM $bookings_table WHERE event_id = %d”,$event_id);
    }

    But still not working.

    I think there is a conflict between $event_id, because event_ids is the multiple ID array, and rsvp.php defines event_id as array ?
    Sorry, I´m a php Beginner.

    #56285
    Anonymous
    Inactive

    Thank you!

    So finally I already edited functions.php (WordPress Theme)

    /* ————————————————
    Doppelte Kursanmeldungen filtern
    ———————————————— */

    add_filter(’eme_eval_booking_form_post_filter’,’do_my_filterss’);
    function do_my_filterss($event) {
    $event_id=$event[‘event_id’];
    $already_registered=0;
    $event_ids = eme_get_recurrence_eventids($event[‘recurrence_id’]);

    // get all attendees
    $attendees = eme_get_attendees_for($event_ids);
    $booker = eme_get_person_by_post();
    if (!empty($booker)) {
    foreach ($attendees as $attendee) {
    if ($attendee[‘person_id’]==$booker[‘person_id’])
    $already_registered=1;
    }
    }

    if (!$already_registered) {
    // eval is success
    return array(0=>1,1=>”);
    } else {
    // bad form entry
    return array(0=>0,1=>’Already registered’);
    }
    }

    and now

    function eme_get_attendees_for($event_id,$pending_approved=0,$only_unpaid=0) {
    global $wpdb;
    $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
    if (is_array($event_id) && eme_array_integers($event_id)) {
    $sql = “SELECT DISTINCT person_id FROM $bookings_table WHERE event_id IN (“.join(“,”,$event_id).”)”;
    } else {
    $sql = $wpdb->prepare(“SELECT DISTINCT person_id FROM $bookings_table WHERE event_id = %d”,$event_id);
    }

    But still not working.

    I think there is a conflict between $event_id, because event_ids is the multiple ID array, and rsvp.php defines event_id as array ?
    Sorry, I´m a php Beginner.

    #56286
    Anonymous
    Inactive

    Thank you!

    So finally I already edited functions.php (WordPress Theme)

    /* ————————————————
    Doppelte Kursanmeldungen filtern
    ———————————————— */

    add_filter(’eme_eval_booking_form_post_filter’,’do_my_filterss’);
    function do_my_filterss($event) {
    $event_id=$event[‘event_id’];
    $already_registered=0;
    $event_ids = eme_get_recurrence_eventids($event[‘recurrence_id’]);

    // get all attendees
    $attendees = eme_get_attendees_for($event_ids);
    $booker = eme_get_person_by_post();
    if (!empty($booker)) {
    foreach ($attendees as $attendee) {
    if ($attendee[‘person_id’]==$booker[‘person_id’])
    $already_registered=1;
    }
    }

    if (!$already_registered) {
    // eval is success
    return array(0=>1,1=>”);
    } else {
    // bad form entry
    return array(0=>0,1=>’Already registered’);
    }
    }

    and now

    function eme_get_attendees_for($event_id,$pending_approved=0,$only_unpaid=0) {
    global $wpdb;
    $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
    if (is_array($event_id) && eme_array_integers($event_id)) {
    $sql = “SELECT DISTINCT person_id FROM $bookings_table WHERE event_id IN (“.join(“,”,$event_id).”)”;
    } else {
    $sql = $wpdb->prepare(“SELECT DISTINCT person_id FROM $bookings_table WHERE event_id = %d”,$event_id);
    }
    But still not working.

    I think there is a conflict between $event_id, because event_ids is the multiple ID array, and rsvp.php defines event_id as array ?
    Sorry, I´m a php Beginner.

    #56287
    Anonymous
    Inactive

    I tried these steps, but does not work for me

    Added second code.
    Is there an conflict between definition of event_ids for multiple IDs and the second code, that defines event_id as array?

    Sorry, I´m a php Beginner.

    #56288
    Franky
    Keymaster

    Teaching php is not part of EME 🙂
    But by doing the change I proposed in my last link, your code should work as is.

    #56289
    Anonymous
    Inactive

    Tried for a second time, no change, still able to register multiple times and other events from series

    rsvp.php

    function eme_get_attendees_for($event_id,$pending_approved=0,$only_unpaid=0) {
    global $wpdb;
    $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME;
    if (is_array($event_id) && eme_array_integers($event_id)) {
    $sql = “SELECT DISTINCT person_id FROM $bookings_table WHERE event_id IN (“.join(“,”,$event_id).”)”;
    } else {
    $sql = $wpdb->prepare(“SELECT DISTINCT person_id FROM $bookings_table WHERE event_id = %d”,$event_id);
    }

    and functions.php

    add_filter(’eme_eval_booking_form_post_filter’,’do_my_filterss’);
    function do_my_filterss($event) {
    $event_id=$event[‘event_id’];
    $already_registered=0;
    $event_ids = eme_get_recurrence_eventids($event[‘recurrence_id’]);

    // get all attendees
    $attendees = eme_get_attendees_for($event_ids);
    $booker = eme_get_person_by_post();
    if (!empty($booker)) {
    foreach ($attendees as $attendee) {
    if ($attendee[‘person_id’]==$booker[‘person_id’])
    $already_registered=1;
    }
    }

    if (!$already_registered) {
    // eval is success
    return array(0=>1,1=>”);
    } else {
    // bad form entry
    return array(0=>0,1=>’Already registered’);
    }
    }

    #56290
    Franky
    Keymaster

    Then either $event_ids or $attendees is empty. Do a print_r on those and an exit afterwards. Check the results. ..

    #56291
    Anonymous
    Inactive

    Thank you!
    Event IDS Results in Array ([0] => 13) Array ([0] => 13)

    Attendes Results in nothing.
    Thank you very much for further advice!

    #56292
    Franky
    Keymaster

    An array that only contains 1 id? That means it is not recurrent …
    I just tested your code locally: works just fine here.

    #56293
    Anonymous
    Inactive

    I tried for a second time with a new created event-series. Still does not work.
    So I tried experimenting with echo / print_r with other parameters.

    echo $event_id for single event does not show any result. Maybe there is an issue in my site by $event, so all following questionnaires like $event_id=$event(….) do not work? Do I have to add a definition of $event to functions.php maybe?

    #56294
    Anonymous
    Inactive

    So i checked our whole code. Co-Programmer entered filter in eme-functions.php. And I set up in functions.php of theme

    After deleting from eme-functions.php I get

    for event_ids

    rray ( [0] => 21 [1] => 23 [2] => 25 [3] => 27 [4] => 29 [5] => 31 ) )

    and:

    Array ( [S_J_3] => Array ( [person_id] => 3 [lastname] => S [firstname] => J [email] => jxxxx@xxx.de [phone] => [wp_id] => 1001046 [address1] => [address2] => [city] => [state] => [zip] => [country] => [lang] => ) )

    But double booking still works?

    #56295
    Anonymous
    Inactive

    So I finally solved. Whatever was not working by get_person_by_post.
    I finally changed to WordPress User IDs, so I used this code

    // get all attendees
    $attendees = eme_get_attendees_for($event_ids);
    $booker = get_current_user_id();
    if (!empty($booker)) {
    foreach ($attendees as $attendee) {
    if ($attendee[‘wp_id’]==$booker)
    $already_registered=1;
    }
    }

    if (!$already_registered) {
    // eval is success
    return array(0=>1,1=>”);
    } else {
    // bad form entry
    return array(0=>0,1=>’Already registered’);
    }
    }

    Works very well! Thank you for your fast and competent help! Thumbs up!

    #56297
    Franky
    Keymaster

    That works for registered users of course. But the other code using eme_get_person_by_post() works too (but maybe I wasn’t clear there: that function finds a eme person with the same lastname *and* email)

Viewing 18 posts - 1 through 18 (of 18 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top