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 / Classes / StepClass.php

StepClass.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.11.1, at back/Classes/StepClass.php

83 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Classes;
4
5 use AcyMailing\Core\AcymClass;
6
7 class StepClass extends AcymClass
8 {
9 public function __construct()
10 {
11 parent::__construct();
12
13 $this->table = 'step';
14 $this->pkey = 'id';
15 }
16
17 public function save(object $step): ?int
18 {
19 foreach ($step as $oneAttribute => $value) {
20 if (empty($value)) continue;
21
22 $step->$oneAttribute = is_array($value) ? json_encode($value) : strip_tags($value);
23 }
24
25 if (empty($step->name)) {
26 $step->name = 'step_'.time();
27 }
28
29 return parent::save($step);
30 }
31
32 public function getOneStepByAutomationId(int $automationId): ?object
33 {
34 $step = acym_loadObject('SELECT * FROM #__acym_step WHERE automation_id = '.intval($automationId));
35
36 return empty($step) ? null : $step;
37 }
38
39 public function getStepsByAutomationId(int $automationId): array
40 {
41 return acym_loadObjectList('SELECT * FROM #__acym_step WHERE automation_id = '.intval($automationId));
42 }
43
44 public function getActiveStepByTrigger(array $triggers): array
45 {
46 if (empty($triggers)) {
47 return [];
48 }
49
50 $query = 'SELECT step.*
51 FROM #__acym_step AS step
52 JOIN #__acym_automation AS automation ON step.automation_id = automation.id
53 WHERE automation.active = 1';
54
55 foreach ($triggers as $i => $oneTrigger) {
56 $triggers[$i] = 'step.triggers LIKE '.acym_escapeDB('%"'.$oneTrigger.'"%');
57 }
58 $query .= ' AND ('.implode(' OR ', $triggers).')';
59 $query .= ' ORDER BY automation.ordering ASC';
60
61 $steps = acym_loadObjectList($query);
62
63 foreach ($steps as $i => $oneStep) {
64 if (!empty($oneStep->triggers)) $steps[$i]->triggers = json_decode($oneStep->triggers, true);
65 }
66
67 return $steps;
68 }
69
70 public function delete(array $elements): int
71 {
72 if (empty($elements)) return 0;
73
74 acym_arrayToInteger($elements);
75
76 $conditions = acym_loadResultArray('SELECT id FROM #__acym_condition WHERE step_id IN ('.implode(',', $elements).')');
77 $conditionClass = new ConditionClass();
78 $conditionClass->delete($conditions);
79
80 return parent::delete($elements);
81 }
82 }
83