Do not display form if logged in and registered to any segment.

[MAILPOET-3059]
This commit is contained in:
Brezo Cordero
2022-02-11 17:49:46 -06:00
committed by Veljko V
parent 8c70069064
commit bfa9a98df6
4 changed files with 255 additions and 2 deletions

View File

@ -3,9 +3,11 @@
namespace MailPoet\Subscribers;
use MailPoet\Entities\FormEntity;
use MailPoet\Entities\SubscriberEntity;
use MailPoet\Form\FormsRepository;
use MailPoet\Form\Util\FieldNameObfuscator;
use MailPoet\NotFoundException;
use MailPoet\Segments\SubscribersFinder;
use MailPoet\Settings\SettingsController;
use MailPoet\Statistics\StatisticsFormsRepository;
use MailPoet\Subscription\Captcha;
@ -49,10 +51,14 @@ class SubscriberSubscribeController {
/** @var StatisticsFormsRepository */
private $statisticsFormsRepository;
/** @var SubscribersFinder */
private $subscribersFinder;
public function __construct(
Captcha $subscriptionCaptcha,
CaptchaSession $captchaSession,
SubscriberActions $subscriberActions,
SubscribersFinder $subscribersFinder,
SubscriptionUrlFactory $subscriptionUrlFactory,
SubscriptionThrottling $throttling,
FieldNameObfuscator $fieldNameObfuscator,
@ -70,6 +76,7 @@ class SubscriberSubscribeController {
$this->fieldNameObfuscator = $fieldNameObfuscator;
$this->settings = $settings;
$this->subscriberActions = $subscriberActions;
$this->subscribersFinder = $subscribersFinder;
$this->wp = $wp;
$this->throttling = $throttling;
$this->statisticsFormsRepository = $statisticsFormsRepository;
@ -153,6 +160,22 @@ class SubscriberSubscribeController {
return $meta;
}
/**
* Checks if the subscriber is subscribed to any segments in the form
*
* @param FormEntity $form The form entity
* @param SubscriberEntity $subscriber The subscriber entity
* @return bool True if the subscriber is subscribed to any of the segments in the form
*/
public function isSubscribedToAnyFormSegments(FormEntity $form, SubscriberEntity $subscriber): bool {
$formSegments = array_merge( $form->getSegmentBlocksSegmentIds(), $form->getSettingsSegmentIds());
$subscribersFound = $this->subscribersFinder->findSubscribersInSegments([$subscriber->getId()], $formSegments);
if (!empty($subscribersFound)) return true;
return false;
}
private function deobfuscateFormPayload($data): array {
return $this->fieldNameObfuscator->deobfuscateFormPayload($data);
}