| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Classes; |
| 4 |
|
| 5 |
use AcyMailing\Core\AcymClass; |
| 6 |
|
| 7 |
class ConditionClass extends AcymClass |
| 8 |
{ |
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
parent::__construct(); |
| 12 |
|
| 13 |
$this->table = 'condition'; |
| 14 |
$this->pkey = 'id'; |
| 15 |
} |
| 16 |
|
| 17 |
public function getOneByStepId($stepId) |
| 18 |
{ |
| 19 |
$query = 'SELECT * FROM #__acym_condition WHERE step_id = '.intval($stepId); |
| 20 |
|
| 21 |
return acym_loadObject($query); |
| 22 |
} |
| 23 |
|
| 24 |
public function delete($elements) |
| 25 |
{ |
| 26 |
if (empty($elements)) return 0; |
| 27 |
|
| 28 |
if (!is_array($elements)) $elements = [$elements]; |
| 29 |
acym_arrayToInteger($elements); |
| 30 |
|
| 31 |
$actionClass = new ActionClass(); |
| 32 |
$actionsIds = $actionClass->getAllActionsIdByConditionsId($elements); |
| 33 |
if (!empty($actionsIds)) $actionClass->delete($actionsIds); |
| 34 |
|
| 35 |
return parent::delete($elements); |
| 36 |
} |
| 37 |
|
| 38 |
public function save($condition) |
| 39 |
{ |
| 40 |
foreach ($condition as $oneAttribute => $value) { |
| 41 |
if (empty($value)) { |
| 42 |
continue; |
| 43 |
} |
| 44 |
|
| 45 |
if (is_array($value)) { |
| 46 |
$value = json_encode($value); |
| 47 |
} |
| 48 |
if ($oneAttribute != 'conditions') $condition->$oneAttribute = strip_tags($value); |
| 49 |
} |
| 50 |
|
| 51 |
return parent::save($condition); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 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); |
| 58 |
|
| 59 |
return acym_loadObjectList($query); |
| 60 |
} |
| 61 |
} |
| 62 |
|