Skip to content

Commit

Permalink
Add images to all reps in postcode page
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed May 29, 2024
1 parent 5b6f3fa commit fe6be09
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion www/docs/postcode/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function pick_multiple($pc, $areas, $area_type, $house) {
$mp = $q;
$mp['former'] = ($mp['left_house'] != '9999-12-31');
$q = $db->query("SELECT * FROM personinfo where person_id=:person_id AND data_key='standing_down_2024'", [':person_id' => $mp['person_id']]);
$mp['standing_down_2024'] = $q['data_value'];
$mp['standing_down_2024'] = $q['data_value'] ?? 0;
}

$query_base = "SELECT member.person_id, given_name, family_name, constituency, house
Expand Down
5 changes: 5 additions & 0 deletions www/docs/style/sass/pages/_mp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,9 @@ a[href^="https://www.publicwhip.org"] {
.person-panels .panel ul.rep-actions {
list-style: disc;
margin-left: 1.2em;
}

.postcode-mp-image-wrapper {
display: block;
margin-top: 5px;
}
32 changes: 25 additions & 7 deletions www/includes/easyparliament/templates/html/postcode/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@
<div class="main">
<?php

function image_from_person_id(int $person_id): ?string {
// Use utility method rather than member object to avoid loading full object
// Using the same image and not using the placeholder
[$image, $size] = MySociety\TheyWorkForYou\Utility\Member::findMemberImage($person_id, true, false);
return $size !== null ? $image : null;
}

function member_image_box(string $person_id, string $person_url, string $person_name): void {
// Render a small image box for a person with a link to the person page
// If image_url is null, render nothing
$image_url = image_from_person_id($person_id);
if ($image_url) {
echo '<div class="postcode-mp-image-wrapper">';
echo '<a href="' . $person_url . '"><img src="' . $image_url . '" height=80 width=60 alt="' . $person_name .'"></a>';
echo '</div>';
}
}

include "ge2024.php";

# The below is normally the main column, but for now let us make it the sidebar...

list ($image_url, $size) = MySociety\TheyWorkForYou\Utility\Member::findMemberImage($mp['person_id'], true);

?>

Expand All @@ -21,9 +38,6 @@
<h2><?= gettext('Your representatives') ?></h2>
<ul>
<li>
<?php if ($image_url) { ?>
<img src="<?= $image_url ?>" alt="" align="right">
<?php } ?>
<?php if ($mp['former']) {
printf(gettext('Your former <strong>MP</strong> (Member of Parliament) is <a href="%s">%s</a>, %s'), '/mp/?p=' . $mp['person_id'], $mp['name'], gettext($mp['constituency']));
} else {
Expand All @@ -32,6 +46,7 @@
<?php if ($mp['standing_down_2024']) {
echo 'They are standing down at the general election.';
} ?>
<?php member_image_box($mp["person_id"], '/mp/?p=' . $mp['person_id'], $mp['name']) ?>
</li>

<?php
Expand All @@ -57,6 +72,7 @@
printf(gettext('Your <strong>constituency MS</strong> (Member of the Senedd) was <a href="%s">%s</a>, %s'), $url, $name, $cons);
}
}
member_image_box($mcon["person_id"], $url, $name);
echo '</li>';
}
if (isset($mreg)) {
Expand All @@ -79,9 +95,11 @@
}
echo '<ul>';
foreach ($mreg as $reg) {
echo '<li><a href="' . $urlp . $reg['person_id'] . '">';
echo $reg['given_name'] . ' ' . $reg['family_name'];
echo '</a>';
$url = $urlp . $reg['person_id'];
$name = $reg['given_name'] . ' ' . $reg['family_name'];
echo '<li><a href="' . $url . '">' . $name . '</a>';
member_image_box($reg["person_id"], $url, $name );
echo '</li>';
}
echo '</ul>';
}
Expand Down

0 comments on commit fe6be09

Please sign in to comment.