芝麻web文件管理V1.00
编辑当前文件:/home/disqkgca/aqanet.org/wp-content/plugins/wpforms-lite/src/Admin/Helpers/Chart.php
setTimezone( $timezone ); $row_date_formatted = $row_datetime->format( self::DATE_FORMAT ); // We must take into account entries submitted at different hours of the day, // because it is possible that more than one entry could be submitted on a given day. if ( ! isset( $dataset[ $row_date_formatted ] ) ) { $dataset[ $row_date_formatted ] = $row_count; continue; } $dataset_count = $dataset[ $row_date_formatted ]; $dataset[ $row_date_formatted ] = $dataset_count + $row_count; } return self::format_chart_dataset_data( $dataset, $start_date, $end_date ); } /** * Format given forms dataset to ensure correct data structure is parsed for serving the "chart.js" instance. * i.e., [ '2023-02-11' => [ 'day' => '2023-02-11', 'count' => 12 ] ]. * * @since 1.8.2 * * @param array $dataset Dataset for the chart. * @param DateTimeImmutable $start_date Start date for the timespan. * @param DateTimeImmutable $end_date End date for the timespan. * * @return array */ private static function format_chart_dataset_data( $dataset, $start_date, $end_date ) { // In the event that there is no dataset to process, leave early. if ( empty( $dataset ) ) { return [ 0, [] ]; } $interval = new DateInterval( 'P1D' ); // Variable that store the date interval of period 1 day. $period = new DatePeriod( $start_date, $interval, $end_date ); // Used for iteration between start and end date period. $data = []; // Placeholder for the actual chart dataset data. $total_entries = 0; $has_non_zero_count = false; // Use loop to store date into array. foreach ( $period as $date ) { $date_formatted = $date->format( self::DATE_FORMAT ); $count = isset( $dataset[ $date_formatted ] ) ? (float) $dataset[ $date_formatted ] : 0; $total_entries += $count; $data[ $date_formatted ] = [ 'day' => $date_formatted, 'count' => $count, ]; // This check helps determine whether there is at least one non-zero count value in the dataset being processed. // It's used to optimize the function's behavior and to decide whether to include certain data in the returned result. if ( $count > 0 && ! $has_non_zero_count ) { $has_non_zero_count = true; } } return [ $total_entries, $has_non_zero_count ? $data : [], // We will return an empty array to indicate that there is no data to display. ]; } }