Skip to content

Commit

Permalink
feat: Support for EduAdmin Form Reserve/Waiting Lists when the event …
Browse files Browse the repository at this point in the history
…is fully booked.

Also fixes bug with percent values on OnDemand courses/events where the values looked at are null.
fixes #455
  • Loading branch information
itssimple committed Apr 8, 2024
1 parent 353e4dd commit 3680b47
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 28 deletions.
2 changes: 1 addition & 1 deletion PLUGIN-CHECKSUM
@@ -1 +1 @@
7fe2fe0a83fb2450129bed8f524c65b1
c60aea30fa4821f190288d72e54fdf34
25 changes: 19 additions & 6 deletions content/template/detailTemplate/blocks/event-item.php
Expand Up @@ -72,15 +72,28 @@ class="eventItem<?php echo( $show_more > 0 && $i >= $show_more ? ' showMoreHidde
<?php
}
} else {
if ( $allow_interest_reg_event && false !== $event_interest_page ) {
if ( $use_eduadmin_form ) {
if ( $ev['UseWaitingList'] ) {
?>
<a class="bookButton book-link cta-btn" href="javascript://"
onclick="edu_OpenEduBookingFormModal('<?php echo esc_js( $ev['BookingFormUrl'] ); ?>');"><?php echo esc_html_x( 'Reserve list', 'frontend', 'eduadmin-booking' ); ?></a>
<?php
} else {
?>
<i class="fullBooked"><?php echo esc_html_x( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
}
} else {
if ( $allow_interest_reg_event && false !== $event_interest_page ) {
?>
<a class="inquiry-link"
href="<?php echo esc_url( $base_url . '/' . make_slugs( $name ) . '__' . $selected_course['CourseTemplateId'] . '/book/interest/?eid=' . $ev['EventId'] . edu_get_query_string( '&', array( 'eid' ) ) . '&_=' . time() ); ?>"><?php echo esc_html_x( 'Inquiry', 'frontend', 'eduadmin-booking' ); ?></a>
<?php
}
?>
<a class="inquiry-link"
href="<?php echo esc_url( $base_url . '/' . make_slugs( $name ) . '__' . $selected_course['CourseTemplateId'] . '/book/interest/?eid=' . $ev['EventId'] . edu_get_query_string( '&', array( 'eid' ) ) . '&_=' . time() ); ?>"><?php echo esc_html_x( 'Inquiry', 'frontend', 'eduadmin-booking' ); ?></a>
<i class="fullBooked"><?php echo esc_html_x( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
}
?>
<i class="fullBooked"><?php echo esc_html_x( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
}
} else {
?>
Expand Down
19 changes: 16 additions & 3 deletions content/template/listTemplate/blocks/event-block-a.php
Expand Up @@ -80,9 +80,22 @@ class="objectItem <?php echo edu_get_percent_from_values( $spots_left, intval( $
<?php
}
} else {
?>
<i class="fullBooked"><?php _ex( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
if ( $use_eduadmin_form ) {
if ( $event['UseWaitingList'] ) {
?>
<a class="bookButton book-link cta-btn" href="javascript://"
onclick="edu_OpenEduBookingFormModal('<?php echo esc_js( $event['BookingFormUrl'] ); ?>');"><?php echo esc_html_x( 'Reserve list', 'frontend', 'eduadmin-booking' ); ?></a>
<?php
} else {
?>
<i class="fullBooked"><?php echo esc_html_x( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
}
} else {
?>
<i class="fullBooked"><?php _ex( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
}
}
} else {
?>
Expand Down
19 changes: 16 additions & 3 deletions content/template/listTemplate/blocks/event-block-b.php
Expand Up @@ -76,9 +76,22 @@ class="objectBlock brick <?php echo edu_get_percent_from_values( $spots_left, $e
<?php
}
} else {
?>
<i class="fullBooked"><?php _ex( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
if ( $use_eduadmin_form ) {
if ( $event['UseWaitingList'] ) {
?>
<a class="bookButton book-link cta-btn" href="javascript://"
onclick="edu_OpenEduBookingFormModal('<?php echo esc_js( $event['BookingFormUrl'] ); ?>');"><?php echo esc_html_x( 'Reserve list', 'frontend', 'eduadmin-booking' ); ?></a>
<?php
} else {
?>
<i class="fullBooked"><?php echo esc_html_x( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
}
} else {
?>
<i class="fullBooked"><?php _ex( 'Full', 'frontend', 'eduadmin-booking' ); ?></i>
<?php
}
}
} else {
?>
Expand Down
18 changes: 11 additions & 7 deletions includes/edu-text-functions.php
Expand Up @@ -106,6 +106,10 @@ function edu_get_price( $price, $vatPercent, $settings_override = '' ) {
}

function edu_get_percent_from_values( $current_value, $max_value ) {
if ( null === $current_value || null === $max_value ) {
return 'percentUnknown';
}

if ( 0 === $current_value || 0 === $max_value ) {
return 'percentUnknown';
}
Expand Down Expand Up @@ -813,7 +817,7 @@ function get_spots_left( $free_spots, $max_spots, $spot_option = 'exactNumbers',
} else {
$lines = explode( "\n", $interval );
foreach ( $lines as $line ) {
if ( stripos( $line, '-' ) > -1 ) {
if ( stripos( $line, '-' ) > - 1 ) {
$range = explode( '-', $line );
$min = intval( $range[0] );
$max = intval( $range[1] );
Expand All @@ -822,7 +826,7 @@ function get_spots_left( $free_spots, $max_spots, $spot_option = 'exactNumbers',

return sprintf( _x( '%1$s spots left', 'frontend', 'eduadmin-booking' ), $line );
}
} elseif ( stripos( $line, '+' ) > -1 ) {
} elseif ( stripos( $line, '+' ) > - 1 ) {
/* translators: 1: Number of spots (range) */

return sprintf( _x( '%1$s spots left', 'frontend', 'eduadmin-booking' ), $line );
Expand Down Expand Up @@ -965,7 +969,7 @@ function edu_get_date_range( $days, $short, $event, $show_days, $always_show_sch

$total_days = count( $days );

for ( $x = 0; $x < $total_days; $x++ ) {
for ( $x = 0; $x < $total_days; $x ++ ) {
$day = $days[ $x ];

$added_dates[ edu_get_timezoned_date( 'H:i', $day['StartDate'] ) . '-' . edu_get_timezoned_date( 'H:i', $day['EndDate'] ) ][] = $day;
Expand Down Expand Up @@ -1177,7 +1181,7 @@ function DateComparer( $a, $b ) {
return 0;
}

return ( $a_date < $b_date ? -1 : 1 );
return ( $a_date < $b_date ? - 1 : 1 );
}

function KeySort( $key ) {
Expand Down Expand Up @@ -1378,7 +1382,7 @@ function edu_event_listitem_applicationopendate( $application_open_date ) {
function my_str_split( $string ) {
$s_array = array();
$slen = strlen( $string );
for ( $i = 0; $i < $slen; $i++ ) {
for ( $i = 0; $i < $slen; $i ++ ) {
$s_array[ (string) $i ] = $string[ $i ];
}

Expand Down Expand Up @@ -1932,7 +1936,7 @@ function remove_duplicates( $s_search, $s_replace, $s_subject ) {
$s_subject = str_replace( $s_search, $s_replace, $s_subject );
$pos = strpos( $s_subject, $s_search );

$i++;
$i ++;
if ( $i > 100 ) {
die( 'removeDuplicates() loop error' );
}
Expand All @@ -1950,6 +1954,6 @@ function edu_starts_with( $haystack, $needle ) {

if ( ! function_exists( 'edu_ends_with' ) ) {
function edu_ends_with( $haystack, $needle ) {
return substr( $haystack, -strlen( $needle ) ) === $needle;
return substr( $haystack, - strlen( $needle ) ) === $needle;
}
}
16 changes: 8 additions & 8 deletions includes/eduapi-helper-functions.php
Expand Up @@ -53,7 +53,7 @@ public function GetCourseDetailInfo( $course_id, $fetch_months, $group_by_city )
';' .
'$orderby=StartDate asc' . ( $group_by_city ? ', City asc' : '' ) .
';' .
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,LocationId,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,ApplicationOpenDate,LastApplicationDate';
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,LocationId,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,ApplicationOpenDate,LastApplicationDate,UseWaitingList';

$expands['CustomFields'] = '$filter=ShowOnWeb;$select=CustomFieldId,CustomFieldName,CustomFieldType,CustomFieldValue,CustomFieldChecked,CustomFieldDate,CustomFieldAlternativeId,CustomFieldAlternativeValue;';

Expand Down Expand Up @@ -116,7 +116,7 @@ public function GetOnDemandCourseDetailInfo( $course_id, $group_by_city ) {
';' .
'$orderby=StartDate asc' . ( $group_by_city ? ', City asc' : '' ) .
';' .
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,LocationId,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,ApplicationOpenDate';
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,LocationId,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,ApplicationOpenDate,UseWaitingList';

$expands['CustomFields'] = '$filter=ShowOnWeb;$select=CustomFieldId,CustomFieldName,CustomFieldType,CustomFieldValue,CustomFieldChecked,CustomFieldDate,CustomFieldAlternativeId,CustomFieldAlternativeValue;';

Expand Down Expand Up @@ -188,7 +188,7 @@ public function GetCourseList( $attributes, $category_id, $city, $subjectid, $co
';' .
'$orderby=StartDate asc' .
';' .
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate,LastApplicationDate';
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate,LastApplicationDate,UseWaitingList';

$expands['CustomFields'] = '$filter=ShowOnWeb;$select=CustomFieldId,CustomFieldName,CustomFieldType,CustomFieldValue,CustomFieldChecked,CustomFieldDate,CustomFieldAlternativeId,CustomFieldAlternativeValue;';

Expand Down Expand Up @@ -303,7 +303,7 @@ public function GetOnDemandCourseList( $attributes, $category_id, $city, $subjec
';' .
'$orderby=StartDate asc' .
';' .
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate';
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate,UseWaitingList';

$expands['CustomFields'] = '$filter=ShowOnWeb;$select=CustomFieldId,CustomFieldName,CustomFieldType,CustomFieldValue,CustomFieldChecked,CustomFieldDate,CustomFieldAlternativeId,CustomFieldAlternativeValue;';

Expand Down Expand Up @@ -417,7 +417,7 @@ public function GetEventList( $attributes, $category_id, $city, $subjectid, $cou
';' .
'$orderby=StartDate asc' .
';' .
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate,LastApplicationDate';
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate,LastApplicationDate,UseWaitingList';

$expands['CustomFields'] = '$filter=ShowOnWeb;$select=CustomFieldId,CustomFieldName,CustomFieldType,CustomFieldValue,CustomFieldChecked,CustomFieldDate,CustomFieldAlternativeId,CustomFieldAlternativeValue;';

Expand Down Expand Up @@ -456,7 +456,7 @@ public function GetEventList( $attributes, $category_id, $city, $subjectid, $cou
$order = array();
$custom_order = explode( ' ', $custom_order_by_order );
foreach ( $custom_order as $coVal ) {
! isset( $coVal ) || $coVal === "asc" ? array_push( $order, 1 ) : array_push( $order, -1 );
! isset( $coVal ) || $coVal === "asc" ? array_push( $order, 1 ) : array_push( $order, - 1 );
}
}
} else {
Expand Down Expand Up @@ -531,7 +531,7 @@ public function GetOnDemandEventList( $attributes, $category_id, $city, $subject
';' .
'$orderby=StartDate asc' .
';' .
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate';
'$select=EventId,City,ParticipantNumberLeft,MaxParticipantNumber,StartDate,EndDate,AddressName,EventName,ParticipantVat,BookingFormUrl,OnDemand,OnDemandPublished,OnDemandAccessDays,LocationId,ApplicationOpenDate,UseWaitingList';

$expands['CustomFields'] = '$filter=ShowOnWeb;$select=CustomFieldId,CustomFieldName,CustomFieldType,CustomFieldValue,CustomFieldChecked,CustomFieldDate,CustomFieldAlternativeId,CustomFieldAlternativeValue;';

Expand Down Expand Up @@ -571,7 +571,7 @@ public function GetOnDemandEventList( $attributes, $category_id, $city, $subject
$order = array();
$custom_order = explode( ' ', $custom_order_by_order );
foreach ( $custom_order as $coVal ) {
! isset( $coVal ) || $coVal === "asc" ? array_push( $order, 1 ) : array_push( $order, -1 );
! isset( $coVal ) || $coVal === "asc" ? array_push( $order, 1 ) : array_push( $order, - 1 );
}
}
} else {
Expand Down

0 comments on commit 3680b47

Please sign in to comment.