58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
require_once("parse_pledge_data.php");
|
|
require_once("page_renderer.php");
|
|
|
|
$options = getopt("", ["candidates-files:", "default-image:"]);
|
|
|
|
if (isset($options['candidates-files'])) {
|
|
$candidates_files = $options['candidates-files'];
|
|
} else {
|
|
error_log("Error: Missing required option '--candidates-files'.");
|
|
exit(1);
|
|
}
|
|
|
|
if (isset($options['default-image'])) {
|
|
$default_image = $options['default-image'];
|
|
} else {
|
|
error_log("Error: Missing required option '--default-image'.");
|
|
exit(1);
|
|
}
|
|
|
|
$default_image = file_get_contents($default_image);
|
|
|
|
if ($default_image !== FALSE) {
|
|
$default_image = json_decode($default_image, true);
|
|
} else {
|
|
error_log("Error opening config.json.");
|
|
exit(1);
|
|
}
|
|
|
|
$candidate_data = parse_pledge_data(explode(" ", $candidates_files), $default_image);
|
|
|
|
/* 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);
|