Update template to support elected candidate data
This commit is contained in:
@@ -38,7 +38,13 @@ function create_or_update_page() {
|
|||||||
candidates_file="$DATA_PATH"/$slug/candidates-generic.csv
|
candidates_file="$DATA_PATH"/$slug/candidates-generic.csv
|
||||||
fi
|
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
|
if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
|
|||||||
2
php-template/example-candidates-elected.csv
Normal file
2
php-template/example-candidates-elected.csv
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Ward,Candidate Name,Elected
|
||||||
|
Harvester,Joe Blogs,y
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "page_renderer.php";
|
require_once "page_renderer.php";
|
||||||
|
|
||||||
$options = getopt("", ["council-file:", "candidates-file:", "media-file:"]);
|
$options = getopt("", ["council-file:", "candidates-file:", "media-file:", "candidates-elected-file:"]);
|
||||||
|
|
||||||
if (isset($options['council-file'])) {
|
if (isset($options['council-file'])) {
|
||||||
$councilFileContents = file_get_contents($options['council-file']);
|
$councilFileContents = file_get_contents($options['council-file']);
|
||||||
@@ -55,6 +55,37 @@ if (isset($options['media-file'])) {
|
|||||||
|
|
||||||
$mediaData = json_decode($mediaFileContents, true);
|
$mediaData = json_decode($mediaFileContents, true);
|
||||||
|
|
||||||
|
// Merge elected data (if present) into candidate objects
|
||||||
|
if (isset($options['candidates-elected-file'])) {
|
||||||
|
$candidatesElectedFile = $options['candidates-elected-file'];
|
||||||
|
|
||||||
|
if (file_exists($candidatesElectedFile)) {
|
||||||
|
if (($handle = fopen($candidatesElectedFile, "r")) !== FALSE) {
|
||||||
|
$headers = fgetcsv($handle);
|
||||||
|
while (($data = fgetcsv($handle)) !== FALSE) {
|
||||||
|
$electedCandidate = [];
|
||||||
|
foreach ($headers as $key => $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();
|
$renderer = new SPLPageRenderer();
|
||||||
$pageContent = $renderer->renderCouncilPage($councilData, $candidateData, $mediaData);
|
$pageContent = $renderer->renderCouncilPage($councilData, $candidateData, $mediaData);
|
||||||
if ($pageContent === null) {
|
if ($pageContent === null) {
|
||||||
|
|||||||
@@ -151,6 +151,12 @@ if (isset($config["survey"])) {
|
|||||||
<?php
|
<?php
|
||||||
$candidate = $chunk[$columnIdx];
|
$candidate = $chunk[$columnIdx];
|
||||||
|
|
||||||
|
if (isset($candidate["Elected"]) && $candidate["Elected"]) {
|
||||||
|
$candidate_elected = true;
|
||||||
|
} else {
|
||||||
|
$candidate_elected = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($candidate['Picture']) && isset($media[$candidate['Picture']])) {
|
if (isset($candidate['Picture']) && isset($media[$candidate['Picture']])) {
|
||||||
$candidate_image = $media[$candidate['Picture']];
|
$candidate_image = $media[$candidate['Picture']];
|
||||||
} else {
|
} else {
|
||||||
@@ -170,7 +176,11 @@ if (isset($config["survey"])) {
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- wp:image {"id":<?php echo $candidate_image['id']; ?>,"width":"200px","height":"200px","scale":"cover","align":"center","style":{"color":{}},"className":"is-resized"} -->
|
<!-- wp:image {"id":<?php echo $candidate_image['id']; ?>,"width":"200px","height":"200px","scale":"cover","align":"center","style":{"color":{}},"className":"is-resized"} -->
|
||||||
<figure class="wp-block-image aligncenter is-resized"><img src="<?php echo $candidate_image['url']; ?>" alt="" class="wp-image-<?php echo $candidate_image['id']; ?>" style="object-fit:cover;width:200px;height:200px"/></figure>
|
<figure class="wp-block-image aligncenter is-resized <?php if ($candidate_elected) { echo "elected-candidate"; } ?>"><img src="<?php echo $candidate_image['url']; ?>" alt="" class="wp-image-<?php echo $candidate_image['id']; ?>" style="object-fit:cover;width:200px;height:200px;"/>
|
||||||
|
<?php if ($candidate_elected): ?>
|
||||||
|
<figcaption>ELECTED</figcaption>
|
||||||
|
<?php endif; ?>
|
||||||
|
</figure>
|
||||||
<!-- /wp:image -->
|
<!-- /wp:image -->
|
||||||
|
|
||||||
<!-- wp:heading {"textAlign":"center","className":"wp-block-heading has-text-align-center has-medium-font-size","style":{"spacing":{"margin":{"top":"1rem","bottom":"0.5rem"}}}} -->
|
<!-- wp:heading {"textAlign":"center","className":"wp-block-heading has-text-align-center has-medium-font-size","style":{"spacing":{"margin":{"top":"1rem","bottom":"0.5rem"}}}} -->
|
||||||
|
|||||||
Reference in New Issue
Block a user