PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.11.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.11.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / dynamics / subscriber / SubscriberFollowup.php

SubscriberFollowup.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.11.1, at back/dynamics/subscriber/SubscriberFollowup.php

106 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Classes\FollowupClass;
4 use AcyMailing\Classes\SegmentClass;
5 use AcyMailing\Helpers\AutomationHelper;
6 use AcyMailing\Classes\AutomationClass;
7 use AcyMailing\Helpers\ScenarioHelper;
8
9 trait SubscriberFollowup
10 {
11 public function onAcymAfterUserCreate(&$user)
12 {
13 $automationClass = new AutomationClass();
14 $automationClass->trigger('user_creation', ['userId' => $user->id]);
15
16 $followupClass = new FollowupClass();
17 $followupClass->addFollowupEmailsQueue(self::FOLLOWUP_USER_CREATION, $user->id);
18
19 $scenarioHelper = new ScenarioHelper();
20 $scenarioHelper->trigger('user_creation', ['userId' => $user->id]);
21 }
22
23 public function matchFollowupsConditions(&$followups, $userId, $params)
24 {
25 $segmentClass = new SegmentClass();
26 foreach ($followups as $key => $followup) {
27 if (empty($followup->condition['segments_status']) || empty($followup->condition['segments'])) continue;
28
29 $segments = $segmentClass->getByIds($followup->condition['segments']);
30 if (empty($segments)) continue;
31
32 $mustMatch = $followup->condition['segments_status'] === 'is';
33
34 if ($mustMatch) {
35 foreach ($segments as $segment) {
36 $segmentMatched = false;
37 foreach ($segment->filters as $orBlock) {
38 if ($this->isUserMatchingOr($userId, $orBlock)) {
39 $segmentMatched = true;
40 break;
41 }
42 }
43
44 if (!$segmentMatched) {
45 unset($followups[$key]);
46
47 break;
48 }
49 }
50 } else {
51 foreach ($segments as $segment) {
52 foreach ($segment->filters as $orBlock) {
53 if ($this->isUserMatchingOr($userId, $orBlock)) {
54 unset($followups[$key]);
55
56 break 2;
57 }
58 }
59 }
60 }
61 }
62 }
63
64 private function isUserMatchingOr($userId, $orBlock): bool
65 {
66 $automationHelper = new AutomationHelper();
67 $automationHelper->where[] = 'user.id = '.intval($userId);
68 foreach ($orBlock as $and => $andValues) {
69 $and = intval($and);
70 foreach ($andValues as $filterName => $options) {
71 acym_trigger('onAcymProcessFilter_'.$filterName, [&$automationHelper, &$options, &$and]);
72 }
73 }
74 $userMatchingOr = acym_loadResult($automationHelper->getQuery(['user.id']));
75
76 return !empty($userMatchingOr);
77 }
78
79 public function getFollowupTriggers(&$triggers)
80 {
81 $triggers[self::FOLLOWUP_USER_CREATION] = acym_translation('ACYM_SUBSCRIBER_CREATION');
82 $triggers[self::FOLLOWUP_USER_CONFIRMATION] = acym_translation('ACYM_SUBSCRIPTION_CONFIRMATION');
83 }
84
85 public function getFollowupTriggerBlock(&$blocks)
86 {
87 $blocks[] = [
88 'name' => acym_translation('ACYM_SUBSCRIBER_CREATION'),
89 'description' => acym_translation('ACYM_SUBSCRIBER_CREATION_DESC'),
90 'icon' => 'acymicon-user-plus',
91 'link' => acym_completeLink('campaigns&task=edit&step=followupCondition&trigger='.self::FOLLOWUP_USER_CREATION),
92 'level' => 2,
93 'alias' => self::FOLLOWUP_USER_CREATION,
94 ];
95
96 $blocks[] = [
97 'name' => acym_translation('ACYM_SUBSCRIPTION_CONFIRMATION'),
98 'description' => acym_translation('ACYM_SUBSCRIPTION_CONFIRMATION_DESC'),
99 'icon' => 'acymicon-user-check',
100 'link' => acym_completeLink('campaigns&task=edit&step=followupCondition&trigger='.self::FOLLOWUP_USER_CONFIRMATION),
101 'level' => 2,
102 'alias' => self::FOLLOWUP_USER_CONFIRMATION,
103 ];
104 }
105 }
106