| 1 |
<?php |
| 2 |
|
| 3 |
use AcyMailing\Classes\FollowupClass; |
| 4 |
use AcyMailing\Classes\ScenarioClass; |
| 5 |
use AcyMailing\Helpers\ExportHelper; |
| 6 |
use AcyMailing\Classes\UserClass; |
| 7 |
use AcyMailing\Classes\FieldClass; |
| 8 |
use AcyMailing\Classes\AutomationClass; |
| 9 |
use AcyMailing\Helpers\ScenarioHelper; |
| 10 |
|
| 11 |
trait SubscriberAutomationTriggers |
| 12 |
{ |
| 13 |
public function onAcymDeclareTriggers(&$triggers, &$defaultValues) |
| 14 |
{ |
| 15 |
foreach ($this->triggers as $key => $name) { |
| 16 |
$triggers['user'][$key] = new stdClass(); |
| 17 |
$triggers['user'][$key]->name = '<div class="cell shrink">'.acym_translation($name).'</div>'; |
| 18 |
$triggers['user'][$key]->option = '<input type="hidden" name="[triggers][user]['.$key.'][]" value="">'; |
| 19 |
|
| 20 |
if (in_array($key, $this->triggerMail)) { |
| 21 |
$mailIdAttributes = [ |
| 22 |
'data-class' => 'acym_select2_ajax', |
| 23 |
'data-placeholder' => acym_translation('ACYM_ANY_EMAIL', true), |
| 24 |
'data-params' => [ |
| 25 |
'plugin' => 'plgAcymStatistics', |
| 26 |
'trigger' => 'searchMail', |
| 27 |
], |
| 28 |
]; |
| 29 |
if (!empty($defaultValues['mail_'.$key])) $mailIdAttributes['data-selected'] = $defaultValues['mail_'.$key]; |
| 30 |
|
| 31 |
$triggers['user'][$key]->option .= '<div class="cell shrink">'.acym_select( |
| 32 |
[], |
| 33 |
'[triggers][user][mail_'.$key.']', |
| 34 |
null, |
| 35 |
$mailIdAttributes |
| 36 |
).'</div>'; |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public function onAcymDeclareTriggersScenario(&$triggers, &$defaultValues) |
| 42 |
{ |
| 43 |
$this->onAcymDeclareTriggers($triggers, $defaultValues); |
| 44 |
} |
| 45 |
|
| 46 |
public function onAcymExecuteTrigger(&$step, &$execute, &$data) |
| 47 |
{ |
| 48 |
if (empty($data['userId'])) return; |
| 49 |
|
| 50 |
$triggers = $step->triggers; |
| 51 |
|
| 52 |
foreach ($this->triggers as $identifier => $name) { |
| 53 |
if (empty($triggers[$identifier])) { |
| 54 |
continue; |
| 55 |
} |
| 56 |
|
| 57 |
if (!empty($triggers['mail_'.$identifier]) && in_array($identifier, $this->triggerMail)) { |
| 58 |
if (empty($data['mailId']) || $data['mailId'] != $triggers['mail_'.$identifier]) { |
| 59 |
continue; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
$execute = true; |
| 64 |
break; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
public function onAcymDeclareSummary_triggers(object $automation): void |
| 69 |
{ |
| 70 |
if (!empty($automation->triggers['user_open'])) $automation->triggers['user_open'] = acym_translation('ACYM_WHEN_USER_OPEN_MAIL'); |
| 71 |
if (!empty($automation->triggers['user_click'])) $automation->triggers['user_click'] = acym_translation('ACYM_WHEN_USER_CLICKS_MAIL'); |
| 72 |
if (!empty($automation->triggers['user_modification'])) $automation->triggers['user_modification'] = acym_translation('ACYM_ON_USER_MODIFICATION'); |
| 73 |
if (!empty($automation->triggers['user_creation'])) $automation->triggers['user_creation'] = acym_translation('ACYM_ON_USER_CREATION'); |
| 74 |
if (!empty($automation->triggers['user_confirmation'])) $automation->triggers['user_confirmation'] = acym_translation('ACYM_WHEN_USER_CONFIRMS_SUBSCRIPTION'); |
| 75 |
} |
| 76 |
|
| 77 |
public function onAcymAfterUserModify(&$user, &$oldUser) |
| 78 |
{ |
| 79 |
if (empty($user)) { |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
$automationClass = new AutomationClass(); |
| 84 |
$automationClass->trigger('user_modification', ['userId' => $user->id]); |
| 85 |
|
| 86 |
$scenarioHelper = new ScenarioHelper(); |
| 87 |
$scenarioHelper->trigger('user_modification', ['userId' => $user->id]); |
| 88 |
|
| 89 |
if (empty($oldUser)) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
$exportChanges = $this->config->get('export_data_changes', 0); |
| 94 |
if (!$exportChanges) { |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
$fieldsToExport = $this->config->get('export_data_changes_fields', []); |
| 99 |
if (empty($fieldsToExport)) { |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
$userClass = new UserClass(); |
| 104 |
$newUser = $userClass->getOneByIdWithCustomFields($user->id); |
| 105 |
if (empty($newUser)) { |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
$fieldsToExport = explode(',', $fieldsToExport); |
| 110 |
$fieldClass = new FieldClass(); |
| 111 |
$fields = $fieldClass->getByIds($fieldsToExport); |
| 112 |
|
| 113 |
$fieldsName = []; |
| 114 |
foreach ($fields as $field) { |
| 115 |
if ($field->name == 'ACYM_NAME') { |
| 116 |
$name = 'name'; |
| 117 |
} elseif ($field->name == 'ACYM_EMAIL') { |
| 118 |
$name = 'email'; |
| 119 |
} elseif ($field->name == 'ACYM_LANGUAGE') { |
| 120 |
$name = 'language'; |
| 121 |
} else { |
| 122 |
$name = $field->name; |
| 123 |
} |
| 124 |
$fieldsName[] = $name; |
| 125 |
} |
| 126 |
|
| 127 |
if (empty($fieldsName)) { |
| 128 |
return; |
| 129 |
} |
| 130 |
|
| 131 |
$exportHelper = new ExportHelper(); |
| 132 |
|
| 133 |
foreach ($newUser as $column => $value) { |
| 134 |
if (!isset($oldUser[$column])) { |
| 135 |
$oldUser[$column] = ''; |
| 136 |
} |
| 137 |
if (!isset($newUser[$column])) { |
| 138 |
$newUser[$column] = ''; |
| 139 |
} |
| 140 |
|
| 141 |
if ($oldUser[$column] == $newUser[$column]) { |
| 142 |
continue; |
| 143 |
} |
| 144 |
|
| 145 |
$exportHelper->exportChanges($newUser, $fieldsName, $column, $newUser[$column], $oldUser[$column]); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
public function onAcymAfterUserConfirm(&$user) |
| 150 |
{ |
| 151 |
$automationClass = new AutomationClass(); |
| 152 |
$automationClass->trigger('user_confirmation', ['userId' => $user->id]); |
| 153 |
|
| 154 |
$scenarioHelper = new ScenarioHelper(); |
| 155 |
$scenarioHelper->trigger('user_confirmation', ['userId' => $user->id]); |
| 156 |
|
| 157 |
$followupClass = new FollowupClass(); |
| 158 |
$followupClass->addFollowupEmailsQueue(self::FOLLOWUP_USER_CONFIRMATION, $user->id); |
| 159 |
} |
| 160 |
} |
| 161 |
|