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