From 5791273f567c08010e5a4ce47f0822823d824d2d Mon Sep 17 00:00:00 2001 From: Matt Way Date: Mon, 18 Nov 2024 00:20:50 +1100 Subject: [PATCH] Update template to support elected candidate data --- make-council-pages.sh | 8 ++++- php-template/example-candidates-elected.csv | 2 ++ php-template/main.php | 33 ++++++++++++++++++++- php-template/template.php | 12 +++++++- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 php-template/example-candidates-elected.csv diff --git a/make-council-pages.sh b/make-council-pages.sh index bed59c6..c821993 100755 --- a/make-council-pages.sh +++ b/make-council-pages.sh @@ -38,7 +38,13 @@ function create_or_update_page() { candidates_file="$DATA_PATH"/$slug/candidates-generic.csv fi - content=$(echo "$council_block" | jq -c | php php-template/main.php --council-file "php://stdin" --candidates-file "$candidates_file" --media-file "$DATA_PATH"/$slug/media.json ) + if test -f "$DATA_PATH"/$slug/candidates-elected.csv; then + candidates_elected_file="$DATA_PATH"/$slug/candidates-elected.csv + echo "Found candidates-elected.csv" + fi + + + content=$(echo "$council_block" | jq -c | php php-template/main.php --council-file "php://stdin" --candidates-file "$candidates_file" --media-file "$DATA_PATH"/$slug/media.json --candidates-elected-file "$candidates_elected_file" ) if [ $? -eq 0 ]; then diff --git a/php-template/example-candidates-elected.csv b/php-template/example-candidates-elected.csv new file mode 100644 index 0000000..5718efe --- /dev/null +++ b/php-template/example-candidates-elected.csv @@ -0,0 +1,2 @@ +Ward,Candidate Name,Elected +Harvester,Joe Blogs,y \ No newline at end of file diff --git a/php-template/main.php b/php-template/main.php index 3a575a3..6dd43bd 100644 --- a/php-template/main.php +++ b/php-template/main.php @@ -1,7 +1,7 @@ $value) { + $electedCandidate[$value] = $data[$key]; + } + foreach ($candidateData as &$candidate) { + if ($candidate["Candidate Name"] == $electedCandidate["Candidate Name"]) { + if ($electedCandidate["Elected"] == "y") { + $candidate["Elected"] = True; + } + break; + } + } + } + fclose($handle); + } else { + error_log('Error opening candidates elected file'); + exit(1); + } + } else { + error_log("The specified candidates elected file does not exist, will not show any elected candidates for " . $councilData["shortName"] . "."); + } +} + $renderer = new SPLPageRenderer(); $pageContent = $renderer->renderCouncilPage($councilData, $candidateData, $mediaData); if ($pageContent === null) { diff --git a/php-template/template.php b/php-template/template.php index 2713ca7..3d794dc 100644 --- a/php-template/template.php +++ b/php-template/template.php @@ -151,6 +151,12 @@ if (isset($config["survey"])) { -
+
"> + +
ELECTED
+ +