PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.11.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.11.1
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 10.11.1, at back/Controllers/Segments/Campaign.php

112 lines 3.9 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 $segmentId = acym_getVar('int', 'segmentId', 0);
78 $isExclude = acym_getVar('boolean', 'exclude', false);
79 $listsIds = json_decode(acym_getVar('string', 'lists', '[]'), true);
80 if (empty($listsIds)) {
81 $listsIds = [];
82 }
83
84 if (empty($segmentId)) {
85 acym_sendAjaxResponse('', ['count' => $this->countSegmentByParams([], $listsIds, $isExclude)]);
86 }
87 acym_sendAjaxResponse('', ['count' => $this->countSegmentById($segmentId, $listsIds, true, $isExclude)]);
88 }
89
90 public function saveFromCampaign(): void
91 {
92 $name = acym_getVar('string', 'segment_name', '');
93 $filters = acym_getVar('array', 'acym_action', []);
94
95 $segmentClass = new SegmentClass();
96
97 $segment = new \stdClass();
98
99 $segment->name = $name;
100 $segment->creation_date = acym_date('now', 'Y-m-d H:i:s');
101 $segment->active = 1;
102 $segment->filters = json_encode($filters['filters']);
103
104 $segmentId = $segmentClass->save($segment);
105 if (!empty($segmentId)) {
106 acym_sendAjaxResponse(acym_translation('ACYM_SEGMENT_WELL_SAVE'), ['segment_id' => $segmentId]);
107 } else {
108 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_SAVE_SEGMENT'), [], false);
109 }
110 }
111 }
112