| 1 |
<?php |
| 2 |
|
| 3 |
namespace Pushly\Models; |
| 4 |
|
| 5 |
class NotificationAudience implements \JsonSerializable { |
| 6 |
public ?bool $all_subscribers = null; |
| 7 |
public ?array $segment_ids = null; |
| 8 |
public ?array $excluded_segment_ids = null; |
| 9 |
|
| 10 |
#[\ReturnTypeWillChange] |
| 11 |
public function jsonSerialize(): array { |
| 12 |
$audience = $this->all_subscribers |
| 13 |
? [ 'all_subscribers' => $this->all_subscribers ] |
| 14 |
: [ 'segment_ids' => $this->segment_ids ]; |
| 15 |
|
| 16 |
// Exclusions accompany the audience rather than replacing it: the API |
| 17 |
// accepts excluded_segment_ids alongside any audience type, so an empty |
| 18 |
// targeting selection plus exclusions means "all subscribers except these". |
| 19 |
if ( ! empty( $this->excluded_segment_ids ) ) { |
| 20 |
$audience['excluded_segment_ids'] = $this->excluded_segment_ids; |
| 21 |
} |
| 22 |
|
| 23 |
return $audience; |
| 24 |
} |
| 25 |
} |
| 26 |
|