From 2f52e88945feef22ad2c9bebe56564b5c426954e Mon Sep 17 00:00:00 2001 From: Timi Wahalahti Date: Thu, 21 Sep 2023 00:52:59 +0300 Subject: [PATCH] add new step to accomodate sponsorship agreement pre-filling data based on sponsor posts on site --- .../classes/class-wordcamp-docs.php | 51 +++++++++-- .../templates/sponsorship-agreement.php | 84 ++++++++++++++++--- 2 files changed, 115 insertions(+), 20 deletions(-) diff --git a/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php b/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php index 465fb2259..6fd00fb84 100644 --- a/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php +++ b/public_html/wp-content/plugins/wordcamp-docs/classes/class-wordcamp-docs.php @@ -86,20 +86,36 @@ public static function form_handler() { // Check selected template on any step. $templates = self::get_templates(); - $template = sanitize_text_field( $_POST['wcdocs_template'] ); - if ( ! array_key_exists( $template, $templates ) ) + $template_selected = sanitize_text_field( $_POST['wcdocs_template'] ); + if ( ! array_key_exists( $template_selected, $templates ) ) return self::error( __( 'Selected template does not exist', 'wordcamporg' ) ); - $template = $templates[ $template ]; + $template = $templates[ $template_selected ]; switch ( $step ) { case 1: // submitted step 1 - // Nothing else to check on this step. - self::$step = 2; + if ( 'sponsorship-agreement' == $template_selected ) { + self::$step = 10; + } else { + // Nothing else to check on this step. + self::$step = 20; + } + + break; + + case 10; // submitted step 10 + // Sanitize input + $data = $template->sanitize( $_POST ); + + if ( 'sponsorship-agreement' == $template_selected ) { + if ( 'wcb_sponsor' === get_post_type( $data['sponsor_id'] ) ) { + self::$step = 20; + } + } break; - case 2: // submitted step 2 + case 20: // submitted step 20 require_once( WORDCAMP_DOCS__PLUGIN_DIR . 'classes/class-wordcamp-docs-pdf-generator.php' ); $generator = new WordCamp_Docs_PDF_Generator; @@ -166,12 +182,29 @@ public static function render_menu_page() {

- + + +
+ + + + + form_prefill_select( $_POST ); + ?> + +

+ +

+
+ +
- + - + 'wcb_sponsor', + 'post_status' => 'publish', + 'posts_per_page' => 500, + ) ); + ?> + + +
+ + + + + + + +
+ + '', - 'sponsor_rep_name' => '', - 'sponsor_rep_title' => '', + $date_format = get_option( 'date_format' ); - 'agreement_date' => '', - 'wordcamp_location' => '', - 'wordcamp_date' => '', + $sponsor_id = absint( $data['sponsor_id'] ); + $sponsor_amount = get_post_meta( $sponsor_id, '_wcb_sponsor_amount', true ); + $sponsor_currency = get_post_meta( $sponsor_id, '_wcb_sponsor_currency', true ); - 'sponsorship_amount' => '', - 'sponsorship_amount_num' => '', - 'sponsorship_benefits' => '', + $wordcamp = get_wordcamp_post(); + $start_date = ! empty( $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) ? date( $date_format, $wordcamp->meta['Start Date (YYYY-mm-dd)'][0] ) : ''; + $end_date = ! empty( $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) ? date( $date_format, $wordcamp->meta['End Date (YYYY-mm-dd)'][0] ) : $start_date; + + $number_formatter = new NumberFormatter( get_locale(), NumberFormatter::SPELLOUT ); + $sponsorship_amount = $number_formatter->format( $sponsor_amount ) . " {$sponsor_currency}"; + + $number_formatter = new NumberFormatter( get_locale(), NumberFormatter::CURRENCY ); + $sponsorship_amount_num = $number_formatter->formatCurrency( $sponsor_amount, $sponsor_currency ); + + $data = wp_parse_args( $data, array( + 'sponsor_name' => get_the_title( $sponsor_id ), + 'sponsor_rep_name' => get_post_meta( $sponsor_id, '_wcpt_sponsor_first_name', true ) . ' ' . get_post_meta( $sponsor_id, '_wcpt_sponsor_last_name', true ), + 'sponsor_rep_title' => '', + 'agreement_date' => wp_date( $date_format ), + 'wordcamp_location' => $wordcamp->meta['Location'][0], + 'wordcamp_date' => ( $start_date !== $end_date ) ? "{$start_date} - {$end_date}" : $start_date, + 'sponsorship_amount' => $sponsorship_amount, + 'sponsorship_amount_num' => $sponsorship_amount_num, + 'sponsorship_benefits' => '', ) ); ?>