PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
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 / Automations / Filter.php

Filter.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Controllers/Automations/Filter.php

132 lines 3.8 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\Automations;
4
5 use AcyMailing\Classes\ActionClass;
6 use AcyMailing\Classes\AutomationClass;
7 use AcyMailing\Classes\ConditionClass;
8 use AcyMailing\Classes\StepClass;
9 use AcyMailing\Helpers\AutomationHelper;
10 use AcyMailing\Helpers\WorkflowHelper;
11
12 trait Filter
13 {
14 public function filter(): void
15 {
16
17 if (!acym_level(ACYM_ENTERPRISE)) {
18 acym_redirect(acym_completeLink('dashboard&task=upgrade&version=enterprise', false, true));
19 }
20 }
21
22 private function _saveFilters(bool $isMassAction = false): array
23 {
24 $automationID = acym_getVar('int', 'id');
25 $actionId = acym_getVar('int', 'actionId');
26 $action = acym_getVar('array', 'acym_action', []);
27 $actionClass = new ActionClass();
28 $conditionId = acym_getVar('int', 'conditionId');
29
30 $stepAutomationId = acym_getVar('int', 'stepAutomationId');
31
32 if (!empty($stepAutomationId)) {
33 $stepAutomation['id'] = $stepAutomationId;
34 }
35
36 if (!empty($conditionId)) {
37 $action['condition_id'] = $conditionId;
38 }
39
40 if (!empty($actionId)) {
41 $action['id'] = $actionId;
42 }
43
44 $action['filters']['type_filter'] = acym_getVar('string', 'type_filter');
45
46 if ($isMassAction) {
47 acym_session();
48 $_SESSION['massAction']['filters'] = $action['filters'];
49
50 return [];
51 }
52
53 $action['filters'] = json_encode($action['filters']);
54
55 $action['order'] = 1;
56
57 foreach ($action as $column => $value) {
58 acym_secureDBColumn($column);
59 }
60
61 $action = (object)$action;
62
63 $action->id = $actionClass->save($action);
64
65 return [
66 'automationId' => $automationID,
67 'stepId' => $stepAutomationId,
68 'actionId' => $action->id,
69 ];
70 }
71
72 public function saveExitFilters(): void
73 {
74 $this->_saveFilters();
75
76 acym_enqueueMessage(acym_translation('ACYM_SUCCESSFULLY_SAVED'), 'success');
77
78 $this->listing();
79 }
80
81 public function saveFilters(): void
82 {
83 $ids = $this->_saveFilters();
84
85 acym_setVar('id', $ids['automationId']);
86 acym_setVar('stepId', $ids['stepId']);
87 acym_setVar('actionId', $ids['actionId']);
88 $this->summary();
89 }
90
91 public function countresults(): void
92 {
93 $or = acym_getVar('int', 'or');
94 $and = acym_getVar('int', 'and');
95 $stepAutomation = acym_getVar('array', 'acym_action');
96
97 if (empty($stepAutomation['filters'][$or][$and])) {
98 acym_sendAjaxResponse(acym_translation('ACYM_AUTOMATION_NOT_FOUND'), [], false);
99 }
100
101 $query = new AutomationHelper();
102
103 $filterName = key($stepAutomation['filters'][$or][$and]);
104 $options = current($stepAutomation['filters'][$or][$and]);
105 $messages = acym_trigger('onAcymProcessFilterCount_'.$filterName, [&$query, &$options, &$and]);
106
107 acym_sendAjaxResponse(implode(' | ', $messages));
108 }
109
110 public function countResultsOrTotal(): void
111 {
112 $or = acym_getVar('int', 'or');
113 $stepAutomation = acym_getVar('array', 'acym_action');
114
115 $query = new AutomationHelper();
116
117 if (!empty($stepAutomation) && !empty($stepAutomation['filters'][$or])) {
118 foreach ($stepAutomation['filters'][$or] as $and => $andValues) {
119 $and = intval($and);
120 foreach ($andValues as $filterName => $options) {
121 $options['countTotal'] = true;
122 acym_trigger('onAcymProcessFilter_'.$filterName, [&$query, &$options, &$and]);
123 }
124 }
125 }
126
127 $result = $query->count();
128
129 acym_sendAjaxResponse(acym_translationSprintf('ACYM_SELECTED_USERS_TOTAL', $result));
130 }
131 }
132