Support

Account

Home Forums General Issues AJAX Blocks Call

Unread

AJAX Blocks Call

  • I have a block that I created and I am looking to update the fields based upon a date range being selected and then having that data update other data that is not touch yed.

    <?php
    
    /**
     * Composite Reports Block Template.
     *
     * @param   array $block The block settings and attributes.
     * @param   string $content The block inner HTML (empty).
     * @param   bool $is_preview True during AJAX preview.
     * @param   (int|string) $post_id The post ID this block is saved to.
     */
    
    // Global Declarations
    global $wpdb;
    
    // Create id attribute allowing for custom "anchor" value.
    $id = 'composite_reports-' . $block['id'];
    if( !empty($block['anchor']) ) {
        $id = $block['anchor'];
    }
    
    // Create class attribute allowing for custom "className" and "align" values.
    $className = 'composite_reports';
    if( !empty($block['className']) ) {
        $className .= ' ' . $block['className'];
    }
    if( !empty($block['align']) ) {
        $className .= ' align' . $block['align'];
    }
    
    // Load values and assign defaults.
    $trainee = get_field('trainee_name') ?: 'Traine Name...';
    $date_from = get_field('date_from') ?: date("01/01/2020");
    $date_to = get_field('date_to') ?: date("m/d/Y");
    $desktop_limit = get_field('desktop_limit') ?: 1000;
    $mobile_limit = get_field('mobile_limit') ?: 5;
    
    // echo $trainee . '<br>';
    // echo $date_from . '<br>';
    // echo $date_to . '<br>';
    // echo $desktop_limit . '<br>';
    // echo $mobile_limit . '<br>';
    
    $procedureDates = [];
    $traineeScores = [];
    $attendingScores = [];
    
    echo $trainee;
    
    // Composite Report Data Queries
    
    $results = $wpdb->get_results("SELECT * FROM (SELECT t1.traineeName, t1.procedureDate, t1.surgeryID, t1.traineeRemovesFatAdrenalRating, t1.traineeSkeletonizesRenalVeinRating, t1.traineeSkeletonizesArteryRating, t1.traineeDonorArteriesRating, t1.traineeRenalVeinAugmentationRating, t1.traineeOverallPerformanceRating, t2.doctorRemovesFatAdrenalRating, t2.doctorSkeletonizesRenalVeinRating, t2.doctorSkeletonizesArteryRating, t2.doctorDonorArteriesRating, t2.doctorRenalVeinAugmentationRating, t2.doctorOverallPerformanceRating FROM BackbenchKidneyChartTrainee t1 JOIN BackbenchKidneyChartDoctor t2 ON t1.traineeName = t2.traineeName WHERE t1.surgeryID = t2.surgeryID AND (t1.traineeName = '" . $trainee . "' AND t2.traineeName = '" . $trainee . "') AND " . date(t1.procedureDate) . " BETWEEN '" . $date_from . "' AND '" . $date_to . "' ORDER BY t1.surgeryID DESC LIMIT " . $desktop_limit . ") t3 ORDER BY t3.surgeryID ASC");
    //STR_TO_DATE(, '%m/%d/%Y')
    
    $overallResults = $wpdb->get_results("SELECT * FROM (SELECT t1.traineeName, t1.procedureDate, t1.surgeryID, t1.traineeOverallPerformanceRating, t2.doctorOverallPerformanceRating FROM BackbenchKidneyChartTrainee t1 JOIN BackbenchKidneyChartDoctor t2 ON t1.traineeName = t2.traineeName WHERE t1.surgeryID = t2.surgeryID AND (t1.traineeName = '" . $trainee . "' AND t2.traineeName = '" . $trainee . "') AND STR_TO_DATE(t1.procedureDate, '%m/%d/%Y') BETWEEN STR_TO_DATE('" . $date_from . "', '%m/%d/%Y') AND STR_TO_DATE('" . $date_to . "', '%m/%d/%Y') ORDER BY t1.surgeryID DESC LIMIT " . $desktop_limit . ") t3 ORDER BY t3.surgeryID ASC");
    
    $overall = json_encode($overallResults);
    
    if ( ! empty( $overallResults ) ) {
            foreach($overallResults as $row) {
    				array_push($procedureDates, "'" . $row->procedureDate . "'" );
    				array_push($traineeScores, $row->traineeOverallPerformanceRating);
    				array_push($attendingScores, $row->doctorOverallPerformanceRating);
            }
        }
    
    // print_r(array_values($procedureDates)) . '<br>';
    // print_r(array_values($traineeScores)) . '<br>';
    // print_r(array_values($attendingScroes)) . '<br>';
    
    $procedureDate = implode(', ', $procedureDates);
    $traineeScore = implode(', ', $traineeScores);
    $attendingScore = implode(', ', $attendingScores);
    
    ?>
    
    <script type="text/javascript">
    
    jQuery(function() {
      var chart = jQuery('#container').highcharts({
        chart: {},
    	title: {
        	text: 'Overall Performance'
    	},
        xAxis: {
          categories: [<?php echo $procedureDate; ?>]
        },
    
        yAxis: {
    	min: 1,
        max: 4,
        title: {
          text: 'Values'
        },
        plotLines: [{
          
    	}]
      },
    
        legend: {
    	  enabled: true,
          align: 'center',
          verticalAlign: 'bottom',
          x: 0,
          y: 0
        },
    
        credits: {
          enabled: false
        },
    	  
    	exporting: {
        	enabled: false
      	},
    
        series: [
    	{
        	name: 'Trainee',
        	data: [<?php echo $traineeScore; ?>]
      	},
    	{
        	name: 'Attending',
        	data: [<?php echo $attendingScore; ?>]
      	}]
      }, function(chart) {
    
      });
    
    });
    	
    </script>
    
    <div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
        <div id="container" style="height: 400px"></div>
    
    </div>

    ;

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.