From 259effc235e72013525e1533676227e0588d2258 Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Fri, 27 Nov 2015 09:37:19 -0500 Subject: [PATCH] Get bundled notifications count Utility functions to get the count of bundled notifications for display and plural purposes. Change-Id: I74d5ad244dec337a94e59c2118c33e474cd76797 --- .../formatters/EventPresentationModel.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/includes/formatters/EventPresentationModel.php b/includes/formatters/EventPresentationModel.php index 163f582b4..b8c7525de 100644 --- a/includes/formatters/EventPresentationModel.php +++ b/includes/formatters/EventPresentationModel.php @@ -109,6 +109,46 @@ abstract class EchoEventPresentationModel { return $this->bundledEvents; } + /** + * @return bool Whether there is other notifications bundled with this one. + */ + final protected function isBundled() { + return $this->getBundleCount() > 1; + } + + /** + * @param bool $includeCurrent + * @return int Number of bundled events, potentially capped to $cap + */ + final protected function getBundleCount( $includeCurrent = true ) { + $count = count( $this->getBundledEvents() ); + if ( $includeCurrent ) { + $count++; + } + return $count; + } + + /** + * Return the count of notifications bundled together. + * @param bool $includeCurrent + * @return array ['number for display', 'number for PLURAL'] + */ + final protected function getNotificationCountForOutput( $includeCurrent = true ) { + global $wgEchoMaxNotificationCount; + $count = $this->getBundleCount( $includeCurrent ); + if ( $count > $wgEchoMaxNotificationCount ) { + return array( + $this->msg( 'echo-notification-count' )->numParams( $wgEchoMaxNotificationCount )->text(), + $wgEchoMaxNotificationCount + ); + } else { + return array( + $this->language->formatNum( $count ), + $count + ); + } + } + /** * @return string The symbolic icon name as defined in $wgEchoNotificationIcons */