Ensuring that bar graphs are cleared before redrawing
This commit is contained in:
parent
4aeb8c37b6
commit
99c59cf977
@ -37,6 +37,9 @@ const width = 600; //+svg.attr("width");
|
||||
const height = 200; //+svg.attr("height");
|
||||
const margin = { top: 40, right: 30, bottom: 60, left: 30 };
|
||||
|
||||
//First clean the svg:
|
||||
svg.selectAll("*").remove();
|
||||
|
||||
// Draw the white background
|
||||
// Draw the rounded rectangle
|
||||
svg.append("rect")
|
||||
|
@ -1,4 +1,21 @@
|
||||
<?php
|
||||
|
||||
function insertOption($surveyId, $question, $option, $text, $pdo) {
|
||||
|
||||
// Prepare the SQL insert statement
|
||||
$stmt = $pdo->prepare("INSERT INTO Filters (surveyId, FilterQuestion, FilterOption, Text) VALUES (:survey, :question, :option, :text)");
|
||||
|
||||
$stmt->execute([
|
||||
':survey' => $surveyId,
|
||||
':question' => $question,
|
||||
':option' => $option,
|
||||
':text' => $text
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Load config
|
||||
$config = require 'config.php';
|
||||
$apiToken = $config['api_token'];
|
||||
@ -42,26 +59,54 @@ curl_close($ch);
|
||||
|
||||
$data = json_decode($response, true);
|
||||
|
||||
// Database connection (PDO)
|
||||
$pdo = new PDO("mysql:host=localhost;dbname={$config['db_name']};charset=utf8mb4", $config['db_user'], $config['db_pass']);
|
||||
|
||||
//Check if the survey data has previously been inserted:
|
||||
$checkSql = "SELECT 1 FROM Filters WHERE surveyId = :surveyId LIMIT 1";
|
||||
|
||||
$stmt = $pdo->prepare($checkSql);
|
||||
$stmt->execute([
|
||||
':surveyId' => $surveyId
|
||||
]);
|
||||
|
||||
if ($stmt->fetch()) {
|
||||
echo "Site already exists. Skipping insert.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (isset($data['result']['elements']) && is_array($data['result']['elements'])) {
|
||||
foreach ($data['result']['elements'] as $element) {
|
||||
if (isset($element['QuestionID'])) {
|
||||
echo "QuestionID: " . $element['QuestionID'] . "<br>". PHP_EOL;
|
||||
|
||||
if (isset($element['QuestionID']) && $element['QuestionID'] === "QID70") {
|
||||
|
||||
//echo json_encode($element, JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
}
|
||||
if (isset($element['QuestionID']) && $element['QuestionID'] === "QID68") {
|
||||
echo json_encode($element['QuestionDescription'], JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
echo json_encode($element['Choices'], JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
echo "Survey: {$surveyId}, QuestionID: {$element['QuestionID']} : Description: {$element['QuestionDescription']} : 0 ". PHP_EOL;
|
||||
insertOption($surveyId, $element['QuestionID'], 0, $element['QuestionDescription'], $pdo);
|
||||
foreach ($element['Choices'] as $index => $choice) {
|
||||
insertOption($surveyId, $element['QuestionID'], $index, $choice['Display'], $pdo);
|
||||
echo "ID: $index, Display: " . $choice['Display'] . "<br>";
|
||||
}
|
||||
}
|
||||
if (isset($element['QuestionID']) && $element['QuestionID'] === "QID69") {
|
||||
echo json_encode($element['QuestionDescription'], JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
echo json_encode($element['Choices'], JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
echo "Survey: {$surveyId}, QuestionID: {$element['QuestionID']} : Description: {$element['QuestionDescription']} : 0 ". PHP_EOL;
|
||||
insertOption($surveyId, $element['QuestionID'], 0, $element['QuestionDescription'], $pdo);
|
||||
foreach ($element['Choices'] as $index => $choice) {
|
||||
insertOption($surveyId, $element['QuestionID'], $index, $choice['Display'], $pdo);
|
||||
echo "ID: $index, Display: " . $choice['Display'] . "<br>";
|
||||
}
|
||||
}
|
||||
if (isset($element['QuestionID']) && $element['QuestionID'] === "QID70") {
|
||||
echo json_encode($element['QuestionDescription'], JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
echo json_encode($element['Choices'], JSON_PRETTY_PRINT) . PHP_EOL;
|
||||
echo "Survey: {$surveyId}, QuestionID: {$element['QuestionID']} : Description: {$element['QuestionDescription']} : 0 ". PHP_EOL;
|
||||
insertOption($surveyId, $element['QuestionID'], 0, $element['QuestionDescription'], $pdo);
|
||||
foreach ($element['Choices'] as $index => $choice) {
|
||||
insertOption($surveyId, $element['QuestionID'], $index, $choice['Display'], $pdo);
|
||||
echo "ID: $index, Display: " . $choice['Display'] . "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user