Files
spl-tools/pledge-update/pledge-page.php
2024-09-21 16:53:24 +10:00

42 lines
963 B
PHP

<?php
require_once("parse_pledge_data.php");
require_once("page_renderer.php");
$options = getopt("", ["candidates-files:"]);
if (isset($options['candidates-files'])) {
$candidates_files = $options['candidates-files'];
} else {
error_log("Error: Missing required option '--candidates-files'.");
exit(1);
}
$candidate_data = parse_pledge_data(explode(" ", $candidates_files));
/* Select people who have taken the pledge */
$pledgeCandidates = array_filter($candidate_data, function ($candidate) {
return $candidate['Pledge'] === 'y';
});
$renderer = new SPLPageRenderer();
//print_r($pledgeCandidates);
$councils = [];
foreach ($pledgeCandidates as $key => $candidate) {
$councils[] = $candidate['Council'];
}
$councils = array_unique($councils);
asort($councils);
//print_r($councils);
$pageContent = $renderer->renderPledgePage($councils, $pledgeCandidates);
if ($pageContent === null) {
exit(2);
}
echo $pageContent;
exit(0);