| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Classes; |
| 4 |
|
| 5 |
use AcyMailing\Core\AcymClass; |
| 6 |
|
| 7 |
class ActionClass extends AcymClass |
| 8 |
{ |
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
parent::__construct(); |
| 12 |
|
| 13 |
$this->table = 'action'; |
| 14 |
$this->pkey = 'id'; |
| 15 |
$this->intColumns = [ |
| 16 |
'id', |
| 17 |
'condition_id', |
| 18 |
'order', |
| 19 |
]; |
| 20 |
} |
| 21 |
|
| 22 |
public function getActionsByStepId(int $stepId): array |
| 23 |
{ |
| 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 |
); |
| 31 |
|
| 32 |
array_map([$this, 'fixTypes'], $actions); |
| 33 |
|
| 34 |
return $actions; |
| 35 |
} |
| 36 |
|
| 37 |
public function getActionsByConditionId(int $id): array |
| 38 |
{ |
| 39 |
$actions = acym_loadObjectList( |
| 40 |
'SELECT action.* |
| 41 |
FROM #__acym_action as action |
| 42 |
WHERE action.condition_id = '.intval($id) |
| 43 |
); |
| 44 |
|
| 45 |
array_map([$this, 'fixTypes'], $actions); |
| 46 |
|
| 47 |
return $actions; |
| 48 |
} |
| 49 |
|
| 50 |
public function getOneByConditionId(int $id): ?object |
| 51 |
{ |
| 52 |
$action = acym_loadObject( |
| 53 |
'SELECT `action`.* |
| 54 |
FROM #__acym_action AS `action` |
| 55 |
WHERE `action`.`condition_id` = '.intval($id) |
| 56 |
); |
| 57 |
|
| 58 |
if (empty($action)) { |
| 59 |
return null; |
| 60 |
} |
| 61 |
|
| 62 |
$this->fixTypes($action); |
| 63 |
|
| 64 |
return $action; |
| 65 |
} |
| 66 |
|
| 67 |
public function getAllActionsIdByConditionsId(array $elements): array |
| 68 |
{ |
| 69 |
if (empty($elements)) { |
| 70 |
return []; |
| 71 |
} |
| 72 |
|
| 73 |
acym_arrayToInteger($elements); |
| 74 |
$ids = acym_loadResultArray('SELECT id FROM #__acym_action WHERE condition_id IN ('.implode(',', $elements).')'); |
| 75 |
acym_arrayToInteger($ids); |
| 76 |
|
| 77 |
return $ids; |
| 78 |
} |
| 79 |
|
| 80 |
public function delete(array $elements): int |
| 81 |
{ |
| 82 |
acym_arrayToInteger($elements); |
| 83 |
if (empty($elements)) return 0; |
| 84 |
$actions = acym_loadObjectList('SELECT * FROM #__acym_action WHERE id IN ('.implode(',', $elements).')'); |
| 85 |
if (empty($actions)) return 0; |
| 86 |
|
| 87 |
$mailClass = new MailClass(); |
| 88 |
|
| 89 |
foreach ($actions as $action) { |
| 90 |
$action->actions = json_decode($action->actions, true); |
| 91 |
if (!empty($action->actions)) { |
| 92 |
foreach ($action->actions as $innerAction) { |
| 93 |
if (!empty($innerAction['acy_add_queue']) && !empty($innerAction['acy_add_queue']['mail_id'])) $mailClass->delete([$innerAction['acy_add_queue']['mail_id']]); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
return parent::delete($elements); |
| 99 |
} |
| 100 |
|
| 101 |
public function save(object $element): ?int |
| 102 |
{ |
| 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` = '.$id |
| 120 |
); |
| 121 |
array_map([$this, 'fixTypes'], $actions); |
| 122 |
|
| 123 |
return $actions; |
| 124 |
} |
| 125 |
} |
| 126 |
|