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/ConditionClass.php +20 -15 10.2.2 → 11.1.0 View file →
@@ -13,20 +13,19 @@
13 13 $this->table = 'condition';
14 14 $this->pkey = 'id';
15 15 }
16 16
17 - public function getOneByStepId($stepId)
17 + public function getOneByStepId(int $stepId): ?object
18 18 {
19 - $query = 'SELECT * FROM #__acym_condition WHERE step_id = '.intval($stepId);
19 + $condition = acym_loadObject('SELECT * FROM #__acym_condition WHERE step_id = '.intval($stepId));
20 20
21 - return acym_loadObject($query);
21 + return empty($condition) ? null : $condition;
22 22 }
23 23
24 - public function delete($elements)
24 + public function delete(array $elements): int
25 25 {
26 26 if (empty($elements)) return 0;
27 27
28 - if (!is_array($elements)) $elements = [$elements];
29 28 acym_arrayToInteger($elements);
30 29
31 30 $actionClass = new ActionClass();
32 31 $actionsIds = $actionClass->getAllActionsIdByConditionsId($elements);
@@ -34,28 +33,34 @@
34 33
35 34 return parent::delete($elements);
36 35 }
37 36
38 - public function save($condition)
37 + public function save(object $element): ?int
39 38 {
40 - foreach ($condition as $oneAttribute => $value) {
39 + foreach ($element as $oneAttribute => $value) {
41 40 if (empty($value)) {
42 41 continue;
43 42 }
44 43
45 - if (is_array($value)) {
46 - $value = json_encode($value);
44 + if ($oneAttribute !== 'conditions') {
45 + $element->$oneAttribute = is_array($value) ? json_encode($value) : acym_stripTags($value);
47 46 }
48 - if ($oneAttribute != 'conditions') $condition->$oneAttribute = strip_tags($value);
49 47 }
50 48
51 - return parent::save($condition);
49 + return parent::save($element);
52 50 }
53 51
52 + public function getConditionsByStepId(int $id): array
53 + {
54 + $conditions = acym_loadObjectList(
55 + 'SELECT *
56 + FROM #__acym_condition
57 + WHERE `step_id` = '.intval($id)
58 + );
54 59
55 - public function getConditionsByStepId($id)
56 - {
57 - $query = 'SELECT acycondition.* FROM #__acym_condition as acycondition LEFT JOIN #__acym_step AS step ON step.id = acycondition.step_id WHERE step.id = '.intval($id);
60 + foreach ($conditions as $condition) {
61 + $condition->conditions = empty($condition->conditions) ? [] : json_decode($condition->conditions, true);
62 + }
58 63
59 - return acym_loadObjectList($query);
64 + return $conditions;
60 65 }
61 66 }