PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
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 10.3.0 10.4.0 All 60 releases
acymailing / back / dynamics / segment / SegmentAutomationFilters.php

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

83 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 public function onAcymDeclareFilters(array &$filters): void
9 {
10 $segmentClass = new SegmentClass();
11 $segments = $segmentClass->getAll();
12 $selectOptionSegment = [];
13 foreach ($segments as $oneSegment) {
14 $selectOptionSegment[] = acym_selectOption($oneSegment->id, $oneSegment->name);
15 }
16
17 $filters['acy_segment'] = new stdClass();
18 $filters['acy_segment']->name = acym_translation('ACYM_ACYMAILING_SEGMENT');
19 $filters['acy_segment']->option = '<div class="intext_select_automation cell">';
20 $filters['acy_segment']->option .= acym_select(
21 $selectOptionSegment,
22 'acym_action[filters][__numor__][__numand__][acy_segment][id]',
23 null,
24 [
25 'class' => 'intext_select_automation acym__select',
26 ]
27 );
28 $filters['acy_segment']->option .= '</div>';
29 }
30
31 public function onAcymProcessFilterCount_acy_segment(&$query, &$options, &$num)
32 {
33 $this->onAcymProcessFilter_acy_segment($query, $options, $num);
34
35 return acym_translationSprintf('ACYM_SELECTED_USERS', $query->count());
36 }
37
38 public function onAcymProcessFilter_acy_segment(&$query, &$options, $num)
39 {
40 $segmentClass = new SegmentClass();
41 $oneSegment = $segmentClass->getOneById($options['id']);
42
43 $automationHelpers = [];
44 if (!empty($oneSegment->filters)) {
45 foreach ($oneSegment->filters as $or => $orValues) {
46 if (empty($orValues)) continue;
47
48 $automationHelpers[$or] = new AutomationHelper();
49 foreach ($orValues as $and => $andValues) {
50 $and = intval($and);
51 foreach ($andValues as $filterName => $filterOptions) {
52 acym_trigger('onAcymProcessFilter_'.$filterName, [&$automationHelpers[$or], &$filterOptions, $and.'_'.$or]);
53 }
54 }
55 }
56 }
57
58 $whereClauses = [];
59 foreach ($automationHelpers as $automationHelper) {
60 if (!empty($automationHelper->where)) {
61 $whereClauses[] = ' ('.implode(') AND (', $automationHelper->where).')';
62 }
63 if (!empty($automationHelper->join)) {
64 $query->join = array_merge($query->join, $automationHelper->join);
65 }
66 if (!empty($automationHelper->leftjoin)) {
67 $query->leftjoin = array_merge($query->leftjoin, $automationHelper->leftjoin);
68 }
69 }
70
71 if (!empty($whereClauses)) {
72 $query->where = array_merge($query->where, [implode(' OR ', $whereClauses)]);
73 }
74 }
75
76 public function onAcymDeclareSummary_filters(&$automation)
77 {
78 if (empty($automation['acy_segment'])) return;
79 $oneSegment = (new SegmentClass())->getOneById($automation['acy_segment']['id']);
80 $automation = acym_translationSprintf('ACYM_FILTER_ACY_SEGMENT_SUMMARY', $oneSegment->name);
81 }
82 }
83