From 024db95f570efa68dc839e4571091aecaa0e348d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 19 Dec 2023 18:03:48 +0000 Subject: [PATCH] Move votes section from profile to votes page. --- classes/Member.php | 6 +- tests/PartyTest.php | 44 ++---- www/docs/mp/index.php | 13 +- .../templates/html/mp/profile.php | 138 ------------------ .../templates/html/mp/votes.php | 55 ++++++- 5 files changed, 76 insertions(+), 180 deletions(-) diff --git a/classes/Member.php b/classes/Member.php index e0d75c6b43..eed74a4d4f 100644 --- a/classes/Member.php +++ b/classes/Member.php @@ -472,7 +472,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); @@ -495,10 +495,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 b25fe94a07..cf78eb19d6 100644 --- a/tests/PartyTest.php +++ b/tests/PartyTest.php @@ -364,7 +364,6 @@ private function getMemberFromPersonId($person_id) } } - public function testMPPartyPolicyTextWhenDiffers() { // Checks that an MP that differs from party gets the 'sometimes differs from their party' on the profile page @@ -372,7 +371,15 @@ public function testMPPartyPolicyTextWhenDiffers() MySociety\TheyWorkForYou\PartyCohort::calculatePositions(); $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); } @@ -386,38 +393,13 @@ public function testSingleMemberPartyPolicyText() $this->assertStringNotContainsString('is a B Party MP', $page); } - public function testMPPartyPolicyWherePartyMissingPositions() - { - // When an MP has votes, but there is no broader party policy to compare it to - // this goes down a funnel that shows the votes, but does not make the comparison to party. - MySociety\TheyWorkForYou\PartyCohort::populateCohorts(); - MySociety\TheyWorkForYou\PartyCohort::calculatePositions(); - $page = $this->fetch_page(array('pid' => 4, 'url' => '/mp/4/test_mp_d/test_westminster_constituency')); - $this->assertStringContainsString('Test MP D', $page); - $this->assertStringContainsString('This is a random selection of Mrs Test MP D’s votes', $page); - $this->assertStringContainsString('
  • assertStringNotContainsString('comparable B Party MPs voted', $page); - } - - public function testMPPartyPolicyTextWhenAgrees() + public function testCrossPartyDisclaimer() { - // Test when an MP mostly agrees with their party, as MP G Party 2 does with party G + // Test if the cross party disclaimer is there MySociety\TheyWorkForYou\PartyCohort::populateCohorts(); MySociety\TheyWorkForYou\PartyCohort::calculatePositions(); - $page = $this->fetch_page(array('pid' => 16, 'url' => '/mp/16/test_mp_g_party_2/test_westminster_constituency')); - $this->assertStringContainsString('Test MP G Party 2', $page); - - $this->assertStringContainsString('This is a random selection of Mrs Test MP G Party 2’s votes', $page); + $page = $this->fetch_page(array('pagetype' => 'votes', 'pid' => 7, 'url' => '/mp/7/test_mp_g/test_westminster_constituency/votes')); + $this->assertStringContainsString('Test MP G', $page); + $this->assertStringContainsString('In the votes below they are compared to their original party', $page); } - - -public function testCrossPartyDisclaimer() -{ - // Test if the cross party disclaimer is there - MySociety\TheyWorkForYou\PartyCohort::populateCohorts(); - MySociety\TheyWorkForYou\PartyCohort::calculatePositions(); - $page = $this->fetch_page(array('pagetype' => 'votes', 'pid' => 7, 'url' => '/mp/7/test_mp_g/test_westminster_constituency/votes')); - $this->assertStringContainsString('Test MP G', $page); - $this->assertStringContainsString('In the votes below they are compared to their original party', $page); -} } diff --git a/www/docs/mp/index.php b/www/docs/mp/index.php index 3056ab2489..05f655cdb0 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); @@ -471,8 +476,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); @@ -1150,7 +1153,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); @@ -1166,6 +1169,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 ?>