Skip to content

Commit

Permalink
Fix segment counts
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Jul 14, 2024
1 parent 66f9dea commit 67a7250
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

### Changed

- Improved the number formatting of counts on element index pages.
- Updated the table attributes for all element types.

### Fixed

- Fixed the displayed contact count on segment index pages ([#484](https://github.com/putyourlightson/craft-campaign/issues/484)).
- Fixed the missing draft status icons in sendouts.

## 3.4.0 - 2024-07-04
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function modifyQuery(ElementQueryInterface $query): void
if ($elementId !== null) {
$query->andWhere(['campaignId' => $elementId]);
}

$query->groupBy(['contactId']);
}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/services/SegmentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ public function getContactIds(SegmentElement $segment): array
*/
public function getFilteredContacts(SegmentElement $segment, array $contactIds = null): array
{
$contactElementQuery = $this->getContactElementQuery($contactIds);
$segment->getContactCondition()->modifyQuery($contactElementQuery);

return $contactElementQuery->all();
return $this->getFilteredContactQuery($segment, $contactIds)
->all();
}

/**
Expand All @@ -104,20 +102,20 @@ public function getFilteredContacts(SegmentElement $segment, array $contactIds =
*/
public function getFilteredContactIds(SegmentElement $segment, array $contactIds = null): array
{
$contactElementQuery = $this->getContactElementQuery($contactIds);
$segment->getContactCondition()->modifyQuery($contactElementQuery);

return $contactElementQuery->ids();
return $this->getFilteredContactQuery($segment, $contactIds)
->ids();
}

private function getContactElementQuery(array $contactIds = null): ContactElementQuery
private function getFilteredContactQuery(SegmentElement $segment, array $contactIds = null): ContactElementQuery
{
$contactQuery = ContactElement::find();

if ($contactIds !== null) {
$contactQuery->id($contactIds);
}

$segment->getContactCondition()->modifyQuery($contactQuery);

return $contactQuery;
}
}

0 comments on commit 67a7250

Please sign in to comment.