PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.1
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 / Controllers / Queue / Campaigns.php

Campaigns.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.0.1, at back/Controllers/Queue/Campaigns.php

153 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers\Queue;
4
5 use AcyMailing\Classes\CampaignClass;
6 use AcyMailing\Classes\QueueClass;
7 use AcyMailing\Classes\TagClass;
8 use AcyMailing\Helpers\PaginationHelper;
9 use AcyMailing\Helpers\ToolbarHelper;
10 use AcyMailing\Helpers\WorkflowHelper;
11
12 trait Campaigns
13 {
14 public function campaigns()
15 {
16 acym_setVar('layout', 'campaigns');
17
18 if (ACYM_PRODUCTION) {
19 if (acym_level(ACYM_ESSENTIAL) && $this->config->get('cron_last', 0) < (time() - 43200)) {
20 $message = acym_translation('ACYM_CREATE_CRON_REMINDER');
21 $message .= ' <a id="acym__queue__configure-cron" href="'.acym_completeLink('configuration&tab=license').'">'.acym_translation('ACYM_GOTO_CONFIG').'</a>';
22
23 acym_enqueueMessage($message, 'warning');
24 }
25 }
26
27 $searchFilter = $this->getVarFiltersListing('string', 'cqueue_search', '');
28 $tagFilter = $this->getVarFiltersListing('string', 'cqueue_tag', '');
29 $status = $this->getVarFiltersListing('string', 'cqueue_status', '');
30
31 $pagination = new PaginationHelper();
32 $campaignsPerPage = $pagination->getListLimit();
33 $page = $this->getVarFiltersListing('int', 'cqueue_pagination_page', 1);
34
35 $queueClass = new QueueClass();
36 $matchingElements = $queueClass->getMatchingCampaigns(
37 [
38 'search' => $searchFilter,
39 'tag' => $tagFilter,
40 'status' => $status,
41 'campaignsPerPage' => $campaignsPerPage,
42 'offset' => ($page - 1) * $campaignsPerPage,
43 ]
44 );
45
46 $pagination->setStatus($matchingElements['total'], $page, $campaignsPerPage);
47 $tagClass = new TagClass();
48
49 $viewData = [
50 'allElements' => $matchingElements['elements'],
51 'pagination' => $pagination,
52 'search' => $searchFilter,
53 'tag' => $tagFilter,
54 'allTags' => $tagClass->getAllTagsByType(TagClass::TYPE_MAIL),
55 'numberPerStatus' => $matchingElements['status'],
56 'status' => $status,
57 'campaignClass' => new CampaignClass(),
58 'languages' => acym_getLanguages(),
59 'workflowHelper' => new WorkflowHelper(),
60 ];
61
62 $this->prepareToolbar($viewData);
63
64 $this->breadcrumb[acym_translation('ACYM_MAILS')] = acym_completeLink('queue');
65 parent::display($viewData);
66 }
67
68 public function prepareToolbar(&$data)
69 {
70 $toolbarHelper = new ToolbarHelper();
71 $toolbarHelper->addSearchBar($data['search'], 'cqueue_search', 'ACYM_SEARCH');
72 $toolbarHelper->addButton(
73 acym_translation('ACYM_EMPTY_QUEUE'),
74 [
75 'data-task' => 'emptyQueue',
76 'data-confirmation-message' => 'ACYM_ARE_YOU_SURE',
77 ],
78 'close'
79 );
80 $otherContent = acym_modal(
81 '<i class="acymicon-paper-plane"></i>'.acym_translation('ACYM_SEND_MAILS_MANUALLY'),
82 '',
83 null,
84 'data-reveal-larger',
85 'class="cell medium-6 large-shrink button" data-reload="true" data-ajax="true" data-iframe="&ctrl=queue&task=continuesend&id=0&totalsend=0"'
86 );
87 $toolbarHelper->addOtherContent($otherContent);
88 $toolbarHelper->addFilterByTag($data, 'cqueue_tag', 'acym__queue__filter__tags acym__select');
89
90 $data['toolbar'] = $toolbarHelper;
91 if (!empty($data['tag'])) {
92 $data['status_toolbar'] = [
93 'cqueue_tag' => $data['tag'],
94 ];
95 }
96 }
97
98 public function cancelSending()
99 {
100 $mailId = acym_getVar('int', 'acym__queue__cancel__mail_id');
101
102 if (!empty($mailId)) {
103 $hasStat = acym_loadResult('SELECT COUNT(*) FROM #__acym_user_stat WHERE mail_id = '.intval($mailId));
104
105 acym_query('DELETE FROM #__acym_queue WHERE mail_id = '.intval($mailId));
106 acym_query('UPDATE #__acym_mail_stat SET total_subscribers = sent WHERE mail_id = '.intval($mailId));
107 acym_query('UPDATE #__acym_campaign SET active = 1 WHERE mail_id = '.intval($mailId));
108 if (empty($hasStat)) {
109 acym_query('UPDATE #__acym_campaign SET draft = "1", sent = "0", sending_date = NULL WHERE mail_id = '.intval($mailId));
110 acym_query('DELETE FROM #__acym_mail_stat WHERE mail_id = '.intval($mailId));
111 }
112 } else {
113 acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_CANCEL_CAMPAIGN'), 'error');
114 }
115 }
116
117 public function cancelCampaignSending()
118 {
119 $this->cancelSending();
120 $this->campaigns();
121 }
122
123 public function playPauseSending()
124 {
125 $active = acym_getVar('int', 'acym__queue__play_pause__active__new_value');
126 $campaignId = acym_getVar('int', 'acym__queue__play_pause__campaign_id');
127
128 if (!empty($campaignId)) {
129 $queueClass = new QueueClass();
130 $queueClass->unpauseCampaign($campaignId, $active);
131 } else {
132 if (!empty($active)) {
133 acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_RESUME'), 'error');
134 } else {
135 acym_enqueueMessage(acym_translation('ACYM_ERROR_QUEUE_PAUSE'), 'error');
136 }
137 }
138
139 $this->campaigns();
140 }
141
142 public function emptyQueue()
143 {
144 acym_checkToken();
145
146 $queueClass = new QueueClass();
147 $deleted = $queueClass->emptyQueue();
148 acym_enqueueMessage(acym_translationSprintf('ACYM_EMAILS_REMOVED_QUEUE', $deleted));
149
150 $this->campaigns();
151 }
152 }
153