From 30b08859f8857f9f4befc2d6913284e4cc620a2c Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Mon, 21 Mar 2022 14:29:40 -0400 Subject: [PATCH] use standard CiviCRM status framework for new SMS notification With this change, the new SMS messages notification stops showing up on every page load and is incorporated into the standard CiviCRM status page. This reduces page clutter and user irritation. --- CRM/Smsinbox/Utils.php | 7 ++----- smsinbox.php | 33 ++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/CRM/Smsinbox/Utils.php b/CRM/Smsinbox/Utils.php index 1f6bd3e..549f731 100644 --- a/CRM/Smsinbox/Utils.php +++ b/CRM/Smsinbox/Utils.php @@ -10,11 +10,10 @@ class CRM_Smsinbox_Utils { * If there are unread SMS messages, this displays a message. */ public static function checkForUnreadMessageStatus() { - $unreadMessageCount = CRM_Smsinbox_SmsInbound::count_unread(); if (0 == $unreadMessageCount) { - return; + return NULL; } elseif (1 == $unreadMessageCount) { $message = 'You have one unread SMS message. Click here to read it.'; @@ -23,9 +22,7 @@ public static function checkForUnreadMessageStatus() { $message = 'You have %1 unread SMS messages. Click here to read them.'; } - CRM_Core_Session::setStatus(E::ts($message, array( - 1 => $unreadMessageCount, - )), '', 'info'); + return E::ts($message, [1 => $unreadMessageCount]); } public static function getDisplayNameWithFallback($contactId) { diff --git a/smsinbox.php b/smsinbox.php index c8e5a47..c97ed7c 100644 --- a/smsinbox.php +++ b/smsinbox.php @@ -180,12 +180,35 @@ function smsinbox_civicrm_navigationMenu(&$params) { * * @param type $page */ -function smsinbox_civicrm_pageRun(&$page) { - if (get_class($page) == 'CRM_Smsinbox_Page_SmsInbox') { +function smsinbox_civicrm_check(&$messages, $statusNames, $includeDisabled) { + // Early return if $statusNames doesn't call for our check + if ($statusNames && !in_array('smsinbox', $statusNames)) { return; } - - CRM_Smsinbox_Utils::checkForUnreadMessageStatus(); + if (!$includeDisabled) { + $disabled = \Civi\Api4\StatusPreference::get() + ->setCheckPermissions(FALSE) + ->addWhere('is_active', '=', FALSE) + ->addWhere('domain_id', '=', 'current_domain') + ->addWhere('name', '=', 'smsinbox') + ->execute()->count(); + if ($disabled) { + return; + } + } + $messageText = CRM_Smsinbox_Utils::checkForUnreadMessageStatus(); + + if ($messageText) { + $message = new CRM_Utils_Check_Message( + 'smsinbox', + $messageText, + E::ts('Unread SMSInbox messages'), + \Psr\Log\LogLevel::WARNING, + 'fa-flag' + ); + $message->addHelp(E::ts('You can read these messages by clicking the SMSInbox menu item from the Mailings menu.')); + $messages[] = $message; + } } /** @@ -199,4 +222,4 @@ function smsinbox_civicrm_buildForm($formName, &$form) { return; } CRM_Smsinbox_Utils::checkForUnreadMessageStatus(); -} \ No newline at end of file +}