From 0dc3551138ab8269667d478a982a05cb5aeebab7 Mon Sep 17 00:00:00 2001 From: thisismeonmounteverest Date: Sat, 21 Oct 2023 22:33:30 +0200 Subject: [PATCH] Add SuspensionNotification Newsletter type. Only show hint to click if images aren't display if there are images. --- build/admin/massmail/adminmassmail.ctrl.php | 2 +- build/admin/massmail/adminmassmail.model.php | 103 +++++++++--------- .../massmail/pages/adminmassmailbase.page.php | 20 ++-- .../adminmassmaildetails.column_col3.php | 2 +- .../adminmassmaileditcreate.column_col3.php | 6 +- .../adminmassmailenqueue.column_col3.php | 50 ++++++--- src/Command/SendMassmailCommand.php | 24 +++- templates/emails/newsletter.html.twig | 4 +- 8 files changed, 123 insertions(+), 88 deletions(-) diff --git a/build/admin/massmail/adminmassmail.ctrl.php b/build/admin/massmail/adminmassmail.ctrl.php index 623dfdfd11..2f9b031fd2 100644 --- a/build/admin/massmail/adminmassmail.ctrl.php +++ b/build/admin/massmail/adminmassmail.ctrl.php @@ -197,9 +197,9 @@ public function massmailEnqueue() { $id = $this->route_vars['id']; $massmail = $this->model->getMassmail($id); $page = new AdminMassmailEnqueuePage($this->model, $massmail); - $page->votersCount = $this->model->getSuggestionsReminderCount(); $page->mailToConfirmCount = $this->model->getMailToConfirmCount(); $page->incorrectBirthDateCount = $this->model->getIncorrectBirthDateCount(); + $page->suspensionNotificationCount = $this->model->getSuspensionNotificationCount(); return $page; } diff --git a/build/admin/massmail/adminmassmail.model.php b/build/admin/massmail/adminmassmail.model.php index bc0fa255af..c676db0598 100644 --- a/build/admin/massmail/adminmassmail.model.php +++ b/build/admin/massmail/adminmassmail.model.php @@ -423,14 +423,14 @@ public function getEnqueueAction($vars) { $action = 'enqueueGroup'; } elseif (array_key_exists('enqueuereminder', $vars)) { $action = 'enqueueReminder'; - } elseif (array_key_exists('enqueuesuggestionsreminder', $vars)) { - $action = 'enqueueSuggestionsReminder'; } elseif (array_key_exists('enqueuemailtoconfirmreminder', $vars)) { $action = 'enqueueMailToConfirmReminder'; } elseif (array_key_exists('enqueuecorrectbday', $vars)) { $action = 'enqueueCorrectBirthDate'; } elseif (array_key_exists('enqueuetermsofuse', $vars)) { $action = 'enqueueTermsOfUse'; + } elseif (array_key_exists('enqueuesuspension', $vars)) { + $action = 'enqueueSuspensionNotification'; } return $action; } @@ -473,6 +473,7 @@ public function massmailEnqueueVarsOk(&$vars) { case 'enqueueMailToConfirmReminder': case 'enqueueTermsOfUse': case 'enqueueCorrectBirthDate': + case 'enqueueSuspensionNotification': break; default: $errors[] = 'AdminMassMailEnqueueWrongAction'; @@ -612,8 +613,7 @@ private function enqueueMassmailReminder($id) { return $count; } - private function enqueueMassmailSuggestionsReminder($id) { - $pref_id = $this->getPreferenceIdForMassmail($id); + private function enqueueMassmailMailToConfirmReminder($id) { $IdEnqueuer = $this->getLoggedInMember()->id; $query = " REPLACE @@ -622,22 +622,15 @@ private function enqueueMassmailSuggestionsReminder($id) { " . $id . ", m.id, " . $IdEnqueuer . ", 'ToApprove', NOW() FROM members AS m - LEFT JOIN - memberspreferences AS mp - ON (m.id = mp.IdMember AND mp.IdPreference = " . $pref_id . ") WHERE - m.Status = 'Active' - AND (mp.Value = 'Yes' OR mp.Value IS NULL) - AND DATEDIFF(NOW(), m.LastLogin) < 180 - ORDER BY - RAND() - LIMIT 0," . $this->getSuggestionsReminderCount(); + m.Status = 'MailToConfirm' + AND created BETWEEN '2015-01-01' AND (NOW() - INTERVAL 1 WEEK)"; $r = $this->dao->query($query); $count = $r->affectedRows(); return $count; } - private function enqueueMassmailMailToConfirmReminder($id) { + private function enqueueMassmailCorrectBirthDate($id) { $IdEnqueuer = $this->getLoggedInMember()->id; $query = " REPLACE @@ -647,14 +640,14 @@ private function enqueueMassmailMailToConfirmReminder($id) { FROM members AS m WHERE - m.Status = 'MailToConfirm' - AND created BETWEEN '2015-01-01' AND (NOW() - INTERVAL 1 WEEK)"; + m.Status IN ('Active', 'OutOfRemind') + AND BirthDate < '1922-06-22'"; $r = $this->dao->query($query); $count = $r->affectedRows(); return $count; } - private function enqueueMassmailCorrectBirthDate($id) { + private function enqueueSuspensionNotification($id) { $IdEnqueuer = $this->getLoggedInMember()->id; $query = " REPLACE @@ -664,10 +657,22 @@ private function enqueueMassmailCorrectBirthDate($id) { FROM members AS m WHERE - m.Status IN ('Active', 'OutOfRemind') - AND BirthDate < '1922-06-22'"; + m.Status IN ('OutOfRemind') + AND m.NbRemindWithoutLogingIn >= 5"; $r = $this->dao->query($query); $count = $r->affectedRows(); + + // Now set all those members to suspended + $query = " + UPDATE + members m + SET + m.status = 'SuspendedBeta' + WHERE + m.status = 'OutOfRemind' AND m.NbRemindWithoutLogingIn >= 5" + ; + $this->dao->query($query); + return $count; } @@ -725,15 +730,15 @@ public function enqueueMassmail($vars) { case 'enqueueReminder': $count = $this->enqueueMassmailReminder($id); break; - case 'enqueueSuggestionsReminder': - $count = $this->enqueueMassmailSuggestionsReminder($id); - break; case 'enqueueMailToConfirmReminder': $count = $this->enqueueMassmailMailToConfirmReminder($id); break; case 'enqueueCorrectBirthDate': $count = $this->enqueueMassmailCorrectBirthDate($id); break; + case 'enqueueSuspensionNotification': + $count = $this->enqueueSuspensionNotification($id); + break; case 'enqueueTermsOfUse': $count = $this->enqueueMassmailTermsOfUse($id); break; @@ -796,36 +801,6 @@ public function triggerMassMail($id) { return $r->affectedRows(); } - /** - * Get the count of members to be invited randomly - * - * Maximum number of votes ever casted for one suggestion times three - */ - public function getSuggestionsReminderCount() { - // fixed number of voters based on the number of members - // that voted for the decision making process - $votersCount = 763 * 3; - $query = " - SELECT - count(memberHash) as votersCount - FROM - suggestions_votes - GROUP BY - suggestionId, - optionId - ORDER BY - votersCount DESC - "; - $r = $this->dao->query($query); - if (!$r) { - return $votersCount; - } - $row = $r->fetch(PDB::FETCH_OBJ); - if (!isset($row->votersCount)) { - return $votersCount; - } - return $row->votersCount * 3; - } /** * Get the count of members with status MailToConfirm between January, 1st 2015 and now - 1 week @@ -874,4 +849,28 @@ public function getIncorrectBirthDateCount() { } return $row->incorrectBirthDateCount; } + + /** + * Get the count of members who will be suspended as they didn't react on 5 login reminders + */ + public function getSuspensionNotificationCount() { + $query = " + SELECT + count(*) as suspensionNotificationCount + FROM + members + WHERE + status IN ('OutOfRemind') + AND NbRemindWithoutLogingIn >= 5 + "; + $r = $this->dao->query($query); + if (!$r) { + return 0; + } + $row = $r->fetch(PDB::FETCH_OBJ); + if (!isset($row->suspensionNotificationCount)) { + return 0; + } + return $row->suspensionNotificationCount; + } } diff --git a/build/admin/massmail/pages/adminmassmailbase.page.php b/build/admin/massmail/pages/adminmassmailbase.page.php index 89d29fc2b0..3f928769a8 100644 --- a/build/admin/massmail/pages/adminmassmailbase.page.php +++ b/build/admin/massmail/pages/adminmassmailbase.page.php @@ -59,21 +59,22 @@ public function __construct($model) { $this->newsletterSpecific = (stripos($scope, '"specific"') !== false); $this->newsletterGeneral = (stripos($scope, '"general"') !== false); $this->loginReminder = (stripos($scope, '"remindtologin"') !== false); - $this->suggestionsReminder = (stripos($scope, '"suggestionsreminder"') !== false); $this->mailToConfirmReminder = (stripos($scope, '"mailtoconfirmreminder"') !== false); $this->correctBirthDate = (stripos($scope, '"correctbirthdate"') !== false); $this->termsOfUse = (stripos($scope, '"termsofuse"') !== false); + $this->suspendAfter5Reminders = (stripos($scope, '"suspendafter5reminders"') !== false); // if no type is set assume all - if (!($this->newsletterSpecific || $this->newsletterGeneral || $this->loginReminder || - $this->suggestionsReminder || $this->mailToConfirmReminder || $this->termsOfUse || $this->correctBirthDate)) { + if (!($this->newsletterSpecific || $this->newsletterGeneral || $this->loginReminder + || $this->mailToConfirmReminder || $this->termsOfUse + || $this->correctBirthDate || $this->suspendAfter5Reminders)) { $this->newsletterSpecific = true; $this->newsletterGeneral = true; $this->loginReminder = true; - $this->suggestionsReminder = true; $this->mailToConfirmReminder = true; $this->correctBirthDate = true; $this->termsOfUse = true; + $this->suspendAfter5Reminders = true; } $this->enqueueGroups = array(); $this->enqueueCountries = array(); @@ -105,23 +106,23 @@ public function __construct($model) { } } $this->canEnqueueReminder = (stripos($scope, "reminder") !== false); - $this->canEnqueueSuggestionsReminder = (stripos($scope, "suggestionsreminder") !== false); $this->canEnqueueMailToConfirmReminder = (stripos($scope, "mailtoconfirmreminder") !== false); $this->canEnqueueTermsOfUse = (stripos($scope, "termsofuse") !== false); // if no scope was given for enqueueing assume full scope $enqueueAny = $this->canEnqueueMembers || $this->canEnqueueLocation || $this->canEnqueueGroup - || $this->canEnqueueReminder || $this->canEnqueueSuggestionsReminder - || $this->canEnqueueMailToConfirmReminder || $this->canEnqueueTermsOfUse; + || $this->canEnqueueReminder || $this->canEnqueueMailToConfirmReminder + || $this->canEnqueueTermsOfUse || $this->canEnqueueSuspensionNotification + ; if ($enqueueAny == false) { $this->canEnqueueMembers = true; $this->canEnqueueLocation = true; $this->canEnqueueGroup = true; $this->canEnqueueReminder = true; $this->canEnqueueCorrectBirthDate = true; - $this->canEnqueueSuggestionsReminder = true; $this->canEnqueueMailToConfirmReminder = true; $this->canEnqueueTermsOfUse = true; + $this->canEnqueueSuspensionNotification = true; } if ($this->rights["MassMail"]["Level"] >= 1) { @@ -137,16 +138,15 @@ public function __construct($model) { $this->canEnqueueLocation = true; $this->canEnqueueGroup = true; $this->canEnqueueReminder = true; - $this->canEnqueueSuggestionsReminder = true; $this->canEnqueueMailToConfirmReminder = true; $this->canEnqueueTermsOfUse = true; $this->canEnqueueCorrectBirthDate = true; + $this->canEnqueueSuspensionNotification = true; $this->canChangeType = true; $this->canTrigger = true; $this->specificNewsletter = true; $this->generalNewsletter = true; $this->loginReminder = true; - $this->suggestionsReminder = true; $this->mailToConfirmReminder = true; $this->correctBirthDate = true; $this->termsOfUse = true; diff --git a/build/admin/massmail/templates/adminmassmaildetails.column_col3.php b/build/admin/massmail/templates/adminmassmaildetails.column_col3.php index 011dd54215..bae81d76f5 100644 --- a/build/admin/massmail/templates/adminmassmaildetails.column_col3.php +++ b/build/admin/massmail/templates/adminmassmaildetails.column_col3.php @@ -59,7 +59,7 @@ echo ''; } } - $purifier = MOD_htmlpure::getAdvancedHtmlPurifier(); + $purifier = (new MOD_htmlpure())->getAdvancedHtmlPurifier(); echo '' . $words->get('AdminMassMailSubject') . ': ' . str_replace("%username%", "Username", $words->getAsIs('BroadCast_Title_' . $massmail->Name)) . ''; diff --git a/build/admin/massmail/templates/adminmassmaileditcreate.column_col3.php b/build/admin/massmail/templates/adminmassmaileditcreate.column_col3.php index 26d1cad32f..92ce35aa4d 100644 --- a/build/admin/massmail/templates/adminmassmaileditcreate.column_col3.php +++ b/build/admin/massmail/templates/adminmassmaileditcreate.column_col3.php @@ -55,15 +55,15 @@ if ($this->loginReminder) { $options["RemindToLog"] = $this->words->getSilent('AdminMassMailEditTypeLoginReminder'); } - if ($this->suggestionsReminder) { - $options["SuggestionReminder"] = $this->words->getSilent('AdminMassMailEditTypeSuggestionsReminder'); - } if ($this->termsOfUse) { $options["TermsOfUse"] = $this->words->getSilent('AdminMassMailEditTypeTermsOfUse'); } if ($this->correctBirthDate) { $options["CorrectBirthDate"] = $this->words->getSilent('massmail.correct.birth.date'); } + if ($this->correctBirthDate) { + $options["SuspendAfter5Reminders"] = $this->words->getSilent('massmail.suspend.after.five.reminders'); + } if ($this->mailToConfirmReminder) { $options["MailToConfirmReminder"] = $this->words->getSilent('AdminMassMailEditTypeMailToConfirmReminder'); } diff --git a/build/admin/massmail/templates/adminmassmailenqueue.column_col3.php b/build/admin/massmail/templates/adminmassmailenqueue.column_col3.php index 02613d699e..643227cab9 100644 --- a/build/admin/massmail/templates/adminmassmailenqueue.column_col3.php +++ b/build/admin/massmail/templates/adminmassmailenqueue.column_col3.php @@ -29,9 +29,6 @@ case 'enqueueLoginReminder' : $activefieldset = 'reminder'; break; - case 'enqueueSuggestionReminder' : - $activefieldset = 'suggestionsreminder'; - break; case 'enqueueMailToConfirmReminder' : $activefieldset = 'mailtoconfirm'; break; @@ -41,6 +38,9 @@ case 'enqueueTermsOfUse' : $activefieldset = 'termsofuse'; break; + case 'enqueueSuspensionNotification' : + $activefieldset = 'suspension'; + break; } } else { if ($this->canEnqueueMembers) { @@ -55,6 +55,8 @@ $defaultfieldset = 'termsofuse'; } elseif ($this->canEnqueueCorrectBirthDate) { $defaultfieldset = 'correctbirthdate'; + } elseif ($this->canEnqueueSuspensionNotification) { + $defaultfieldset = 'suspension'; } } @@ -114,10 +116,18 @@ + type == 'SuspendAfter5Reminders' && $this->canEnqueueSuspensionNotification) { ?> + + -
+
canEnqueueMembers) { ?> -
+
/> -
- -
+
+
+
/> +
"/> get('AdminMassMailEnqueueUsernamesInfo'); ?>
-
flushBuffer(); ?>
@@ -212,7 +222,7 @@
type == 'RemindToLog' && $this->canEnqueueReminder) { ?> -
+
get('AdminMassMailEnqueueReminderInfo'); ?>
@@ -261,6 +271,18 @@
+ type == 'SuspendAfter5Reminders' && $this->canEnqueueSuspensionNotification) { ?> +
+
+

get('admin.massmail.suspension.notification.info'); ?>

+ Send notification that they were suspended to suspensionNotificationCount; ?> members. +

+
+

flushBuffer(); ?> +
+
+