ConfirmationEmailTemplate
1 month ago
ImportExport
2 weeks ago
RestApi
3 days ago
Statistics
1 month ago
BulkActionController.php
3 days ago
BulkActionException.php
1 month ago
BulkConfirmationEmailResender.php
2 months ago
ConfirmationEmailCustomizer.php
2 months ago
ConfirmationEmailMailer.php
2 months ago
ConfirmationEmailResolver.php
2 months ago
EngagementDataBackfiller.php
2 months ago
InactiveSubscribersController.php
4 days ago
LinkTokens.php
2 months ago
NewSubscriberNotificationMailer.php
2 months ago
RequiredCustomFieldValidator.php
2 months ago
SegmentsCountRecalculator.php
2 weeks ago
Source.php
2 months ago
SubscriberActions.php
2 months ago
SubscriberCustomFieldRepository.php
3 years ago
SubscriberIPsRepository.php
2 years ago
SubscriberLimitNotificationEvaluator.php
2 months ago
SubscriberLimitNotificationMailer.php
2 months ago
SubscriberLimitNotificationScheduler.php
2 months ago
SubscriberListingRepository.php
2 weeks ago
SubscriberPersonalDataEraser.php
2 months ago
SubscriberSaveController.php
3 days ago
SubscriberSegmentRepository.php
2 weeks ago
SubscriberSubscribeController.php
2 weeks ago
SubscriberTagRepository.php
4 years ago
SubscribersCountsController.php
2 weeks ago
SubscribersEmailCountsController.php
2 weeks ago
SubscribersRepository.php
3 days ago
TrackingConsentController.php
4 days ago
index.php
3 years ago
ConfirmationEmailResolver.php
57 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Subscribers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\SegmentEntity; |
| 9 | |
| 10 | class ConfirmationEmailResolver { |
| 11 | /** |
| 12 | * Resolves which confirmation email and page to use based on segment settings. |
| 13 | * |
| 14 | * Rules: |
| 15 | * - If no segments have custom settings, returns [null, null] (use global). |
| 16 | * - If exactly one unique custom email/page is set, use it. |
| 17 | * - If segments conflict (different custom values), fall back to global (null). |
| 18 | * |
| 19 | * Email and page are resolved independently. |
| 20 | * |
| 21 | * @param SegmentEntity[] $segments |
| 22 | * @return array{0: int|null, 1: int|null} [confirmationEmailId, confirmationPageId] |
| 23 | */ |
| 24 | public function resolveFromSegments(array $segments): array { |
| 25 | $emailIds = []; |
| 26 | $pageIds = []; |
| 27 | |
| 28 | foreach ($segments as $segment) { |
| 29 | $emailId = $segment->getConfirmationEmailId(); |
| 30 | if ($emailId !== null) { |
| 31 | $emailIds[] = $emailId; |
| 32 | } |
| 33 | |
| 34 | $pageId = $segment->getConfirmationPageId(); |
| 35 | if ($pageId !== null) { |
| 36 | $pageIds[] = $pageId; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | $resolvedEmailId = $this->resolveValue($emailIds); |
| 41 | $resolvedPageId = $this->resolveValue($pageIds); |
| 42 | |
| 43 | return [$resolvedEmailId, $resolvedPageId]; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @param int[] $values |
| 48 | */ |
| 49 | private function resolveValue(array $values): ?int { |
| 50 | $unique = array_unique($values); |
| 51 | if (count($unique) === 1) { |
| 52 | return $unique[0]; |
| 53 | } |
| 54 | return null; |
| 55 | } |
| 56 | } |
| 57 |