| @@ -1,135 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace AcyMailing\Controllers\Users; | |
| 4 | - | |
| 5 | -use AcyMailing\Classes\ListClass; | |
| 6 | -use AcyMailing\Classes\UserClass; | |
| 7 | - | |
| 8 | -trait Subscription | |
| 9 | -{ | |
| 10 | - public function resetSubscription(): void | |
| 11 | - { | |
| 12 | - $userId = acym_getVar('int', 'userId'); | |
| 13 | - | |
| 14 | - if (empty($userId)) { | |
| 15 | - $this->listing(); | |
| 16 | - | |
| 17 | - return; | |
| 18 | - } | |
| 19 | - | |
| 20 | - $userClass = new UserClass(); | |
| 21 | - if (!$userClass->hasUserAccess($userId)) { | |
| 22 | - die('Access denied for subscription reset of this user'); | |
| 23 | - } | |
| 24 | - | |
| 25 | - $list = acym_getVar('int', 'acym__entity_select__selected'); | |
| 26 | - $userClass->resetSubscription($userId, [$list]); | |
| 27 | - | |
| 28 | - $this->edit(); | |
| 29 | - } | |
| 30 | - | |
| 31 | - public function unsubscribeUser(): void | |
| 32 | - { | |
| 33 | - $userId = acym_getVar('int', 'userId'); | |
| 34 | - if (empty($userId)) { | |
| 35 | - $this->listing(); | |
| 36 | - | |
| 37 | - return; | |
| 38 | - } | |
| 39 | - | |
| 40 | - $userClass = new UserClass(); | |
| 41 | - if (!$userClass->hasUserAccess($userId)) { | |
| 42 | - die('Access denied for unsubscribing this user'); | |
| 43 | - } | |
| 44 | - | |
| 45 | - $lists = json_decode(acym_getVar('string', 'acym__entity_select__selected', '{}')); | |
| 46 | - if (!is_array($lists)) { | |
| 47 | - $lists = (array)$lists; | |
| 48 | - } | |
| 49 | - | |
| 50 | - $userClass->unsubscribe($userId, $lists); | |
| 51 | - | |
| 52 | - $this->edit(); | |
| 53 | - } | |
| 54 | - | |
| 55 | - public function unsubscribeUserFromAll(): void | |
| 56 | - { | |
| 57 | - $userId = acym_getVar('int', 'userId'); | |
| 58 | - | |
| 59 | - if (empty($userId)) { | |
| 60 | - $this->listing(); | |
| 61 | - | |
| 62 | - return; | |
| 63 | - } | |
| 64 | - | |
| 65 | - $userClass = new UserClass(); | |
| 66 | - if (!$userClass->hasUserAccess($userId)) { | |
| 67 | - die('Access denied for unsubscribing this user'); | |
| 68 | - } | |
| 69 | - | |
| 70 | - $lists = []; | |
| 71 | - $subscriptions = $userClass->getSubscriptionStatus($userId); | |
| 72 | - foreach ($subscriptions as $i => $oneList) { | |
| 73 | - if ($oneList->status == 1) { | |
| 74 | - $lists[] = $oneList->list_id; | |
| 75 | - } | |
| 76 | - } | |
| 77 | - | |
| 78 | - $userClass->unsubscribe($userId, $lists); | |
| 79 | - | |
| 80 | - $this->edit(); | |
| 81 | - } | |
| 82 | - | |
| 83 | - public function resubscribeUserToAll(): void | |
| 84 | - { | |
| 85 | - $userId = acym_getVar('int', 'userId'); | |
| 86 | - if (empty($userId)) { | |
| 87 | - $this->listing(); | |
| 88 | - | |
| 89 | - return; | |
| 90 | - } | |
| 91 | - | |
| 92 | - $userClass = new UserClass(); | |
| 93 | - if (!$userClass->hasUserAccess($userId)) { | |
| 94 | - die('Access denied for resubscribing this user'); | |
| 95 | - } | |
| 96 | - | |
| 97 | - $lists = []; | |
| 98 | - $subscriptions = $userClass->getSubscriptionStatus($userId); | |
| 99 | - foreach ($subscriptions as $i => $oneList) { | |
| 100 | - if ($oneList->status == 0) { | |
| 101 | - $lists[] = $oneList->list_id; | |
| 102 | - } | |
| 103 | - } | |
| 104 | - | |
| 105 | - $userClass->subscribe($userId, $lists); | |
| 106 | - | |
| 107 | - $this->edit(); | |
| 108 | - } | |
| 109 | - | |
| 110 | - public function subscribeUser(bool $returnOnEdit = true, bool $frontCreation = false): void | |
| 111 | - { | |
| 112 | - $userId = acym_getVar('int', 'userId'); | |
| 113 | - $lists = json_decode(acym_getVar('string', 'acym__entity_select__selected', '{}')); | |
| 114 | - | |
| 115 | - if (empty($userId)) { | |
| 116 | - $this->listing(); | |
| 117 | - | |
| 118 | - return; | |
| 119 | - } | |
| 120 | - | |
| 121 | - $userClass = new UserClass(); | |
| 122 | - if (!$frontCreation && !$userClass->hasUserAccess($userId)) { | |
| 123 | - die('Access denied for subscribing this user'); | |
| 124 | - } | |
| 125 | - | |
| 126 | - if (!is_array($lists)) { | |
| 127 | - $lists = (array)$lists; | |
| 128 | - } | |
| 129 | - $userClass->subscribe($userId, $lists); | |
| 130 | - | |
| 131 | - if ($returnOnEdit) { | |
| 132 | - $this->edit(); | |
| 133 | - } | |
| 134 | - } | |
| 135 | -} | |