From 6c6458156354d3694c26755b590e80fdade82e81 Mon Sep 17 00:00:00 2001 From: BigTigerKU Date: Tue, 10 Sep 2024 17:06:00 -0700 Subject: [PATCH] Configurable Person's Initial Format --- src/ChurchCRM/dto/Photo.php | 7 +++---- src/ChurchCRM/dto/SystemConfig.php | 13 ++++++++++++- src/ChurchCRM/model/ChurchCRM/Person.php | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/ChurchCRM/dto/Photo.php b/src/ChurchCRM/dto/Photo.php index aa4e1c1c5c..3c1dd9ce05 100644 --- a/src/ChurchCRM/dto/Photo.php +++ b/src/ChurchCRM/dto/Photo.php @@ -7,6 +7,8 @@ use ChurchCRM\Utils\LoggerUtils; use ChurchCRM\Utils\MiscUtils; +const initialFormatOptionFI = 'FI'; + class Photo { private string $photoType; @@ -304,10 +306,7 @@ private function getInitialsString(): string { $retstr = ''; if ($this->photoType == 'Person') { - $fullNameArr = PersonQuery::create()->select(['FirstName', 'LastName'])->findOneById($this->id); - foreach ($fullNameArr as $name) { - $retstr .= mb_strtoupper(mb_substr($name, 0, 1)); - } + $retstr = PersonQuery::create()->findOneById($this->id)->getInitial(SystemConfig::getValue('iPersonInitialStyle')); } elseif ($this->photoType == 'Family') { $fullNameArr = FamilyQuery::create()->findOneById($this->id)->getName(); $retstr .= mb_strtoupper(mb_substr($fullNameArr, 0, 1)); diff --git a/src/ChurchCRM/dto/SystemConfig.php b/src/ChurchCRM/dto/SystemConfig.php index 5143b03c57..b7a2dfb1b6 100644 --- a/src/ChurchCRM/dto/SystemConfig.php +++ b/src/ChurchCRM/dto/SystemConfig.php @@ -81,6 +81,16 @@ public static function getFamilyRoleChoices(): array return ['Choices' => $roles]; } + public static function getInitialStyleChoices(): array + { + return [ + 'Choices' => [ + gettext('One character from FirstName and one character from LastName') . ':0', + gettext('Two characters from FirstName') . ':1', + ], + ]; + } + private static function buildConfigs(): array { return [ @@ -198,6 +208,7 @@ private static function buildConfigs(): array 'sDepositSlipType' => new ConfigItem(2001, 'sDepositSlipType', 'choice', 'QBDT', gettext('Deposit ticket type. QBDT - Quickbooks'), '', '{"Choices":["QBDT"]}'), 'bAllowEmptyLastName' => new ConfigItem(2010, 'bAllowEmptyLastName', 'boolean', '0', gettext('Set true to allow empty lastname in Person Editor. Set false to validate last name and inherit from family when left empty.')), 'iPersonNameStyle' => new ConfigItem(2020, 'iPersonNameStyle', 'choice', '4', '', '', json_encode(SystemConfig::getNameChoices(), JSON_THROW_ON_ERROR)), + 'iPersonInitialStyle' => new ConfigItem(20201, 'iPersonInitialStyle', 'choice', '0', '', '', json_encode(SystemConfig::getInitialStyleChoices(), JSON_THROW_ON_ERROR)), 'bDisplayBillCounts' => new ConfigItem(2002, 'bDisplayBillCounts', 'boolean', '1', gettext('Display bill counts on deposit slip')), 'sCloudURL' => new ConfigItem(2003, 'sCloudURL', 'text', 'http://demo.churchcrm.io/', gettext('ChurchCRM Cloud Access URL')), 'sNexmoAPIKey' => new ConfigItem(2012, 'sNexmoAPIKey', 'text', '', gettext('Nexmo SMS API Key')), @@ -277,7 +288,7 @@ private static function buildCategories(): array gettext('Church Information') => ['sChurchName', 'sChurchAddress', 'sChurchCity', 'sChurchState', 'sChurchZip', 'sChurchCountry', 'sChurchPhone', 'sChurchEmail', 'sHomeAreaCode', 'sTimeZone', 'iChurchLatitude', 'iChurchLongitude', 'sChurchWebSite', 'sChurchFB', 'sChurchTwitter'], gettext('User Setup') => ['iMinPasswordLength', 'iMinPasswordChange', 'iMaxFailedLogins', 'iSessionTimeout', 'aDisallowedPasswords', 'bEnableLostPassword', 'bEnable2FA', 'bRequire2FA', 's2FAApplicationName', 'bSendUserDeletedEmail'], gettext('Email Setup') => ['sSMTPHost', 'bSMTPAuth', 'sSMTPUser', 'sSMTPPass', 'iSMTPTimeout', 'sToEmailAddress', 'bPHPMailerAutoTLS', 'sPHPMailerSMTPSecure'], - gettext('People Setup') => ['sDirClassifications', 'sDirRoleHead', 'sDirRoleSpouse', 'sDirRoleChild', 'sDefaultCity', 'sDefaultState', 'sDefaultZip', 'sDefaultCountry', 'bShowFamilyData', 'bHidePersonAddress', 'bHideFriendDate', 'bHideFamilyNewsletter', 'bHideWeddingDate', 'bHideLatLon', 'bForceUppercaseZip', 'bEnableSelfRegistration', 'bAllowEmptyLastName', 'iPersonNameStyle', 'iProfilePictureListSize', 'sNewPersonNotificationRecipientIDs', 'IncludeDataInNewPersonNotifications', 'sGreeterCustomMsg1', 'sGreeterCustomMsg2', 'sInactiveClassification'], + gettext('People Setup') => ['sDirClassifications', 'sDirRoleHead', 'sDirRoleSpouse', 'sDirRoleChild', 'sDefaultCity', 'sDefaultState', 'sDefaultZip', 'sDefaultCountry', 'bShowFamilyData', 'bHidePersonAddress', 'bHideFriendDate', 'bHideFamilyNewsletter', 'bHideWeddingDate', 'bHideLatLon', 'bForceUppercaseZip', 'bEnableSelfRegistration', 'bAllowEmptyLastName', 'iPersonNameStyle', 'iPersonInitialStyle', 'iProfilePictureListSize', 'sNewPersonNotificationRecipientIDs', 'IncludeDataInNewPersonNotifications', 'sGreeterCustomMsg1', 'sGreeterCustomMsg2', 'sInactiveClassification'], gettext('Enabled Features') => ['bEnabledFinance', 'bEnabledSundaySchool', 'bEnabledEvents', 'bEnabledCalendar', 'bEnabledFundraiser', 'bEnabledEmail', 'bEnabledMenuLinks'], gettext('Map Settings') => ['sGeoCoderProvider', 'sGoogleMapsGeocodeKey', 'sGoogleMapsRenderKey', 'sBingMapKey', 'sGMapIcons', 'iMapZoom'], gettext('Report Settings') => ['sQBDTSettings', 'leftX', 'incrementY', 'sTaxReport1', 'sTaxReport2', 'sTaxReport3', 'sTaxSigner', 'sReminder1', 'sReminderSigner', 'sReminderNoPledge', 'sReminderNoPayments', 'sConfirm1', 'sConfirm2', 'sConfirm3', 'sConfirm4', 'sConfirm5', 'sConfirm6', 'sDear', 'sConfirmSincerely', 'sConfirmSigner', 'sPledgeSummary1', 'sPledgeSummary2', 'sDirectoryDisclaimer1', 'sDirectoryDisclaimer2', 'bDirLetterHead', 'sZeroGivers', 'sZeroGivers2', 'sZeroGivers3', 'iPDFOutputType'], diff --git a/src/ChurchCRM/model/ChurchCRM/Person.php b/src/ChurchCRM/model/ChurchCRM/Person.php index f6fef6870f..a469a7a93e 100644 --- a/src/ChurchCRM/model/ChurchCRM/Person.php +++ b/src/ChurchCRM/model/ChurchCRM/Person.php @@ -707,4 +707,25 @@ public function getEmail(): ?string return parent::getEmail(); } + + /** + * Returns a string of a person's full name initial, formatted as specified by $Style + * $Style = 0 : "One character from FirstName and one character from LastName" + * $Style = 1 : "Two characters from FirstName" + */ + public function getInitial(int $Style): string + { + $initialString = ''; + switch ($Style) { + case 0: + $initialString .= mb_strtoupper(mb_substr($this->getFirstName(), 0, 1)); + $initialString .= mb_strtoupper(mb_substr($this->getLastName(), 0, 1)); + break; + case 1: + $fullNameArr = $this->getFirstName(); + $initialString .= mb_strtoupper(mb_substr($fullNameArr, 0, 2)); + } + + return $initialString; + } }