PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.2.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.2.2
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
acymailing / back / Classes / MailboxClass.php

MailboxClass.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.2.2, at back/Classes/MailboxClass.php

124 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Classes;
4
5 use AcyMailing\Helpers\PaginationHelper;
6 use AcyMailing\Core\AcymClass;
7
8 class MailboxClass extends AcymClass
9 {
10 public function __construct()
11 {
12 parent::__construct();
13
14 $this->table = 'mailbox_action';
15 $this->pkey = 'id';
16 }
17
18 public function getMatchingElements(array $settings = []): array
19 {
20 $query = 'SELECT * FROM #__acym_mailbox_action';
21 $queryCount = 'SELECT COUNT(id) AS total, SUM(active) AS totalActive FROM #__acym_mailbox_action';
22
23 if (!empty($settings['search'])) {
24 $filters[] = 'name LIKE '.acym_escapeDB('%'.$settings['search'].'%');
25 }
26
27 if (!empty($filters)) {
28 $queryCount .= ' WHERE ('.implode(') AND (', $filters).')';
29 }
30
31 if (!empty($settings['status'])) {
32 $filters[] = 'active = '.($settings['status'] == 'active' ? '1' : '0');
33 }
34
35 if (!empty($filters)) {
36 $query .= ' WHERE ('.implode(') AND (', $filters).')';
37 }
38
39 if (!empty($settings['ordering']) && !empty($settings['ordering_sort_order'])) {
40 $query .= ' ORDER BY '.acym_secureDBColumn($settings['ordering']).' '.acym_secureDBColumn(strtoupper($settings['ordering_sort_order']));
41 } else {
42 $query .= ' ORDER BY id asc';
43 }
44
45 if (empty($settings['offset']) || $settings['offset'] < 0) {
46 $settings['offset'] = 0;
47 }
48
49 if (empty($settings['elementsPerPage']) || $settings['elementsPerPage'] < 1) {
50 $pagination = new PaginationHelper();
51 $settings['elementsPerPage'] = $pagination->getListLimit();
52 }
53
54 return [
55 'elements' => acym_loadObjectList($query, '', $settings['offset'], $settings['elementsPerPage']),
56 'total' => acym_loadObject($queryCount),
57 ];
58 }
59
60 public function duplicate($mailboxIds)
61 {
62 if (empty($mailboxIds)) {
63 return;
64 }
65
66 if (!is_array($mailboxIds)) {
67 $mailboxIds = [$mailboxIds];
68 }
69
70 $duplicateErrors = [];
71 foreach ($mailboxIds as $mailboxId) {
72 $mailbox = $this->getOneById($mailboxId);
73
74 if (empty($mailbox)) {
75 continue;
76 }
77
78 $originalName = $mailbox->name;
79 unset($mailbox->id);
80 $mailbox->active = 0;
81 $mailbox->name .= '_copy';
82
83 if (empty($this->save($mailbox))) {
84 $duplicateErrors[] = acym_translationSprintf('ACYM_ERROR_DUPLICATING_MAILBOX_ACTION', $originalName);
85 }
86 }
87
88 if (!empty($duplicateErrors)) {
89 acym_enqueueMessage($duplicateErrors, 'error');
90 }
91 }
92
93 public function getOneById($id)
94 {
95 $mailbox = acym_loadObject('SELECT * FROM #__acym_mailbox_action WHERE `id` = '.intval($id));
96
97 if (!empty($mailbox)) {
98 $mailbox->conditions = json_decode($mailbox->conditions, true);
99 $mailbox->actions = json_decode($mailbox->actions, true);
100 }
101
102 return $mailbox;
103 }
104
105 public function getAllActiveReadyWithActions(): array
106 {
107 $mailboxes = acym_loadObjectList('SELECT * FROM #__acym_mailbox_action WHERE active = 1 AND nextdate < '.time().' AND actions IS NOT NULL ORDER BY id ASC');
108
109 if (empty($mailboxes)) {
110 return [];
111 }
112
113 return array_map([$this, 'decodeMailbox'], $mailboxes);
114 }
115
116 public function decodeMailbox($mailbox)
117 {
118 $mailbox->conditions = json_decode($mailbox->conditions, true);
119 $mailbox->actions = json_decode($mailbox->actions, true);
120
121 return $mailbox;
122 }
123 }
124