From f0c6737fd8091be00c4656f5af6aa26bccb6df61 Mon Sep 17 00:00:00 2001 From: Alex Parsons Date: Fri, 23 Feb 2024 12:01:39 +0000 Subject: [PATCH] Move votes section from profile to votes page. --------- Co-authored-by: M Somerville --- classes/Member.php | 6 +- tests/PartyTest.php | 9 +- www/docs/mp/index.php | 13 +- .../templates/html/mp/profile.php | 138 ------------------ .../templates/html/mp/votes.php | 55 ++++++- 5 files changed, 71 insertions(+), 150 deletions(-) diff --git a/classes/Member.php b/classes/Member.php index 25f7261449..deadb7631c 100644 --- a/classes/Member.php +++ b/classes/Member.php @@ -459,7 +459,7 @@ private function left_house_line($house, $house_name) { } } - public function getPartyPolicyDiffs($partyCohort, $policiesList, $positions, $only_diffs = false) { + public function getPartyPolicyDiffs($partyCohort, $policiesList, $positions) { $policy_diffs = array(); $party_positions = $partyCohort->getAllPolicyPositions($policiesList); @@ -482,10 +482,6 @@ public function getPartyPolicyDiffs($partyCohort, $policiesList, $positions, $on $score_diff = $this->calculatePolicyDiffScore($mp_score, $party_score); - // skip anything that isn't a yes vs no diff - if ( $only_diffs && $score_diff < 2 ) { - continue; - } $policy_diffs[$policy_id] = [ 'policy_text' => $details['policy'], 'score_difference' => $score_diff, diff --git a/tests/PartyTest.php b/tests/PartyTest.php index f018e951f9..17116a068a 100644 --- a/tests/PartyTest.php +++ b/tests/PartyTest.php @@ -252,13 +252,20 @@ private function getMemberFromPersonId($person_id) return new MySociety\TheyWorkForYou\Member([ "person_id" => $person_id ]); } - public function testMPPartyPolicyTextWhenDiffers() { // Checks that an MP that differs from party gets the 'sometimes differs from their party' on the profile page $page = $this->fetch_page(array('pid' => 15, 'url' => '/mp/15/test_mp_g_party_1/test_westminster_constituency')); $this->assertStringContainsString('Test MP G Party 1', $page); + } + + public function testMPPartyPolicyTextWhenDiffersVotes() + { + MySociety\TheyWorkForYou\PartyCohort::populateCohorts(); + MySociety\TheyWorkForYou\PartyCohort::calculatePositions(); + $page = $this->fetch_page(array('pagetype' => 'votes', 'pid' => 15, 'url' => '/mp/15/test_mp_g_party_1/test_westminster_constituency/votes')); $this->assertStringContainsString('is a G Party MP', $page); + $this->assertStringContainsString('Test MP G Party 1', $page); $this->assertStringContainsString('sometimes differs from their party', $page); } diff --git a/www/docs/mp/index.php b/www/docs/mp/index.php index 751215e2bf..cfe6618a49 100644 --- a/www/docs/mp/index.php +++ b/www/docs/mp/index.php @@ -416,7 +416,12 @@ ); } - person_party_policy_diffs($MEMBER, $policiesList, false); + person_party_policy_diffs($MEMBER, $policiesList); + + $data['sorted_diffs_only'] = array_filter( + $data['sorted_diffs'], + function($k) { return $k['score_difference'] >= 2; } + ); // Send the output for rendering MySociety\TheyWorkForYou\Renderer::output('mp/votes', $data); @@ -483,8 +488,6 @@ // Generate limited voting record list $data['policyPositions'] = new MySociety\TheyWorkForYou\PolicyPositions($policies, $MEMBER, $policyOptions); - person_party_policy_diffs($MEMBER, $policiesList, true); - // Send the output for rendering MySociety\TheyWorkForYou\Renderer::output('mp/profile', $data); @@ -1162,7 +1165,7 @@ function policy_image($data, $MEMBER, $format) { } // generate party policy diffs -function person_party_policy_diffs($MEMBER, $policiesList, $only_diffs) { +function person_party_policy_diffs($MEMBER, $policiesList) { global $data; $divisions = new MySociety\TheyWorkForYou\Divisions($MEMBER); @@ -1178,6 +1181,6 @@ function person_party_policy_diffs($MEMBER, $policiesList, $only_diffs) { $positions = new MySociety\TheyWorkForYou\PolicyPositions( $policiesList, $MEMBER, [ 'summaries' => $policySummaries, ]); - $policy_diffs = $MEMBER->getPartyPolicyDiffs($partyCohort, $policiesList, $positions, $only_diffs); + $policy_diffs = $MEMBER->getPartyPolicyDiffs($partyCohort, $policiesList, $positions); $data['sorted_diffs'] = $policy_diffs; } diff --git a/www/includes/easyparliament/templates/html/mp/profile.php b/www/includes/easyparliament/templates/html/mp/profile.php index a134e2a9bc..adcdf15056 100644 --- a/www/includes/easyparliament/templates/html/mp/profile.php +++ b/www/includes/easyparliament/templates/html/mp/profile.php @@ -5,10 +5,6 @@ // it'll display a banner with the MPs stats, assuming we have them for the // year $display_wtt_stats_banner = '2015'; - -# fetch covid_policy_list -$policies_obj = new MySociety\TheyWorkForYou\Policies(); -$covid_policy_list = $policies_obj->getCovidAffected(); ?>
@@ -29,9 +25,6 @@

    - positions) > 0): ?> -
  • -
  • @@ -69,137 +62,6 @@
- - positions) > 0) { ?> -
- -

A selection of ’s votes

- -

See full list of topics voted on

- -
    - positions as $key_vote) { - $policy_id = $key_vote['policy_id']; - $covid_affected = in_array($policy_id, $covid_policy_list); - $description = ucfirst($key_vote['desc']); - $link = sprintf( - '%s/divisions?policy=%s', - $member_url, - $key_vote['policy_id'] - ); - $link_text = ($key_vote['position'] != 'has never voted on') ? 'Show votes' : 'Details'; - - include '_vote_description.php'; - - } ?> -
