/** * Get the list of usernames to display in the notification. * * 1 user: nameA * 2 users: nameA and nameB * 3 users: nameA, nameB and nameC * 4+ users: nameA, nameB, and 2+ others * * @return null|string */ protected function getUsernameText() { if ($userIds = $this->getFromUserIds()) { $userIdCount = count($userIds); $showUsernameCount = $userIdCount > 3 ? 2 : 3; $usernames = $this->getFromUsernames($showUsernameCount); if ($userIdCount <= 3) { $usernameStr = LangHelpers::naturalLanguageImplode($usernames); } else { $usernameStr = implode(', ', $usernames); $remaining = $userIdCount - $showUsernameCount; $usernameStr .= ', ' . Lang::get('notifications.andothers', ['count' => $remaining]); } return $usernameStr; } return null; }