Skip to content

Commit

Permalink
explicitly fetch communal data for communal votations
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalvb committed Feb 3, 2025
1 parent d4c1e81 commit 0d3cab7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Service/PolisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ public function __construct(
) {
}

public function fetchPolisCaseByVotationId(int $id, string $language): PolisCase
public function fetchPolisCaseByVotationId(int $id, string $language, bool $fetchCommunalResultData = false): PolisCase
{
$votationResponse = $this->client->request('GET', sprintf('/polis-api/v2/votations/%s?lang=%s', $id, $language));
// by default, Polis only delivers results for locations types 1 - 3 (national, cantonal and district)
$locationTypeIds = '1,2,3';
// if we need communal data (which we only do for communal votations), we need to explicitly request them
if ($fetchCommunalResultData) {
$locationTypeIds = '4';
}

$votationResponse = $this->client->request('GET', sprintf('/polis-api/v2/votations/%s?lang=%s&locationtypeid=%s', $id, $language, $locationTypeIds));
$data = $votationResponse->toArray();

$case = [];
Expand All @@ -35,6 +42,11 @@ public function fetchPolisCaseByVotationId(int $id, string $language): PolisCase
$case = $item;
} elseif ('tpc.eMedia.PolisV2.Business.API.v1.Models.Export.Votation, tpc.eMedia.PolisV2.Business' === $item['__type']) {
$item['VotationCantonalResults'] = [];
$location = PolisVoteLocation::createFromArray($item['VotationLocation']);
// if this is a communal votation, we need to explicitly fetch communal result data (that gets ignored by default)
if ($location->type->id === 4 && $fetchCommunalResultData === false) {
return $this->fetchPolisCaseByVotationId($id, $language, true);
}

$cantonalMajority = [
'yes' => 0,
Expand Down

0 comments on commit 0d3cab7

Please sign in to comment.