- -

We have lots more plain English analysis of ’s voting record on issues like health, welfare, taxation and more. Visit ’s full vote analysis page for more.

- -
- - positions) > 0 || count($sorted_diffs) > 0): ?> -
- -

’s voting in Parliament

- - 0 && $party_member_count > 1): ?> - -

- is a MP, and on the vast majority of issues votes the same way as other MPs. -

- -

- However, sometimes differs from their party colleagues, such as: -

- -
    - $diff) { - - $key_vote = $diff; - $covid_affected = in_array($policy_id, $covid_policy_list); - $policy_desc = strip_tags($key_vote['policy_text']); - $policy_direction = $key_vote["person_position"]; - $policy_group = "highlighted"; - $party_score_difference = $key_vote["score_difference"]; - $party_position = $key_vote['party_position'] ; - $comparison_party = $data["comparison_party"]; - $current_party_comparison = $data["current_party_comparison"]; - $party_voting_line = sprintf("%s, %s", $party, $diff['party_voting_summary']); - $description = sprintf( - '%s %s %s; comparable %s MPs %s.', - $full_name, - $diff['person_position'], - strip_tags($diff['policy_text']), - $comparison_party, - $diff['party_position'] - ); - $link = $member_url . '/divisions?policy=' . $policy_id; - $link_text = 'Show votes'; - - include '_vote_description.php'; - - } ?> -
- -

We have lots more plain English analysis of ’s voting record on issues like health, welfare, taxation and more. Visit ’s full vote analysis page for more.

- - positions) > 0 ): ?> - 1) { ?> - $comparison_party){ ?> -

- is a MP, but has changed parties or become independent. -

-

- Compared to their original party (), for the vast majority of issues they have voted in the same way as other MPs. -

- - -

- is a MP, and on the vast majority of issues votes the same way as other MPs. -

- - - - -

- This is a random selection of ’s votes. -

- -
    - positions as $key_vote) { - - $policy_id = $key_vote['policy_id']; - $covid_affected = in_array($policy_id, $covid_policy_list); $description = ucfirst($key_vote['desc']); - $link = sprintf( - '%s/divisions?policy=%s', - $member_url, - $key_vote['policy_id'] - ); - $link_text = $key_vote['position'] != 'has never voted on' ? 'Show votes' : 'Details'; - - include '_vote_description.php'; - - } ?> -
- -

- Last updated: . - Learn more about our voting records and what they mean. -

- -

We have lots more plain English analysis of ’s voting record on issues like health, welfare, taxation and more. Visit ’s full vote analysis page for more.

- positions) == 0 ): ?> - -

No votes to display.

- - - -

- -
- -
diff --git a/www/includes/easyparliament/templates/html/mp/votes.php b/www/includes/easyparliament/templates/html/mp/votes.php index 57b4a7c322..b21318993c 100644 --- a/www/includes/easyparliament/templates/html/mp/votes.php +++ b/www/includes/easyparliament/templates/html/mp/votes.php @@ -1,5 +1,9 @@ getCovidAffected(); ?>
@@ -56,6 +60,55 @@
+ 0 && $party_member_count > 1) { ?> +
+ +

’s voting in Parliament

+ +

+ is a MP, and on the vast majority of issues votes the same way as other MPs. +

+ +

+ However, sometimes differs from their party colleagues, such as: +

+ +
    + $diff) { + + $key_vote = $diff; + $covid_affected = in_array($policy_id, $covid_policy_list); + $policy_desc = strip_tags($key_vote['policy_text']); + $policy_direction = $key_vote["person_position"]; + $policy_group = "highlighted"; + $party_score_difference = $key_vote["score_difference"]; + $party_position = $key_vote['party_position'] ; + $comparison_party = $data["comparison_party"]; + $current_party_comparison = $data["current_party_comparison"]; + $party_voting_line = sprintf("%s, %s", $party, $diff['party_voting_summary']); + $description = sprintf( + '%s %s %s; comparable %s MPs %s.', + $full_name, + $diff['person_position'], + strip_tags($diff['policy_text']), + $comparison_party, + $diff['party_position'] + ); + $link = $member_url . '/divisions?policy=' . $policy_id; + $link_text = 'Show votes'; + + include '_vote_description.php'; + + } ?> +
+ + +

+ + +
+ + @@ -146,7 +199,7 @@ - moreLinksString)): ?> + moreLinksString): ?>

moreLinksString ?>