From 3680b4703298c57210f5d025a70fbbf1f6565a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20G=C3=A5rdenberg?= Date: Mon, 8 Apr 2024 16:06:49 +0200 Subject: [PATCH] feat: Support for EduAdmin Form Reserve/Waiting Lists when the event is fully booked. Also fixes bug with percent values on OnDemand courses/events where the values looked at are null. fixes #455 --- PLUGIN-CHECKSUM | 2 +- .../detailTemplate/blocks/event-item.php | 25 ++++++++++++++----- .../listTemplate/blocks/event-block-a.php | 19 +++++++++++--- .../listTemplate/blocks/event-block-b.php | 19 +++++++++++--- includes/edu-text-functions.php | 18 +++++++------ includes/eduapi-helper-functions.php | 16 ++++++------ 6 files changed, 71 insertions(+), 28 deletions(-) diff --git a/PLUGIN-CHECKSUM b/PLUGIN-CHECKSUM index 009142fc..5950f823 100644 --- a/PLUGIN-CHECKSUM +++ b/PLUGIN-CHECKSUM @@ -1 +1 @@ -7fe2fe0a83fb2450129bed8f524c65b1 +c60aea30fa4821f190288d72e54fdf34 diff --git a/content/template/detailTemplate/blocks/event-item.php b/content/template/detailTemplate/blocks/event-item.php index 94dbffc8..b0d0c0ea 100644 --- a/content/template/detailTemplate/blocks/event-item.php +++ b/content/template/detailTemplate/blocks/event-item.php @@ -72,15 +72,28 @@ class="eventItem 0 && $i >= $show_more ? ' showMoreHidde + + + + + + - + - - diff --git a/content/template/listTemplate/blocks/event-block-a.php b/content/template/listTemplate/blocks/event-block-a.php index d7564699..d174269b 100644 --- a/content/template/listTemplate/blocks/event-block-a.php +++ b/content/template/listTemplate/blocks/event-block-a.php @@ -80,9 +80,22 @@ class="objectItem - - + + + + + + diff --git a/content/template/listTemplate/blocks/event-block-b.php b/content/template/listTemplate/blocks/event-block-b.php index 75fe990c..2375f1a4 100644 --- a/content/template/listTemplate/blocks/event-block-b.php +++ b/content/template/listTemplate/blocks/event-block-b.php @@ -76,9 +76,22 @@ class="objectBlock brick - - + + + + + + diff --git a/includes/edu-text-functions.php b/includes/edu-text-functions.php index 0b0b5913..7bd862c2 100644 --- a/includes/edu-text-functions.php +++ b/includes/edu-text-functions.php @@ -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'; } @@ -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] ); @@ -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 ); @@ -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; @@ -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 ) { @@ -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 ]; } @@ -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' ); } @@ -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; } } diff --git a/includes/eduapi-helper-functions.php b/includes/eduapi-helper-functions.php index 4b4de8ae..25a232ec 100644 --- a/includes/eduapi-helper-functions.php +++ b/includes/eduapi-helper-functions.php @@ -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;'; @@ -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;'; @@ -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;'; @@ -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;'; @@ -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;'; @@ -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 { @@ -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;'; @@ -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 {