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/UserStatClass.php +30 -12 10.11.1 → 11.1.0 View file →
@@ -36,10 +36,10 @@
36 36
37 37 $query = 'INSERT INTO #__acym_user_stat ('.implode(',', $column).') VALUE ('.implode(', ', $valueColumn).')';
38 38 $onDuplicate = [];
39 39
40 - if (!empty($userStat['statusSending'])) {
41 - $onDuplicate[] = $userStat['statusSending'] == 0 ? 'fail = fail + 1' : 'sent = sent + 1';
40 + if (isset($userStat['statusSending'])) {
41 + $onDuplicate[] = empty($userStat['statusSending']) ? 'fail = fail + 1' : 'sent = sent + 1';
42 42 }
43 43
44 44 if ($overrideSendDate && !empty($userStat['send_date'])) {
45 45 $onDuplicate[] = 'send_date = '.acym_escapeDB($userStat['send_date']);
@@ -46,13 +46,8 @@
46 46 }
47 47
48 48 if (!empty($userStat['open'])) {
49 49 $onDuplicate[] = 'open = open + 1';
50 - $automationClass = new AutomationClass();
51 - $automationClass->trigger('user_open', ['userId' => $userStat['user_id'], 'mailId' => $userStat['mail_id']]);
52 -
53 - $scenarioHelper = new ScenarioHelper();
54 - $scenarioHelper->trigger('user_open', ['userId' => $userStat['user_id'], 'mailId' => $userStat['mail_id']]);
55 50 }
56 51
57 52 if (!empty($userStat['open_date'])) {
58 53 $onDuplicate[] = 'open_date = '.acym_escapeDB($userStat['open_date']);
@@ -85,8 +80,16 @@
85 80
86 81 return (int)acym_query($query);
87 82 }
88 83
84 + public static function triggerActivity(string $event, int $userId, int $mailId): void
85 + {
86 + $payload = ['userId' => $userId, 'mailId' => $mailId];
87 +
88 + (new AutomationClass())->trigger($event, $payload);
89 + (new ScenarioHelper())->trigger($event, $payload);
90 + }
91 +
89 92 public function getOneByMailAndUserId(int $mailId, int $userId): ?object
90 93 {
91 94 $userStat = acym_loadObject('SELECT * FROM #__acym_user_stat WHERE `mail_id` = '.intval($mailId).' AND `user_id` = '.intval($userId));
92 95
@@ -183,13 +186,15 @@
183 186
184 187 $totalClicksForMails = [];
185 188 $campaignsForMails = [];
186 189 foreach ($mails as $key => $mail) {
190 + // Add tracked income amount
187 191 if (!empty($trackingSales[$mail->mail_id.'-'.$mail->user_id])) {
188 192 acym_trigger('getCurrency', [&$mails[$key]->currency]);
189 193 $mails[$key]->sales = $trackingSales[$mail->mail_id.'-'.$mail->user_id]->sale;
190 194 }
191 195
196 + // Add total clicks
192 197 if (!isset($totalClicksForMails[$mail->mail_id])) {
193 198 $totalClicksForMails[$mail->mail_id] = acym_loadObjectList(
194 199 'SELECT SUM(click) AS nbClicks, user_id
195 200 FROM #__acym_url_click
@@ -199,8 +204,9 @@
199 204 );
200 205 }
201 206 $mails[$key]->total_click = empty($totalClicksForMails[$mail->mail_id][$mail->user_id]) ? 0 : $totalClicksForMails[$mail->mail_id][$mail->user_id]->nbClicks;
202 207
208 + // Handle multilingual
203 209 $mainMailId = empty($mail->parent_id) ? $mail->mail_id : $mail->parent_id;
204 210 if (!isset($campaignsForMails[$mainMailId])) {
205 211 $campaignsForMails[$mainMailId] = acym_loadObject('SELECT id AS campaign_id, parent_id FROM #__acym_campaign WHERE mail_id = '.intval($mainMailId));
206 212 }
@@ -223,14 +229,14 @@
223 229 $offsetSeconds = acym_getTimeOffsetCMS();
224 230
225 231 return [
226 232 'total_open' => acym_loadResult(
227 - 'SELECT SUM(`open`)
228 - FROM #__acym_user_stat
233 + 'SELECT SUM(`open`)
234 + FROM #__acym_user_stat
229 235 WHERE open_date IS NOT NULL '.$specificMailsCondition
230 236 ),
231 237 'stats' => acym_loadObjectList(
232 - 'SELECT
238 + 'SELECT
233 239 SUM(`open`) AS `open_total`,
234 240 DATE_FORMAT(DATE_ADD(open_date, INTERVAL '.$offsetSeconds.' SECOND), "%w") AS `day`,
235 241 FORMAT(CONVERT(DATE_FORMAT(DATE_ADD(open_date, INTERVAL '.$offsetSeconds.' SECOND), "%H"), SIGNED INTEGER) / 3, 0) AS `hour`,
236 242 CONCAT(
@@ -238,9 +244,9 @@
238 244 "_",
239 245 FORMAT(CONVERT(DATE_FORMAT(DATE_ADD(open_date, INTERVAL '.$offsetSeconds.' SECOND), "%H"), SIGNED INTEGER) / 3, 0)
240 246 ) AS `date_id`
241 247 FROM `#__acym_user_stat`
242 - WHERE open_date IS NOT NULL '.$specificMailsCondition.'
248 + WHERE open_date IS NOT NULL '.$specificMailsCondition.'
243 249 GROUP BY date_id',
244 250 'date_id'
245 251 ),
246 252 ];
@@ -328,9 +334,9 @@
328 334 6 => [1, 2],
329 335 7 => [0, 2],
330 336 ];
331 337
332 - $percentage = rand($randoms[$hour][0], $randoms[$hour][1]);
338 + $percentage = acym_rand($randoms[$hour][0], $randoms[$hour][1]);
333 339
334 340 if ($percentageRemaining - $percentage < 0) {
335 341 return 0;
336 342 }
@@ -337,6 +343,18 @@
337 343
338 344 $percentageRemaining -= $percentage;
339 345
340 346 return $percentage;
347 + }
348 +
349 + public function hasUserReceivedMail(int $mailId, int $userId): bool
350 + {
351 + $sentToRecipient = acym_loadResult(
352 + 'SELECT COUNT(*)
353 + FROM #__acym_user_stat AS userStat
354 + WHERE userStat.mail_id = '.intval($mailId).'
355 + AND userStat.user_id = '.intval($userId)
356 + );
357 +
358 + return !empty($sentToRecipient);
341 359 }
342 360 }