← All changes
|
back/dynamics/subscription/SubscriptionAutomationActions.php
+0
-167
10.11.1
→
11.1.1
View file →
| @@ -1,167 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -use AcyMailing\Classes\FollowupClass; | |
| 4 | -use AcyMailing\Classes\ListClass; | |
| 5 | - | |
| 6 | -trait SubscriptionAutomationActions | |
| 7 | -{ | |
| 8 | - public function onAcymDeclareActions(array &$actions): void | |
| 9 | - { | |
| 10 | - $listClass = new ListClass(); | |
| 11 | - | |
| 12 | - $listActions = [ | |
| 13 | - 'sub' => acym_translation('ACYM_SUBSCRIBE_USERS_TO'), | |
| 14 | - 'remove' => acym_translation('ACYM_REMOVE_USERS_FROM'), | |
| 15 | - 'unsub' => acym_translation('ACYM_UNSUBSCRIBE_USERS_TO'), | |
| 16 | - ]; | |
| 17 | - $lists = $listClass->getAllForSelect(); | |
| 18 | - | |
| 19 | - $actions['acy_list'] = new stdClass(); | |
| 20 | - $actions['acy_list']->name = acym_translation('ACYM_ACYMAILING_LIST'); | |
| 21 | - ob_start(); | |
| 22 | - include acym_getPartial('actions', 'acy_list'); | |
| 23 | - $actions['acy_list']->option = ob_get_clean(); | |
| 24 | - | |
| 25 | - $followupClass = new FollowupClass(); | |
| 26 | - $allListFollowups = $followupClass->getAll(); | |
| 27 | - $actions['subscribe_followup'] = new stdClass(); | |
| 28 | - $actions['subscribe_followup']->name = acym_translation('ACYM_SUBSCRIBE_FOLLOW_UP'); | |
| 29 | - ob_start(); | |
| 30 | - include acym_getPartial('actions', 'subscribe_followup'); | |
| 31 | - $actions['subscribe_followup']->option = ob_get_clean(); | |
| 32 | - | |
| 33 | - $actions['unsubscribe_followup'] = new stdClass(); | |
| 34 | - $actions['unsubscribe_followup']->name = acym_translation('ACYM_UNSUBSCRIBE_FOLLOW_UP'); | |
| 35 | - ob_start(); | |
| 36 | - include acym_getPartial('actions', 'unsubscribe_followup'); | |
| 37 | - $actions['unsubscribe_followup']->option = ob_get_clean(); | |
| 38 | - } | |
| 39 | - | |
| 40 | - public function onAcymDeclareActionsScenario(array &$actions): void | |
| 41 | - { | |
| 42 | - $this->onAcymDeclareActions($actions); | |
| 43 | - } | |
| 44 | - | |
| 45 | - public function onAcymProcessAction_acy_list(&$query, $action) | |
| 46 | - { | |
| 47 | - if ($action['list_actions'] === 'sub') { | |
| 48 | - $queryToProcess = 'INSERT IGNORE #__acym_user_has_list (`user_id`, `list_id`, `status`, `subscription_date`) ('.$query->getQuery( | |
| 49 | - [ | |
| 50 | - 'user.id', | |
| 51 | - intval($action['list_id']), | |
| 52 | - '1', | |
| 53 | - acym_escapeDB(acym_date(time(), 'Y-m-d H:i:s')), | |
| 54 | - ] | |
| 55 | - ).') ON DUPLICATE KEY UPDATE status = 1'; | |
| 56 | - } elseif ($action['list_actions'] === 'remove') { | |
| 57 | - $queryToProcess = 'DELETE FROM #__acym_user_has_list WHERE list_id = '.intval($action['list_id']).' AND user_id IN ('.$query->getQuery(['user.id']).')'; | |
| 58 | - } elseif ($action['list_actions'] === 'unsub') { | |
| 59 | - $queryToProcess = 'UPDATE #__acym_user_has_list SET status = 0 WHERE list_id = '.intval($action['list_id']).' AND user_id IN ('.$query->getQuery(['user.id']).')'; | |
| 60 | - } | |
| 61 | - | |
| 62 | - $nbAffected = acym_query($queryToProcess); | |
| 63 | - | |
| 64 | - return acym_translationSprintf('ACYM_ACTION_LIST_'.strtoupper($action['list_actions']), $nbAffected); | |
| 65 | - } | |
| 66 | - | |
| 67 | - public function onAcymProcessAction_subscribe_followup(&$query, &$action) | |
| 68 | - { | |
| 69 | - $followupClass = new FollowupClass(); | |
| 70 | - $followup = $followupClass->getOneById($action['followup_id']); | |
| 71 | - if (empty($followup->active)) { | |
| 72 | - return ''; | |
| 73 | - } | |
| 74 | - | |
| 75 | - $queryToProcess = 'INSERT IGNORE #__acym_user_has_list (`user_id`, `list_id`, `status`, `subscription_date`) ('.$query->getQuery( | |
| 76 | - [ | |
| 77 | - 'user.id', | |
| 78 | - $followup->list_id, | |
| 79 | - '1', | |
| 80 | - acym_escapeDB(acym_date(time(), 'Y-m-d H:i:s')), | |
| 81 | - ] | |
| 82 | - ).') ON DUPLICATE KEY UPDATE status = 1'; | |
| 83 | - | |
| 84 | - $nbAffected = acym_query($queryToProcess); | |
| 85 | - | |
| 86 | - $followups = $followupClass->getFollowupsWithMailsInfoByIds([$action['followup_id']]); | |
| 87 | - foreach ($followups as $mails) { | |
| 88 | - foreach ($mails as $mail) { | |
| 89 | - $sendDate = time() + (intval($mail->delay) * intval($mail->delay_unit)); | |
| 90 | - $sendDate = acym_escapeDB(acym_date($sendDate, 'Y-m-d H:i:s', false)); | |
| 91 | - $queryToProcess = 'INSERT IGNORE #__acym_queue (`mail_id`, `user_id`, `sending_date`, `priority`, `try`) ('.$query->getQuery( | |
| 92 | - [ | |
| 93 | - $mail->mail_id, | |
| 94 | - 'user.id', | |
| 95 | - $sendDate, | |
| 96 | - $this->config->get('priority_newsletter', 3), | |
| 97 | - 0, | |
| 98 | - ] | |
| 99 | - ).')'; | |
| 100 | - | |
| 101 | - acym_query($queryToProcess); | |
| 102 | - } | |
| 103 | - } | |
| 104 | - | |
| 105 | - return acym_translationSprintf('ACYM_ACTION_LIST_SUB', $nbAffected); | |
| 106 | - } | |
| 107 | - | |
| 108 | - public function onAcymProcessAction_unsubscribe_followup(&$query, &$action) | |
| 109 | - { | |
| 110 | - $followupClass = new FollowupClass(); | |
| 111 | - $followup = $followupClass->getOneById($action['followup_id']); | |
| 112 | - if (empty($followup)) { | |
| 113 | - return ''; | |
| 114 | - } | |
| 115 | - | |
| 116 | - $mailIds = $followupClass->getEmailsByIds([$action['followup_id']]); | |
| 117 | - if (!empty($mailIds)) { | |
| 118 | - acym_query( | |
| 119 | - 'DELETE FROM #__acym_queue | |
| 120 | - WHERE user_id IN ('.$query->getQuery(['user.id']).') | |
| 121 | - AND mail_id IN ('.implode(',', $mailIds).')' | |
| 122 | - ); | |
| 123 | - } | |
| 124 | - | |
| 125 | - $unsubscribeDate = date('Y-m-d H:i:s', time() - date('Z')); | |
| 126 | - $nbAffected = acym_query( | |
| 127 | - 'UPDATE #__acym_user_has_list | |
| 128 | - SET `status` = 0, `unsubscribe_date` = '.acym_escapeDB($unsubscribeDate).' | |
| 129 | - WHERE list_id = '.intval($followup->list_id).' | |
| 130 | - AND user_id IN ('.$query->getQuery(['user.id']).')' | |
| 131 | - ); | |
| 132 | - | |
| 133 | - return acym_translationSprintf('ACYM_ACTION_LIST_UNSUB', $nbAffected); | |
| 134 | - } | |
| 135 | - | |
| 136 | - public function onAcymDeclareSummary_actions(&$automationAction) | |
| 137 | - { | |
| 138 | - if (!empty($automationAction['acy_list'])) { | |
| 139 | - $listClass = new ListClass(); | |
| 140 | - $list = $listClass->getOneById($automationAction['acy_list']['list_id'] ? : 0); | |
| 141 | - if ($automationAction['acy_list']['list_actions'] == 'sub') $automationAction['acy_list']['list_actions'] = 'ACYM_SUBSCRIBED_TO'; | |
| 142 | - if ($automationAction['acy_list']['list_actions'] == 'unsub') $automationAction['acy_list']['list_actions'] = 'ACYM_UNSUBSCRIBE_FROM'; | |
| 143 | - if ($automationAction['acy_list']['list_actions'] == 'remove') $automationAction['acy_list']['list_actions'] = 'ACYM_REMOVE_FROM'; | |
| 144 | - if (empty($list)) { | |
| 145 | - $automationAction = '<span class="acym__color__red">'.acym_translation('ACYM_SELECT_A_LIST').'</span>'; | |
| 146 | - } else { | |
| 147 | - $automationAction = acym_translationSprintf('ACYM_ACTION_LIST_SUMMARY', acym_translation($automationAction['acy_list']['list_actions']), $list->name); | |
| 148 | - } | |
| 149 | - } | |
| 150 | - | |
| 151 | - if (!empty($automationAction['subscribe_followup'])) { | |
| 152 | - $followupClass = new FollowupClass(); | |
| 153 | - $followup = $followupClass->getOneById($automationAction['subscribe_followup']['followup_id']); | |
| 154 | - $automationAction = !empty($followup) | |
| 155 | - ? acym_translationSprintf('ACYM_ACTION_SUBSCRIBE_FOLLOWUP_SUMMARY', $followup->name) | |
| 156 | - : acym_translation('ACYM_FOLLOWUP_NOT_FOUND'); | |
| 157 | - } | |
| 158 | - | |
| 159 | - if (!empty($automationAction['unsubscribe_followup'])) { | |
| 160 | - $followupClass = new FollowupClass(); | |
| 161 | - $followup = $followupClass->getOneById($automationAction['unsubscribe_followup']['followup_id']); | |
| 162 | - $automationAction = !empty($followup) | |
| 163 | - ? acym_translationSprintf('ACYM_ACTION_UNSUBSCRIBE_FOLLOWUP_SUMMARY', $followup->name) | |
| 164 | - : acym_translation('ACYM_FOLLOWUP_NOT_FOUND'); | |
| 165 | - } | |
| 166 | - } | |
| 167 | -} | |