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
← All changes | back/Classes/ActionClass.php +67 -19 10.0.1 → 11.1.0 View file →
@@ -11,45 +11,74 @@
11 11 parent::__construct();
12 12
13 13 $this->table = 'action';
14 14 $this->pkey = 'id';
15 + $this->intColumns = [
16 + 'id',
17 + 'condition_id',
18 + 'order',
19 + ];
15 20 }
16 21
17 - public function getActionsByStepId($stepId)
22 + public function getActionsByStepId(int $stepId): array
18 23 {
19 - $query = 'SELECT action.* FROM #__acym_action AS action LEFT JOIN #__acym_condition AS conditionT ON action.condition_id = conditionT.id WHERE conditionT.step_id = '.intval(
20 - $stepId
21 - ).' ORDER BY action.order';
24 + $actions = acym_loadObjectList(
25 + 'SELECT `action`.*
26 + FROM #__acym_action AS `action`
27 + LEFT JOIN #__acym_condition AS `conditionT` ON `action`.condition_id = `conditionT`.id
28 + WHERE `conditionT`.step_id = '.intval($stepId).'
29 + ORDER BY `action`.order'
30 + );
22 31
23 - return acym_loadObjectList($query);
32 + array_map([$this, 'fixTypes'], $actions);
33 +
34 + return $actions;
24 35 }
25 36
26 - public function getActionsByConditionId($id)
37 + public function getActionsByConditionId(int $id): array
27 38 {
28 - return acym_loadObjectList(
29 - 'SELECT action.*
30 - FROM #__acym_action as action
31 - WHERE action.condition_id = '.intval($id)
39 + $actions = acym_loadObjectList(
40 + 'SELECT *
41 + FROM #__acym_action
42 + WHERE condition_id = '.intval($id)
32 43 );
44 +
45 + array_map([$this, 'fixTypes'], $actions);
46 +
47 + return $actions;
33 48 }
34 49
35 - public function getOneByConditionId($id)
50 + public function getOneByConditionId(int $id): ?object
36 51 {
37 - return acym_loadObject(
52 + $action = acym_loadObject(
38 53 'SELECT `action`.*
39 54 FROM #__acym_action AS `action`
40 55 WHERE `action`.`condition_id` = '.intval($id)
41 56 );
57 +
58 + if (empty($action)) {
59 + return null;
60 + }
61 +
62 + $this->fixTypes($action);
63 +
64 + return $action;
42 65 }
43 66
44 - public function getAllActionsIdByConditionsId($elements)
67 + public function getAllActionsIdByConditionsId(array $elements): array
45 68 {
69 + if (empty($elements)) {
70 + return [];
71 + }
72 +
46 73 acym_arrayToInteger($elements);
74 + $ids = acym_loadResultArray('SELECT id FROM #__acym_action WHERE condition_id IN ('.implode(',', $elements).')');
75 + acym_arrayToInteger($ids);
47 76
48 - return acym_loadResultArray('SELECT id FROM #__acym_action WHERE condition_id IN ('.implode(',', $elements).')');
77 + return $ids;
49 78 }
50 79
51 - public function delete($elements)
80 + public function delete(array $elements): int
52 81 {
53 82 acym_arrayToInteger($elements);
54 83 if (empty($elements)) return 0;
55 84 $actions = acym_loadObjectList('SELECT * FROM #__acym_action WHERE id IN ('.implode(',', $elements).')');
@@ -60,9 +89,9 @@
60 89 foreach ($actions as $action) {
61 90 $action->actions = json_decode($action->actions, true);
62 91 if (!empty($action->actions)) {
63 92 foreach ($action->actions as $innerAction) {
64 - if (!empty($innerAction['acy_add_queue']) && !empty($innerAction['acy_add_queue']['mail_id'])) $mailClass->delete($innerAction['acy_add_queue']['mail_id']);
93 + if (!empty($innerAction['acy_add_queue']) && !empty($innerAction['acy_add_queue']['mail_id'])) $mailClass->delete([$innerAction['acy_add_queue']['mail_id']]);
65 94 }
66 95 }
67 96 }
68 97
@@ -68,10 +97,29 @@
68 97
69 98 return parent::delete($elements);
70 99 }
71 100
72 - public function save($element)
101 + public function save(object $element): ?int
73 102 {
74 - if (!isset($element->order)) $element->order = 1;
75 - parent::save($element);
103 + if (!isset($element->order)) {
104 + $element->order = 1;
105 + }
106 +
107 + return parent::save($element);
108 + }
109 +
110 + public function getActionsByAutomationId(int $id): array
111 + {
112 + $actions = acym_loadObjectList(
113 + 'SELECT action.*
114 + FROM `#__acym_action` AS `action`
115 + JOIN `#__acym_condition` AS `condition`
116 + ON `action`.`condition_id` = `condition`.`id`
117 + JOIN `#__acym_step` AS `step`
118 + ON `condition`.`step_id` = `step`.`id`
119 + WHERE `step`.`automation_id` = '.intval($id)
120 + );
121 + array_map([$this, 'fixTypes'], $actions);
122 +
123 + return $actions;
76 124 }
77 125 }