Events Made Easy › Forums › How do I … › No Double Registration for recurring events
- This topic has 17 replies, 2 voices, and was last updated 7 years, 4 months ago by Franky.
-
AuthorPosts
-
Sun 2 Jul 2017 at 20:34 #56278AnonymousInactive
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.10When 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!
Sun 2 Jul 2017 at 21:03 #56280FrankyKeymasterUsing 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’]);
Sun 2 Jul 2017 at 22:54 #56281AnonymousInactiveThank 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’);
}
}Mon 3 Jul 2017 at 00:00 #56282FrankyKeymastereme_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/Mon 3 Jul 2017 at 00:20 #56283AnonymousInactiveThank 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.Mon 3 Jul 2017 at 00:24 #56284AnonymousInactiveThank 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.Mon 3 Jul 2017 at 00:25 #56285AnonymousInactiveThank 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.Mon 3 Jul 2017 at 00:26 #56286AnonymousInactiveThank 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.Mon 3 Jul 2017 at 00:27 #56287AnonymousInactiveI 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.
Mon 3 Jul 2017 at 00:38 #56288FrankyKeymasterTeaching php is not part of EME 🙂
But by doing the change I proposed in my last link, your code should work as is.Mon 3 Jul 2017 at 00:49 #56289AnonymousInactiveTried 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’);
}
}Mon 3 Jul 2017 at 14:36 #56290FrankyKeymasterThen either $event_ids or $attendees is empty. Do a print_r on those and an exit afterwards. Check the results. ..
Mon 3 Jul 2017 at 17:18 #56291AnonymousInactiveThank you!
Event IDS Results in Array ([0] => 13) Array ([0] => 13)Attendes Results in nothing.
Thank you very much for further advice!Mon 3 Jul 2017 at 19:49 #56292FrankyKeymasterAn array that only contains 1 id? That means it is not recurrent …
I just tested your code locally: works just fine here.Mon 3 Jul 2017 at 20:29 #56293AnonymousInactiveI 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?
Mon 3 Jul 2017 at 21:13 #56294AnonymousInactiveSo 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?
Mon 3 Jul 2017 at 21:25 #56295AnonymousInactiveSo 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!
Mon 3 Jul 2017 at 23:21 #56297FrankyKeymasterThat 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)
-
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.