← All changes
|
back/dynamics/subscriber/SubscriberAutomationTriggers.php
+0
-171
trunk
→
11.1.1
View file →
| @@ -1,171 +1,0 @@ | ||
| 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 | - protected function initAutomationTriggers(): void | |
| 14 | - { | |
| 15 | - foreach ($this->triggers as $key => $name) { | |
| 16 | - $this->automationTriggers['user'][$key] = acym_translation($name); | |
| 17 | - } | |
| 18 | - } | |
| 19 | - | |
| 20 | - public function displayTriggerOptions(string $fieldName, array $defaultValues, string $key): void | |
| 21 | - { | |
| 22 | - echo '<input type="hidden" name="'.esc_attr($fieldName.'[]').'" value="">'; | |
| 23 | - | |
| 24 | - if (!in_array($key, $this->triggerMail)) { | |
| 25 | - return; | |
| 26 | - } | |
| 27 | - | |
| 28 | - $mailIdAttributes = [ | |
| 29 | - 'data-class' => 'acym_select2_ajax', | |
| 30 | - 'data-placeholder' => acym_translation('ACYM_ANY_EMAIL', true), | |
| 31 | - 'data-params' => [ | |
| 32 | - 'plugin' => 'plgAcymStatistics', | |
| 33 | - 'trigger' => 'searchMail', | |
| 34 | - ], | |
| 35 | - ]; | |
| 36 | - if (!empty($defaultValues['mail_'.$key])) $mailIdAttributes['data-selected'] = $defaultValues['mail_'.$key]; | |
| 37 | - ?> | |
| 38 | - <div class="cell shrink"> | |
| 39 | - <?php | |
| 40 | - // This one is a sibling of the trigger in the saved data, not one of its children, see | |
| 41 | - // onAcymExecuteTrigger, so it keeps an absolute name | |
| 42 | - acym_select( | |
| 43 | - [], | |
| 44 | - '[triggers][user][mail_'.$key.']', | |
| 45 | - null, | |
| 46 | - $mailIdAttributes, | |
| 47 | - 'value', | |
| 48 | - 'text', | |
| 49 | - null, | |
| 50 | - false, | |
| 51 | - true | |
| 52 | - ); ?> | |
| 53 | - </div> | |
| 54 | - <?php | |
| 55 | - } | |
| 56 | - | |
| 57 | - public function onAcymExecuteTrigger(&$step, &$execute, &$data) | |
| 58 | - { | |
| 59 | - if (empty($data['userId'])) return; | |
| 60 | - | |
| 61 | - $triggers = $step->triggers; | |
| 62 | - | |
| 63 | - foreach ($this->triggers as $identifier => $name) { | |
| 64 | - if (empty($triggers[$identifier])) { | |
| 65 | - continue; | |
| 66 | - } | |
| 67 | - | |
| 68 | - if (!empty($triggers['mail_'.$identifier]) && in_array($identifier, $this->triggerMail)) { | |
| 69 | - if (empty($data['mailId']) || $data['mailId'] != $triggers['mail_'.$identifier]) { | |
| 70 | - continue; | |
| 71 | - } | |
| 72 | - } | |
| 73 | - | |
| 74 | - $execute = true; | |
| 75 | - break; | |
| 76 | - } | |
| 77 | - } | |
| 78 | - | |
| 79 | - public function onAcymDeclareSummary_triggers(object $automation): void | |
| 80 | - { | |
| 81 | - if (!empty($automation->triggers['user_open'])) $automation->triggers['user_open'] = acym_translation('ACYM_WHEN_USER_OPEN_MAIL'); | |
| 82 | - if (!empty($automation->triggers['user_click'])) $automation->triggers['user_click'] = acym_translation('ACYM_WHEN_USER_CLICKS_MAIL'); | |
| 83 | - if (!empty($automation->triggers['user_modification'])) $automation->triggers['user_modification'] = acym_translation('ACYM_ON_USER_MODIFICATION'); | |
| 84 | - if (!empty($automation->triggers['user_creation'])) $automation->triggers['user_creation'] = acym_translation('ACYM_ON_USER_CREATION'); | |
| 85 | - if (!empty($automation->triggers['user_confirmation'])) $automation->triggers['user_confirmation'] = acym_translation('ACYM_WHEN_USER_CONFIRMS_SUBSCRIPTION'); | |
| 86 | - } | |
| 87 | - | |
| 88 | - public function onAcymAfterUserModify(&$user, &$oldUser) | |
| 89 | - { | |
| 90 | - if (empty($user)) { | |
| 91 | - return; | |
| 92 | - } | |
| 93 | - | |
| 94 | - $automationClass = new AutomationClass(); | |
| 95 | - $automationClass->trigger('user_modification', ['userId' => $user->id]); | |
| 96 | - | |
| 97 | - $scenarioHelper = new ScenarioHelper(); | |
| 98 | - $scenarioHelper->trigger('user_modification', ['userId' => $user->id]); | |
| 99 | - | |
| 100 | - if (empty($oldUser)) { | |
| 101 | - return; | |
| 102 | - } | |
| 103 | - | |
| 104 | - $exportChanges = $this->config->get('export_data_changes', 0); | |
| 105 | - if (!$exportChanges) { | |
| 106 | - return; | |
| 107 | - } | |
| 108 | - | |
| 109 | - $fieldsToExport = $this->config->get('export_data_changes_fields', []); | |
| 110 | - if (empty($fieldsToExport)) { | |
| 111 | - return; | |
| 112 | - } | |
| 113 | - | |
| 114 | - $userClass = new UserClass(); | |
| 115 | - $newUser = $userClass->getOneByIdWithCustomFields($user->id); | |
| 116 | - if (empty($newUser)) { | |
| 117 | - return; | |
| 118 | - } | |
| 119 | - | |
| 120 | - $fieldsToExport = explode(',', $fieldsToExport); | |
| 121 | - $fieldClass = new FieldClass(); | |
| 122 | - $fields = $fieldClass->getByIds($fieldsToExport); | |
| 123 | - | |
| 124 | - $fieldsName = []; | |
| 125 | - foreach ($fields as $field) { | |
| 126 | - if ($field->name == 'ACYM_NAME') { | |
| 127 | - $name = 'name'; | |
| 128 | - } elseif ($field->name == 'ACYM_EMAIL') { | |
| 129 | - $name = 'email'; | |
| 130 | - } elseif ($field->name == 'ACYM_LANGUAGE') { | |
| 131 | - $name = 'language'; | |
| 132 | - } else { | |
| 133 | - $name = $field->name; | |
| 134 | - } | |
| 135 | - $fieldsName[] = $name; | |
| 136 | - } | |
| 137 | - | |
| 138 | - if (empty($fieldsName)) { | |
| 139 | - return; | |
| 140 | - } | |
| 141 | - | |
| 142 | - $exportHelper = new ExportHelper(); | |
| 143 | - | |
| 144 | - foreach ($newUser as $column => $value) { | |
| 145 | - if (!isset($oldUser[$column])) { | |
| 146 | - $oldUser[$column] = ''; | |
| 147 | - } | |
| 148 | - if (!isset($newUser[$column])) { | |
| 149 | - $newUser[$column] = ''; | |
| 150 | - } | |
| 151 | - | |
| 152 | - if ($oldUser[$column] == $newUser[$column]) { | |
| 153 | - continue; | |
| 154 | - } | |
| 155 | - | |
| 156 | - $exportHelper->exportChanges($newUser, $fieldsName, $column, $newUser[$column], $oldUser[$column]); | |
| 157 | - } | |
| 158 | - } | |
| 159 | - | |
| 160 | - public function onAcymAfterUserConfirm(&$user) | |
| 161 | - { | |
| 162 | - $automationClass = new AutomationClass(); | |
| 163 | - $automationClass->trigger('user_confirmation', ['userId' => $user->id]); | |
| 164 | - | |
| 165 | - $scenarioHelper = new ScenarioHelper(); | |
| 166 | - $scenarioHelper->trigger('user_confirmation', ['userId' => $user->id]); | |
| 167 | - | |
| 168 | - $followupClass = new FollowupClass(); | |
| 169 | - $followupClass->addFollowupEmailsQueue(self::FOLLOWUP_USER_CONFIRMATION, $user->id); | |
| 170 | - } | |
| 171 | -} | |