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
acymailing / back / dynamics / segment / SegmentAutomationFilters.php

SegmentAutomationFilters.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.1.0, at back/dynamics/segment/SegmentAutomationFilters.php

90 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Classes\SegmentClass;
4 use AcyMailing\Helpers\AutomationHelper;
5
6 trait SegmentAutomationFilters
7 {
8 protected function initAutomationFilters(): void
9 {
10 $this->automationFilters['acy_segment'] = acym_translation('ACYM_ACYMAILING_SEGMENT');
11 }
12
13 public function displayFilterOptions_acy_segment(string $fieldName): void
14 {
15 $segmentClass = new SegmentClass();
16 $segments = $segmentClass->getAll();
17 $selectOptionSegment = [];
18 foreach ($segments as $oneSegment) {
19 $selectOptionSegment[] = acym_selectOption($oneSegment->id, $oneSegment->name);
20 }
21 ?>
22 <div class="intext_select_automation cell">
23 <?php acym_select(
24 $selectOptionSegment,
25 $fieldName.'[id]',
26 null,
27 ['class' => 'intext_select_automation acym__select'],
28 'value',
29 'text',
30 null,
31 false,
32 true
33 ); ?>
34 </div>
35 <?php
36 }
37
38 public function onAcymProcessFilterCount_acy_segment(&$query, &$options, &$num)
39 {
40 $this->onAcymProcessFilter_acy_segment($query, $options, $num);
41
42 return acym_translationSprintf('ACYM_SELECTED_USERS', $query->count());
43 }
44
45 public function onAcymProcessFilter_acy_segment(&$query, &$options, $num)
46 {
47 $segmentClass = new SegmentClass();
48 $oneSegment = $segmentClass->getOneById($options['id']);
49
50 $automationHelpers = [];
51 if (!empty($oneSegment->filters)) {
52 foreach ($oneSegment->filters as $or => $orValues) {
53 if (empty($orValues)) continue;
54
55 $automationHelpers[$or] = new AutomationHelper();
56 foreach ($orValues as $and => $andValues) {
57 $and = intval($and);
58 foreach ($andValues as $filterName => $filterOptions) {
59 acym_trigger('onAcymProcessFilter_'.$filterName, [&$automationHelpers[$or], &$filterOptions, $and.'_'.$or]);
60 }
61 }
62 }
63 }
64
65 $whereClauses = [];
66 foreach ($automationHelpers as $automationHelper) {
67 if (!empty($automationHelper->where)) {
68 $whereClauses[] = ' ('.implode(') AND (', $automationHelper->where).')';
69 }
70 if (!empty($automationHelper->join)) {
71 $query->join = array_merge($query->join, $automationHelper->join);
72 }
73 if (!empty($automationHelper->leftjoin)) {
74 $query->leftjoin = array_merge($query->leftjoin, $automationHelper->leftjoin);
75 }
76 }
77
78 if (!empty($whereClauses)) {
79 $query->where = array_merge($query->where, [implode(' OR ', $whereClauses)]);
80 }
81 }
82
83 public function onAcymDeclareSummary_filters(&$automation)
84 {
85 if (empty($automation['acy_segment'])) return;
86 $oneSegment = (new SegmentClass())->getOneById($automation['acy_segment']['id']);
87 $automation = acym_translationSprintf('ACYM_FILTER_ACY_SEGMENT_SUMMARY', $oneSegment->name);
88 }
89 }
90