PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Controllers/Users/Listing.php +41 -29 10.0.1 → 11.1.0 View file →
@@ -12,15 +12,15 @@
12 12 use AcyMailing\Helpers\ToolbarHelper;
13 13
14 14 trait Listing
15 15 {
16 - public function listing()
16 + public function listing(): void
17 17 {
18 18 acym_setVar('layout', 'listing');
19 19
20 20 $data = [];
21 - $data['ordering'] = $this->getVarFiltersListing('string', 'users_ordering', 'id');
22 - $data['orderingSortOrder'] = $this->getVarFiltersListing('string', 'users_ordering_sort_order', 'desc');
21 + $data['ordering'] = $this->getVarFiltersListing('cmd', 'users_ordering', 'id');
22 + $data['orderingSortOrder'] = $this->getVarFiltersListing('cmd', 'users_ordering_sort_order', 'desc');
23 23 $data['pagination'] = new PaginationHelper();
24 24
25 25 $this->prepareSegmentField($data);
26 26 $this->prepareListingFilters($data);
@@ -31,9 +31,9 @@
31 31
32 32 parent::display($data);
33 33 }
34 34
35 - protected function prepareSegmentField(&$data)
35 + protected function prepareSegmentField(array &$data): void
36 36 {
37 37 $segmentClass = new SegmentClass();
38 38 $segments = $segmentClass->getAllForSelect();
39 39 $data['segments'] = [];
@@ -42,9 +42,9 @@
42 42 $data['segments'][$id] = $name;
43 43 }
44 44 }
45 45
46 - protected function prepareToolbar(&$data)
46 + protected function prepareToolbar(array &$data): void
47 47 {
48 48 $toolbarHelper = new ToolbarHelper();
49 49 $toolbarHelper->addSearchBar($data['search'], 'users_search');
50 50 $toolbarHelper->addOptionSelect(
@@ -84,28 +84,35 @@
84 84 'download'
85 85 );
86 86 $toolbarHelper->addButton(acym_translation('ACYM_IMPORT'), ['data-task' => 'import'], 'upload');
87 87 $entityHelper = new EntitySelectHelper();
88 - $otherContent = acym_modal(
89 - '<i class="acymicon-bell"></i>'.acym_translation('ACYM_SUBSCRIBE').' (<span id="acym__users__listing__number_to_add_to_list">0</span>)',
90 - $entityHelper->entitySelect('list', ['join' => ''], $entityHelper->getColumnsForList(), [
91 - 'text' => acym_translation('ACYM_SUBSCRIBE_USERS_TO_THESE_LISTS'),
92 - 'action' => 'addToList',
93 - ]),
94 - null,
95 - '',
88 + $toolbarHelper->addModalButton(
96 89 [
97 - 'class' => 'button button-secondary disabled cell medium-6 large-shrink',
98 - 'id' => 'acym__users__listing__button--add-to-list',
90 + 'button' => '<i class="acymicon-bell"></i>'.esc_html(
91 + acym_translation('ACYM_SUBSCRIBE')
92 + ).' (<span id="acym__users__listing__number_to_add_to_list">0</span>)',
93 + 'modalContent' => $entityHelper->entitySelect(
94 + [
95 + 'entity' => 'list',
96 + 'columnsToDisplay' => $entityHelper->getColumnsForList(),
97 + 'buttonSubmit' => [
98 + 'text' => acym_translation('ACYM_SUBSCRIBE_USERS_TO_THESE_LISTS'),
99 + 'action' => 'addToList',
100 + ],
101 + ]
102 + ),
103 + 'attributesButton' => [
104 + 'class' => 'button button-secondary disabled cell medium-6 large-shrink',
105 + 'id' => 'acym__users__listing__button--add-to-list',
106 + ],
99 107 ]
100 108 );
101 - $toolbarHelper->addOtherContent($otherContent);
102 109 $toolbarHelper->addButton(acym_translation('ACYM_CREATE'), ['data-task' => 'edit'], 'user-plus', true);
103 110
104 111 $data['toolbar'] = $toolbarHelper;
105 112 }
106 113
107 - protected function prepareListingFilters(&$data)
114 + protected function prepareListingFilters(array &$data): void
108 115 {
109 116 $data['status'] = $this->getVarFiltersListing('string', 'users_status', '');
110 117 $data['search'] = $this->getVarFiltersListing('string', 'users_search', '');
111 118 $data['list'] = $this->getVarFiltersListing('int', 'users_list', 0);
@@ -121,8 +128,9 @@
121 128 return strtolower($a->name) > strtolower($b->name) ? 1 : -1;
122 129 }
123 130 );
124 131
132 + // This keeps keys
125 133 $data['lists'] = [0 => acym_translation('ACYM_SELECT_A_LIST')];
126 134 foreach ($lists as $oneList) {
127 135 if ($oneList->type === ListClass::LIST_TYPE_FRONT) continue;
128 136 if ($oneList->type === ListClass::LIST_TYPE_FOLLOWUP) {
@@ -151,10 +159,11 @@
151 159 $data['status_toolbar'][] = $data['segment'];
152 160 }
153 161 }
154 162
155 - protected function prepareUsersListing(&$data)
163 + protected function prepareUsersListing(array &$data): void
156 164 {
165 + // Prepare the pagination
157 166 $usersPerPage = $data['pagination']->getListLimit();
158 167 $page = $this->getVarFiltersListing('int', 'users_pagination_page', 1);
159 168
160 169 $matchingUsers = $this->getMatchingElementsFromData(
@@ -173,15 +182,16 @@
173 182 $data['status'],
174 183 $page
175 184 );
176 185
177 - $data['pagination']->setStatus($matchingUsers['total'], $page, $usersPerPage);
186 + // Prepare the pagination
187 + $data['pagination']->setStatus($matchingUsers['total']->total, $page, $usersPerPage);
178 188
179 189 $data['allUsers'] = $matchingUsers['elements'];
180 190 $data['userNumberPerStatus'] = $matchingUsers['status'];
181 191 }
182 192
183 - protected function prepareUsersSubscriptions(&$data)
193 + protected function prepareUsersSubscriptions(array &$data): void
184 194 {
185 195 $usersId = [];
186 196 foreach ($data['allUsers'] as $oneUser) {
187 197 $usersId[] = $oneUser->id;
@@ -200,9 +210,9 @@
200 210
201 211 $data['usersSubscriptions'] = $subscriptions;
202 212 }
203 213
204 - protected function prepareUsersFields(&$data)
214 + protected function prepareUsersFields(array &$data): void
205 215 {
206 216 $data['fields'] = [];
207 217
208 218 if (empty($data['allUsers'])) return;
@@ -232,19 +242,21 @@
232 242
233 243 $data['fields'] = $fieldsToDisplay['names'];
234 244 }
235 245
236 - public function addToList()
246 + public function addToList(): void
237 247 {
238 - $listsSelected = json_decode(acym_getVar('string', 'acym__entity_select__selected', '{}'));
239 - $userSelected = acym_getVar('array', 'elements_checked', []);
248 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
240 249
250 + $listsSelected = json_decode(acym_getVar('string', 'acym__entity_select__selected', '[]'), true);
251 + if (empty($listsSelected)) {
252 + $listsSelected = [];
253 + }
254 + $selectedUserIds = acym_getVar('array', 'elements_checked', []);
255 +
241 256 $userClass = new UserClass();
242 - $userClass->onlyManageableUsers($userSelected);
243 -
244 - foreach ($userSelected as $user) {
245 - $userClass->subscribe($user, $listsSelected);
246 - }
257 + $userClass->onlyManageableUsers($selectedUserIds);
258 + $userClass->subscribe($selectedUserIds, $listsSelected);
247 259
248 260 $this->listing();
249 261 }
250 262 }