Home › Forums › General Issues › 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>
;
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
The most recent ACF Chat Friday featured a live demo of how to register CPTs directly in the plugin, one of our most requested features. Check out the summary below for a replay of the demo, and don’t forget to register for the next session! https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.