Update pledge page template to show elected candidates.
This commit is contained in:
@@ -9,6 +9,7 @@ function parse_pledge_data($candidates_files, $default_image) {
|
||||
foreach ($candidates_files as $key => $file) {
|
||||
$config_file = dirname($file)."/config.json";
|
||||
$config_string = file_get_contents($config_file);
|
||||
$elected_file = dirname($file)."/candidates-elected.csv";
|
||||
|
||||
if ($config_string !== FALSE) {
|
||||
$config = json_decode($config_string, true);
|
||||
@@ -17,6 +18,24 @@ function parse_pledge_data($candidates_files, $default_image) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$elected_data = [];
|
||||
if (file_exists($elected_file)) {
|
||||
if (($elected_handle = fopen($elected_file, "r")) !== FALSE) {
|
||||
$headers = fgetcsv($elected_handle);
|
||||
while (($data = fgetcsv($elected_handle)) !== FALSE) {
|
||||
$candidate = [];
|
||||
foreach ($headers as $key => $value) {
|
||||
$candidate[$value] = $data[$key];
|
||||
}
|
||||
$name_slug = trim_sluggify($candidate['Candidate Name']);
|
||||
$elected_data[$name_slug] = $candidate;
|
||||
}
|
||||
} else {
|
||||
error_log('Error opening candidates file');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (($handle = fopen($file, "r")) !== FALSE) {
|
||||
$headers = fgetcsv($handle);
|
||||
while (($data = fgetcsv($handle)) !== FALSE) {
|
||||
@@ -39,6 +58,9 @@ function parse_pledge_data($candidates_files, $default_image) {
|
||||
$candidate['Pledge'] = 'y';
|
||||
}
|
||||
}
|
||||
if (!empty($elected_data) && array_key_exists($name_slug, $elected_data)) {
|
||||
$candidate['Elected'] = $elected_data[$name_slug]['Elected'];
|
||||
}
|
||||
$candidate['Council'] = $config['councilName'];
|
||||
$candidate['Path'] = dirname($file);
|
||||
$media_desc = $candidate['Path']."/".
|
||||
|
||||
@@ -97,6 +97,12 @@ $councilCount = count($councils);
|
||||
<?php
|
||||
$candidate = $chunk[$columnIdx];
|
||||
|
||||
if (isset($candidate['Elected']) && $candidate['Elected'] === 'y') {
|
||||
$candidate_elected = true;
|
||||
} else {
|
||||
$candidate_elected = false;
|
||||
}
|
||||
|
||||
if (isset($candidate['Picture']) && strlen($candidate['image_url'])) {
|
||||
$candidate_image['url'] = $candidate['image_url'];
|
||||
$candidate_image['id'] = $candidate['image_id'];
|
||||
@@ -107,7 +113,11 @@ $councilCount = count($councils);
|
||||
?>
|
||||
|
||||
<!-- 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: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