Skip to content

Commit

Permalink
fixup! Show number of agreements in top level summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Mar 25, 2024
1 parent 9e86d80 commit b314bf4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions classes/Divisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ public function getMemberDivisionDetails($strong_only = false) {
$args
);

$allowed_policies = (new \MySociety\TheyWorkForYou\Policies())->getPolicyIDs();
$policies_list = new \MySociety\TheyWorkForYou\Policies();
$allowed_policies = $policies_list->getPolicyIDs();

foreach ($q as $row) {
$policy_id = $row['policy_id'];
Expand Down Expand Up @@ -306,8 +307,8 @@ public function getMemberDivisionDetails($strong_only = false) {
}

// for each key in $policy_divisions, we want to add agreement information
foreach ($policy_divisions as $policy_id => $summary) {
$agreement_details = $this->member->member_agreements($policy_id);
foreach ($policy_divisions as $policy_id => &$summary) {
$agreement_details = $this->member->member_agreements($policy_id, HOUSE_TYPE_COMMONS, $policies_list );
$summary["agreements_for"] = 0;
$summary["agreements_against"] = 0;
foreach ($agreement_details as $agreement){
Expand All @@ -320,7 +321,6 @@ public function getMemberDivisionDetails($strong_only = false) {
$summary["agreements_against"] += 1;
}
}
$policy_divisions[$policy_id] = $summary;
}
return $policy_divisions;
}
Expand Down
18 changes: 12 additions & 6 deletions www/includes/easyparliament/member.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

include_once INCLUDESPATH."easyparliament/glossary.php";

use MySociety\TheyWorkForYou\Policies as Policies;


class MEMBER {

public $valid = false;
Expand Down Expand Up @@ -242,13 +245,16 @@ public function date_in_memberships($house, $date){
return false;
}

public function member_agreements($policyID, $house = HOUSE_TYPE_COMMONS){
// agreements that a member has been present for on a specific policy
$policiesList = new MySociety\TheyWorkForYou\Policies($policyID);
public function member_agreements(int $policyID, int $house = HOUSE_TYPE_COMMONS, Policies $policiesList = null) {
// agreements that a member has been present for on a specific policy.
// Pass in a Policies object to avoid reloading the list of policies.
// Ideally one that has been initalised without a specific policy id.
if (!$policiesList) {
$policiesList = new Policies($policyID);
}
$rel_agreements = $policiesList->all_policy_agreements[$policyID] ?? [];
$MEMBER = $this;
$rel_agreements = array_filter($rel_agreements, function($agreement) use ($MEMBER, $house) {
return $MEMBER->date_in_memberships($house, $agreement['date']);
$rel_agreements = array_filter($rel_agreements, function($agreement) use ($house) {
return $this->date_in_memberships($house, $agreement['date']);
});
return $rel_agreements;
}
Expand Down

0 comments on commit b314bf4

Please sign in to comment.