| 1 |
<?php |
| 2 |
|
| 3 |
namespace AcyMailing\Classes; |
| 4 |
|
| 5 |
use AcyMailing\Helpers\PaginationHelper; |
| 6 |
use AcyMailing\Core\AcymClass; |
| 7 |
|
| 8 |
class ScenarioProcessClass extends AcymClass |
| 9 |
{ |
| 10 |
public function __construct() |
| 11 |
{ |
| 12 |
parent::__construct(); |
| 13 |
|
| 14 |
$this->table = 'scenario_process'; |
| 15 |
$this->pkey = 'id'; |
| 16 |
} |
| 17 |
|
| 18 |
public function getOneByScenarioIdUserId(int $scenarioId, int $userId) |
| 19 |
{ |
| 20 |
$query = 'SELECT * FROM #__acym_scenario_process WHERE scenario_id = '.$scenarioId.' AND user_id = '.$userId; |
| 21 |
|
| 22 |
return acym_loadResult($query); |
| 23 |
} |
| 24 |
|
| 25 |
public function endProcess(int $scenarioProcessId) |
| 26 |
{ |
| 27 |
$scenarioProcess = new \stdClass(); |
| 28 |
$scenarioProcess->id = $scenarioProcessId; |
| 29 |
$scenarioProcess->end_at = acym_date('now', 'Y-m-d H:i:s', false); |
| 30 |
|
| 31 |
$this->save($scenarioProcess); |
| 32 |
} |
| 33 |
|
| 34 |
public function getNumberOfTriggerByScenarioId(int $scenarioId) |
| 35 |
{ |
| 36 |
$numberOfTrigger = acym_loadResult('SELECT COUNT(*) FROM #__acym_scenario_process WHERE scenario_id = '.$scenarioId); |
| 37 |
|
| 38 |
if (empty($numberOfTrigger)) { |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
return $numberOfTrigger; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
public function getMatchingElements(array $settings = []): array |
| 47 |
{ |
| 48 |
$results = []; |
| 49 |
|
| 50 |
$query = 'SELECT DISTINCT scenario_process.*, user.email FROM #__acym_scenario_process AS `scenario_process`'; |
| 51 |
$queryCount = 'SELECT COUNT(DISTINCT scenario_process.id) FROM #__acym_scenario_process AS scenario_process'; |
| 52 |
$filters = []; |
| 53 |
|
| 54 |
$joins = [ |
| 55 |
'JOIN #__acym_user AS user ON user.id = scenario_process.user_id', |
| 56 |
]; |
| 57 |
|
| 58 |
if (!empty($joins)) { |
| 59 |
$query .= ' '.implode(' ', $joins); |
| 60 |
$queryCount .= ' '.implode(' ', $joins); |
| 61 |
} |
| 62 |
|
| 63 |
if (!empty($settings['scenarioId'])) { |
| 64 |
$filters[] = 'scenario_process.scenario_id = '.intval($settings['scenarioId']); |
| 65 |
|
| 66 |
$results['totalOverall'] = acym_loadResult('SELECT COUNT(*) FROM #__acym_scenario_process WHERE scenario_id = '.intval($settings['scenarioId'])); |
| 67 |
} |
| 68 |
|
| 69 |
if (!empty($settings['search'])) { |
| 70 |
$searchValue = acym_escapeDB('%'.$settings['search'].'%'); |
| 71 |
$filters[] = 'user.name LIKE '.$searchValue.' OR user.email LIKE '.$searchValue; |
| 72 |
} |
| 73 |
|
| 74 |
if (!empty($filters)) { |
| 75 |
$query .= ' WHERE ('.implode(') AND (', $filters).')'; |
| 76 |
$queryCount .= ' WHERE ('.implode(') AND (', $filters).')'; |
| 77 |
} |
| 78 |
|
| 79 |
if (empty($settings['offset']) || $settings['offset'] < 0) { |
| 80 |
$settings['offset'] = 0; |
| 81 |
} |
| 82 |
|
| 83 |
if (empty($settings['elementsPerPage']) || $settings['elementsPerPage'] < 1) { |
| 84 |
$pagination = new PaginationHelper(); |
| 85 |
$settings['elementsPerPage'] = $pagination->getListLimit(); |
| 86 |
} |
| 87 |
|
| 88 |
$results['elements'] = acym_loadObjectList($query, 'id', $settings['offset'], $settings['elementsPerPage']); |
| 89 |
$results['total'] = acym_loadResult($queryCount); |
| 90 |
|
| 91 |
return $results; |
| 92 |
} |
| 93 |
} |
| 94 |
|