Renders evaluation results for a specific form.
Description
See also
Parameters
- $results
-
(array) (Required) Results to show.
- $form
-
(awsmug\Torro_Forms\DB_Objects\Forms\Form) (Required) Form the results belong to.
- $args
-
(array) (Optional) Additional arguments for displaying the results.
- 'total'
(bool) Whether to show total results. Default true. - 'year'
(int|string|array) One or more years to only display results for those. Otherwise results are displayed for all relevant years. Default none.
Default value: array()
- 'total'
Source
File: src/modules/evaluators/participation.php
public function show_results( $results, $form, $args = array() ) { $args = wp_parse_args( $args, array( 'total' => true, 'year' => 0, ) ); $args['total'] = rest_sanitize_boolean( $args['total'] ); $total_count = 0; if ( isset( $results['total'] ) ) { $total_count = $results['total']; unset( $results['total'] ); } if ( ! empty( $results ) ) { ksort( $results ); $keys = array_keys( $results ); $min_year = $keys[0]; $max_year = $keys[ count( $keys ) - 1 ]; $years = array_map( 'strval', range( (int) $min_year, (int) $max_year, 1 ) ); } else { $years = array( (string) current_time( 'Y' ) ); } $tabs = array(); if ( $args['total'] ) { $tabs['total'] = array( 'label' => _x( 'Total', 'submission count', 'torro-forms' ), 'callback' => function() use ( $results, $years, $total_count, $form ) { $year_results = array(); foreach ( $years as $year ) { if ( isset( $results[ $year ]['total'] ) ) { $year_results[] = (int) $results[ $year ]['total']; } else { $year_results[] = 0; } } ?> <p> <strong> <?php _e( 'Number of completed submissions:', 'torro-forms' ); ?> <?php echo absint( $total_count ); ?> </strong> </p> <div id="<?php echo esc_attr( $this->slug . '-chart-total' ); ?>"></div> <script type="application/json" class="c3-chart-data"> <?php echo json_encode( $this->get_chart_json( $form, esc_attr( $this->slug . '-chart-total' ), $years, $year_results, __( 'Years', 'torro-forms' ), __( 'Submission Count', 'torro-forms' ) ) ); ?> </script> <?php }, ); } if ( ! empty( $args['year'] ) ) { if ( is_int( $args['year'] ) ) { $years = array( $args['year'] ); } else { $years = wp_parse_id_list( $args['year'] ); } } foreach ( $years as $year ) { $tabs[ $year ] = array( 'label' => $year, 'callback' => function() use ( $results, $year, $form ) { global $wp_locale; $total_count = isset( $results[ $year ]['total'] ) ? $results[ $year ]['total'] : 0; $months = $wp_locale->month; $month_results = array(); foreach ( $months as $index => $month ) { if ( isset( $results[ $year ][ $index ] ) ) { $month_results[] = (int) $results[ $year ][ $index ]; } else { $month_results[] = 0; } } ?> <p> <strong> <?php /* translators: %s: a year */ printf( __( 'Number of completed submissions in %s:', 'torro-forms' ), $year ); ?> <?php echo absint( $total_count ); ?> </strong> </p> <div id="<?php echo esc_attr( $this->slug . '-chart-' . $year ); ?>"></div> <script type="application/json" class="c3-chart-data"> <?php echo json_encode( $this->get_chart_json( $form, esc_attr( $this->slug . '-chart-' . $year ), array_values( $months ), $month_results, __( 'Months', 'torro-forms' ), __( 'Submission Count', 'torro-forms' ) ) ); ?> </script> <?php }, ); } $this->display_tabs( $tabs ); }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |