diff --git a/html/modules/custom/ghi_blocks/src/Plugin/Block/GlobalPage/KeyFigures.php b/html/modules/custom/ghi_blocks/src/Plugin/Block/GlobalPage/KeyFigures.php index 2b20c24a6..c832741a4 100644 --- a/html/modules/custom/ghi_blocks/src/Plugin/Block/GlobalPage/KeyFigures.php +++ b/html/modules/custom/ghi_blocks/src/Plugin/Block/GlobalPage/KeyFigures.php @@ -63,6 +63,7 @@ public function getData(string $source_key = 'data') { 'expectedReach' => 'Expected reach', ]; $caseload_values = $this->getPlanQuery()->getCaseloadTotalValues($types); + $affected_countries = $this->getPlanQuery()->getNumerOfGhoCountries(); return [ 'total_funding' => $funding, 'total_requirements' => $requirements, @@ -72,6 +73,7 @@ public function getData(string $source_key = 'data') { 'people_reached' => $caseload_values['reached'], 'people_reached_percent' => CommonHelper::calculateRatio($caseload_values['reached_custom'], $caseload_values['target_custom']), 'people_expected_reach' => $caseload_values['expectedReach'], + 'countries_affected' => $affected_countries, ]; } diff --git a/html/modules/custom/ghi_plans/src/Plugin/EndpointQuery/PlanOverviewQuery.php b/html/modules/custom/ghi_plans/src/Plugin/EndpointQuery/PlanOverviewQuery.php index 204aa3d83..f5c64ab8a 100644 --- a/html/modules/custom/ghi_plans/src/Plugin/EndpointQuery/PlanOverviewQuery.php +++ b/html/modules/custom/ghi_plans/src/Plugin/EndpointQuery/PlanOverviewQuery.php @@ -100,6 +100,44 @@ public function getPlans($filter = TRUE) { return $this->plans; } + /** + * Get the caseload total values for the supplied types. + * + * @return int + * The number of unique countries of all GHO plans. + */ + public function getNumerOfGhoCountries() { + // Get the plans, but make sure they are not filtered for visibility. The + // number of affected countries will appear only in the key figures + // element, where we want the number of countries for all GHO plans + // independently of whether specific plans are hidden from global pages or + // not. + $plans = $this->getPlans(FALSE); + if (empty($plans)) { + return 0; + } + + $countries = []; + foreach ($plans as $plan) { + // Only include plans with isPartOfGho=true. + if (!$plan->isPartOfGho()) { + continue; + } + $plan_countries = $plan->getCountries(); + if (empty($plan_countries)) { + continue; + } + foreach ($plan_countries as $plan_country) { + if (array_key_exists($plan_country->id(), $countries)) { + continue; + } + $countries[$plan_country->id()] = $plan_country; + } + } + + return count($countries); + } + /** * Get the caseload total values for the supplied types. *