PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.3
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.3
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
acymailing / back / Controllers / Segments / Campaign.php

Campaign.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.3, at back/Controllers/Segments/Campaign.php

118 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers\Segments;
4
5 use AcyMailing\Classes\SegmentClass;
6 use AcyMailing\Helpers\AutomationHelper;
7
8 trait Campaign
9 {
10 public function countSegmentById(int $segmentId, array $listsIds, bool $ajax = true, bool $exclude = false): int
11 {
12 acym_arrayToInteger($listsIds);
13
14 if (empty($listsIds)) {
15 return 0;
16 }
17
18 if (empty($segmentId)) {
19 if ($ajax) {
20 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_COUNT_USER'), [], false);
21 } else {
22 return 0;
23 }
24 }
25
26 $segmentClass = new SegmentClass();
27 $segment = $segmentClass->getOneById($segmentId);
28 if (empty($segment)) {
29 if ($ajax) {
30 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_COUNT_USER'), [], false);
31 } else {
32 return 0;
33 }
34 }
35
36 $automationHelperBase = new AutomationHelper();
37 $automationHelperBase->removeFlag(self::FLAG_COUNT);
38
39 $automationHelpers = [];
40 foreach ($segment->filters as $or => $orValues) {
41 if (empty($orValues)) continue;
42 $automationHelpers[$or] = new AutomationHelper();
43 foreach ($orValues as $and => $andValues) {
44 $and = intval($and);
45 foreach ($andValues as $filterName => $options) {
46 acym_trigger('onAcymProcessFilter_'.$filterName, [&$automationHelpers[$or], &$options, $and.'_'.$or]);
47 }
48 }
49
50 $automationHelpers[$or]->excludeSelected = $exclude;
51 $automationHelpers[$or]->addFlag(self::FLAG_COUNT);
52 }
53
54 $join = ' #__acym_user_has_list AS user_list ON user_list.user_id = user.id ';
55 $join .= 'AND user_list.list_id IN ('.implode(',', $listsIds).') ';
56 $join .= 'AND user_list.status = 1 ';
57 if ($this->config->get('require_confirmation', 1) == 1) {
58 $join .= 'AND user.confirmed = 1 ';
59 }
60
61 if (empty($automationHelpers)) {
62 $automationHelperBase->join['user_list'] = $join;
63
64 return acym_loadResult($automationHelperBase->getQuery(['COUNT(DISTINCT user.id)']));
65 } else {
66 $automationHelperBase = array_pop($automationHelpers);
67 $automationHelperBase->join['user_list'] = $join;
68 $numberOfRecipients = acym_loadResult($automationHelperBase->getQuery(['COUNT(DISTINCT user.id)']));
69 $automationHelperBase->removeFlag(self::FLAG_COUNT);
70
71 return $numberOfRecipients;
72 }
73 }
74
75 public function countGlobalBySegmentId(): void
76 {
77 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
78
79 $segmentId = acym_getVar('int', 'segmentId', 0);
80 $isExclude = acym_getVar('boolean', 'exclude', false);
81 $listsIds = json_decode(acym_getVar('string', 'lists', '[]'), true);
82 if (empty($listsIds)) {
83 $listsIds = [];
84 }
85
86 if (empty($segmentId)) {
87 acym_sendAjaxResponse('', ['count' => $this->countSegmentByParams([], $listsIds, $isExclude)]);
88 }
89 acym_sendAjaxResponse('', ['count' => $this->countSegmentById($segmentId, $listsIds, true, $isExclude)]);
90 }
91
92 public function saveFromCampaign(): void
93 {
94 wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
95
96 $filters = acym_getVar('array', 'acym_action', []);
97 acym_blockRestrictedFilterAjax($filters);
98
99 $name = acym_getVar('string', 'segment_name', '');
100
101 $segmentClass = new SegmentClass();
102
103 $segment = new \stdClass();
104
105 $segment->name = $name;
106 $segment->creation_date = acym_date('now', 'Y-m-d H:i:s');
107 $segment->active = 1;
108 $segment->filters = json_encode($filters['filters']);
109
110 $segmentId = $segmentClass->save($segment);
111 if (!empty($segmentId)) {
112 acym_sendAjaxResponse(acym_translation('ACYM_SEGMENT_WELL_SAVE'), ['segment_id' => $segmentId]);
113 } else {
114 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_SAVE_SEGMENT'), [], false);
115 }
116 }
117 }
118