Skip to content

Commit

Permalink
Display agreements in detailed policy page
Browse files Browse the repository at this point in the history
- Uses date range to only show relevant agreements for an MP
  • Loading branch information
ajparsons committed Feb 6, 2024
1 parent 46f944f commit 216a8e5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
14 changes: 13 additions & 1 deletion www/docs/mp/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,22 @@

if ( $policyID ) {
$data['policydivisions'] = $divisions->getMemberDivisionsForPolicy($policyID);
$rel_agreements = $policiesList->all_policy_agreements[$policyID];
// filter down to where 'date' is within the member's term
// This won't be perfect where the member has been in and out of the house
// But it doesn't affect their score.
$rel_agreements = array_filter($rel_agreements, function($agreement) use ($MEMBER) {
return $MEMBER->date_in_memberships(HOUSE_TYPE_COMMONS, $agreement['date']);
});
$data['policyagreements'] = array($policyID => $rel_agreements);
} else {
$data['policydivisions'] = $divisions->getAllMemberDivisionsByPolicy();
$data['policyagreements'] = $policiesList->all_policy_agreements;
}




// Send the output for rendering
MySociety\TheyWorkForYou\Renderer::output('mp/divisions', $data);

Expand Down Expand Up @@ -1157,7 +1169,7 @@ function person_party_policy_diffs($MEMBER, $policiesList, $only_diffs) {
$policySummaries = $divisions->getMemberDivisionDetails();

$party = new MySociety\TheyWorkForYou\Party($MEMBER->party());
$partyCohort = new MySociety\TheyWorkForYou\PartyCohort($MEMBER->cohortKey());
$partyCohort = new MySociety\TheyWorkForYou\PartyCohort($MEMBER->person_id(), $MEMBER->cohortParty());
$data['party_positions'] = $partyCohort->getAllPolicyPositions($policiesList);
# house hard coded as this is only used for the party position
# comparison which is Commons only
Expand Down
14 changes: 14 additions & 0 deletions www/includes/easyparliament/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MEMBER {
public $party;
public $other_parties = array();
public $other_constituencies;
public $memberships = array();
public $houses = array();
public $entered_house = array();
public $left_house = array();
Expand Down Expand Up @@ -165,6 +166,8 @@ public function __construct($args) {
if (!in_array($house, $this->houses)) {
$this->houses[] = $house;
}
# add the entire row into the memberships array
$this->memberships[] = $row;
$const = $row['constituency'] ? gettext($row['constituency']) : '';
$party = $row['party'] ? gettext($row['party']) : '';
$entered_house = $row['entered_house'];
Expand Down Expand Up @@ -227,6 +230,17 @@ public function __construct($args) {
$this->set_users_mp();
}

public function date_in_memberships($house, $date){
// Given a date, see if they had any memberships during that time
foreach ($this->memberships as $membership) {
if ($membership['entered_house'] <= $date && $membership['left_house'] >= $date) {
if ($membership['house'] == $house) {
return true;
} }
}
return false;
}

public function member_id_to_person_id($member_id) {
$q = $this->db->query("SELECT person_id FROM member
WHERE member_id = :member_id",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<li id="<?= $agreement['gid'] ?>">
<span class="policy-vote__date">On <?= strftime('%e %b %Y', strtotime($agreement['date'])) ?>:</span>
<span class="policy-vote__text"><?= $division['division_name'] ?></span>

<a class="vote-description__source" href="<?= $division['url'] ?>">Show Decision</a>

</li>
49 changes: 48 additions & 1 deletion www/includes/easyparliament/templates/html/mp/divisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<h3 class="browse-content"><?= gettext('Browse content') ?></h3>
<ul>
<li><a href="#scoring">Major votes</a></li>
<li><a href="#scoring-agreements">Major agreements</a></li>
<li><a href="#informative">Minor votes</a></li>
<li><a href="#informative-agreements">Minor agreements</a></li>
<li><a href="<?= $member_url ?>/votes">Back to all topics</a></li>
</ul>
<?php include '_featured_content.php'; ?>
Expand All @@ -50,17 +52,29 @@
# does all divisions, but generally this is an array of one
# (the current policy)
foreach ($policydivisions as $policy) { ?>

<?php
$current_policy_agreements = $policyagreements[$policy['policy_id']];
$divisions_scoring = [];
$divisions_informative = [];
$agreements_scoring = [];
$agreements_informative = [];
foreach ($policy['divisions'] as $division) {
if ($division['strong']) {
$divisions_scoring[] = $division;
} else {
$divisions_informative[] = $division;
}
}

foreach ($current_policy_agreements as $agreement) {
if ($agreement['strength'] == 'strong') {
$agreements_scoring[] = $agreement;
} else {
$agreements_informative[] = $agreement;
}
}

?>

<?php
Expand Down Expand Up @@ -119,9 +133,27 @@
} ?>
</ul>
<?php } ?>

<a name="scoring-agreements"></a>
<h3 class="policy-votes-list-header">Scoring Agreements</h3>
<p>Agreements are when Parliament takes a decision without holding a vote.</p>
<p>This does not necessarily mean universal approval, but does mean there were no objections made to the decision being made</p>

<?php if ($agreements_scoring) { ?>
<p>The following agreements were made while this member was elected:</p>
<ul class="vote-descriptions policy-votes">
<?php foreach ($agreements_scoring as $division) {
include('_agreement_description.php');
$displayed_votes = true;
} ?>
</ul>
<?php } else { ?>
<p>No scoring agreements are part of this policy while this member was elected.</p>
<?php } ?>
<?php if ($divisions_informative) { ?>
<a name="informative"></a>
<h3 class="policy-votes-list-header">Minor votes</h3>

<ul class="vote-descriptions policy-votes">
<?php foreach ($divisions_informative as $division) {
include('_division_description.php');
Expand All @@ -130,6 +162,21 @@
</ul>
<?php } ?>

<a name="informative-agreements"></a>
<h3 class="policy-votes-list-header">Informative Agreements</h3>
<p>Agreements are when Parliament takes a decision without holding a vote.</p>
<p>This may or may not mean universal approval, but does mean there were no objections made to the decision being made.</p>

<?php if ($agreements_informative) { ?>
<ul class="vote-descriptions policy-votes">
<?php foreach ($agreements_informative as $division) {
include('_agreement_description.php');
$displayed_votes = true;
} ?>
</ul>
<?php } else { ?>
<p>No informative agreements are part of this policy while this member was elected.</p>
<?php } ?>
<div class="policy-votes-list-footer">
<p class="voting-information-provenance">
Vote information from <a href="https://www.publicwhip.org.uk/mp.php?mpid=<?= $member_id ?>&amp;dmp=<?= $policy['policy_id'] ?>">PublicWhip</a>.
Expand Down

0 comments on commit 216a8e5

Please sign in to comment.