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/ScenarioHistoryLineClass.php +89 -0 10.10.1 → 11.1.0 View file →
@@ -1,0 +1,89 @@
1 +<?php
2 +
3 +namespace AcyMailing\Classes;
4 +
5 +use AcyMailing\Helpers\PaginationHelper;
6 +use AcyMailing\Core\AcymClass;
7 +
8 +class ScenarioHistoryLineClass extends AcymClass
9 +{
10 + public function __construct()
11 + {
12 + parent::__construct();
13 +
14 + $this->table = 'scenario_history_line';
15 + $this->pkey = 'id';
16 + }
17 +
18 + public function save(object $element): ?int
19 + {
20 + if (isset($element->params) && is_array($element->params)) {
21 + $element->params = json_encode($element->params);
22 + }
23 +
24 + return parent::save($element);
25 + }
26 +
27 + public function getAllByProcessId(int $processId): array
28 + {
29 + return array_map([$this, 'formatHistoryLine'], acym_loadObjectList('SELECT * FROM #__acym_scenario_history_line WHERE scenario_process_id = '.$processId, 'id'));
30 + }
31 +
32 + public function getMatchingElements(array $settings = []): array
33 + {
34 + $results = [];
35 +
36 + $query = 'SELECT history_line.*, `user`.email, `user`.id AS user_id FROM #__acym_scenario_history_line AS history_line';
37 + $queryCount = 'SELECT COUNT(history_line.id) AS total FROM #__acym_scenario_history_line AS history_line';
38 + $filters = [];
39 +
40 + $joins = [
41 + 'JOIN #__acym_scenario_process AS scenario_process ON history_line.scenario_process_id = scenario_process.id',
42 + 'JOIN #__acym_user AS `user` ON scenario_process.user_id = `user`.id',
43 + ];
44 +
45 + if (!empty($joins)) {
46 + $query .= ' '.implode(' ', $joins);
47 + $queryCount .= ' '.implode(' ', $joins);
48 + }
49 +
50 + if (!empty($settings['stepId'])) {
51 + $filters[] = 'history_line.scenario_step_id = '.acym_escapeDB($settings['stepId']);
52 +
53 + $results['totalOverall'] = acym_loadResult('SELECT COUNT(*) FROM #__acym_scenario_history_line WHERE scenario_step_id = '.acym_escapeDB($settings['stepId']));
54 + }
55 +
56 + if (!empty($settings['search'])) {
57 + $searchValue = acym_escapeDB('%'.$settings['search'].'%');
58 + $filters[] = 'user.name LIKE '.$searchValue.' OR user.email LIKE '.$searchValue;
59 + }
60 +
61 + if (!empty($filters)) {
62 + $query .= ' WHERE ('.implode(') AND (', $filters).')';
63 + $queryCount .= ' WHERE ('.implode(') AND (', $filters).')';
64 + }
65 +
66 + if (empty($settings['offset']) || $settings['offset'] < 0) {
67 + $settings['offset'] = 0;
68 + }
69 +
70 + if (empty($settings['elementsPerPage']) || $settings['elementsPerPage'] < 1) {
71 + $pagination = new PaginationHelper();
72 + $settings['elementsPerPage'] = $pagination->getListLimit();
73 + }
74 +
75 + $results['elements'] = acym_loadObjectList($query, 'id', $settings['offset'], $settings['elementsPerPage']);
76 + $results['total'] = acym_loadObject($queryCount);
77 +
78 + return $results;
79 + }
80 +
81 + private function formatHistoryLine(object $historyLine): object
82 + {
83 + if (!empty($historyLine->params)) {
84 + $historyLine->params = json_decode($historyLine->params);
85 + }
86 +
87 + return $historyLine;
88 + }
89 +}