← All changes
|
back/dynamics/subscription/SubscriptionMailboxAction.php
+0
-131
11.1.0
→
11.1.1
View file →
| @@ -1,131 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -use AcyMailing\Classes\UserClass; | |
| 4 | -use AcyMailing\Classes\ListClass; | |
| 5 | - | |
| 6 | -trait SubscriptionMailboxAction | |
| 7 | -{ | |
| 8 | - protected function initMailboxActions(): void | |
| 9 | - { | |
| 10 | - $this->mailboxActions = [ | |
| 11 | - 'acy_list_subscribe' => acym_translation('ACYM_SUBSCRIBE_USER'), | |
| 12 | - 'acy_list_unsubscribe' => acym_translation('ACYM_UNSUB_USER'), | |
| 13 | - ]; | |
| 14 | - } | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * Both actions offer the same list selector | |
| 18 | - */ | |
| 19 | - public function displayMailboxActionOptions(string $fieldName): void | |
| 20 | - { | |
| 21 | - $listClass = new ListClass(); | |
| 22 | - ?> | |
| 23 | - <div class="intext_select_mailbox cell"> | |
| 24 | - <?php acym_select( | |
| 25 | - $listClass->getAllWithIdName(), | |
| 26 | - $fieldName.'[list_id]', | |
| 27 | - null, | |
| 28 | - ['class' => 'acym__select'], | |
| 29 | - 'value', | |
| 30 | - 'text', | |
| 31 | - null, | |
| 32 | - false, | |
| 33 | - true | |
| 34 | - ); ?> | |
| 35 | - </div> | |
| 36 | - <?php | |
| 37 | - } | |
| 38 | - | |
| 39 | - public function onAcymMailboxActionSummaryListing(&$action, &$result) | |
| 40 | - { | |
| 41 | - $listClass = new ListClass(); | |
| 42 | - if (!empty($action['acy_list_subscribe'])) { | |
| 43 | - $list = $listClass->getOneById($action['acy_list_subscribe']['list_id']); | |
| 44 | - | |
| 45 | - if (empty($list)) { | |
| 46 | - return; | |
| 47 | - } | |
| 48 | - | |
| 49 | - $result[] = acym_translationSprintf('ACYM_SUBSCRIBE_USER_X', $list->name); | |
| 50 | - } | |
| 51 | - | |
| 52 | - if (!empty($action['acy_list_unsubscribe'])) { | |
| 53 | - $list = $listClass->getOneById($action['acy_list_unsubscribe']['list_id']); | |
| 54 | - | |
| 55 | - if (empty($list)) { | |
| 56 | - return; | |
| 57 | - } | |
| 58 | - | |
| 59 | - $result[] = acym_translationSprintf('ACYM_UNSUB_USER_X', $list->name); | |
| 60 | - } | |
| 61 | - } | |
| 62 | - | |
| 63 | - public function onAcymMailboxAction_acy_list_subscribe(&$action, &$report, &$executedActions, $mailboxHelper) | |
| 64 | - { | |
| 65 | - $userClass = new UserClass(); | |
| 66 | - $user = new \stdClass(); | |
| 67 | - $user->email = $mailboxHelper->_message->header->from_email; | |
| 68 | - $userDatabase = $userClass->getOneByEmail($user->email); | |
| 69 | - if (empty($userDatabase->id)) { | |
| 70 | - $user->id = $userClass->save($user); | |
| 71 | - if (empty($user->id)) { | |
| 72 | - $report[] = [ | |
| 73 | - 'message' => acym_translation('ACYM_ERROR_SAVING'), | |
| 74 | - 'success' => false, | |
| 75 | - ]; | |
| 76 | - $executedActions = false; | |
| 77 | - | |
| 78 | - return; | |
| 79 | - } | |
| 80 | - } else { | |
| 81 | - $user->id = $userDatabase->id; | |
| 82 | - } | |
| 83 | - | |
| 84 | - $subscribed = $userClass->subscribe([$user->id], [$action['list_id']]); | |
| 85 | - | |
| 86 | - if (!$subscribed) { | |
| 87 | - $report[] = [ | |
| 88 | - 'message' => acym_translationSprintf('ACYM_COULD_NOT_SUBSCRIBE_TO_X', $action['list_id']), | |
| 89 | - 'success' => false, | |
| 90 | - ]; | |
| 91 | - $executedActions = false; | |
| 92 | - | |
| 93 | - return; | |
| 94 | - } | |
| 95 | - | |
| 96 | - $report[] = [ | |
| 97 | - 'message' => acym_translationSprintf('ACYM_SUBSCRIBE_USER_X', $action['list_id']), | |
| 98 | - 'success' => true, | |
| 99 | - ]; | |
| 100 | - } | |
| 101 | - | |
| 102 | - public function onAcymMailboxAction_acy_list_unsubscribe(&$action, &$report, &$executedActions, $mailboxHelper) | |
| 103 | - { | |
| 104 | - $user = new \stdClass(); | |
| 105 | - $user->email = $mailboxHelper->_message->header->from_email; | |
| 106 | - | |
| 107 | - $userClass = new UserClass(); | |
| 108 | - $userDatabase = $userClass->getOneByEmail($user->email); | |
| 109 | - | |
| 110 | - if (empty($userDatabase->id)) { | |
| 111 | - $report[] = [ | |
| 112 | - 'message' => acym_translationSprintf('ACYM_SEND_ERROR_USER', $mailboxHelper->_message->header->from_email), | |
| 113 | - 'success' => false, | |
| 114 | - ]; | |
| 115 | - | |
| 116 | - $executedActions = false; | |
| 117 | - | |
| 118 | - return; | |
| 119 | - } | |
| 120 | - $affected = $userClass->unsubscribe([$userDatabase->id], [$action['list_id']]); | |
| 121 | - $message = $affected | |
| 122 | - ? acym_translationSprintf('ACYM_UNSUB_USER_X_FROM_X', $userDatabase->email, $action['list_id']) | |
| 123 | - : acym_translationSprintf('ACYM_COULD_NOT_UNSUB_USER_X_FROM_X', $userDatabase->email, $action['list_id']); | |
| 124 | - $report[] = [ | |
| 125 | - 'message' => $message, | |
| 126 | - 'success' => $affected, | |
| 127 | - ]; | |
| 128 | - | |
| 129 | - $executedActions = $affected; | |
| 130 | - } | |
| 131 | -} | |