Update template to support elected candidate data
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?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'])) {
|
||||
$councilFileContents = file_get_contents($options['council-file']);
|
||||
@@ -55,6 +55,37 @@ if (isset($options['media-file'])) {
|
||||
|
||||
$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();
|
||||
$pageContent = $renderer->renderCouncilPage($councilData, $candidateData, $mediaData);
|
||||
if ($pageContent === null) {
|
||||
|
||||
Reference in New Issue
Block a user