Skip to content

Commit

Permalink
Configurable Person's Initial Format
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtigerku committed Sep 12, 2024
1 parent 4ad8385 commit 6c64581
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/ChurchCRM/dto/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use ChurchCRM\Utils\LoggerUtils;
use ChurchCRM\Utils\MiscUtils;

const initialFormatOptionFI = 'FI';

class Photo
{
private string $photoType;
Expand Down Expand Up @@ -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));
Expand Down
13 changes: 12 additions & 1 deletion src/ChurchCRM/dto/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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')),
Expand Down Expand Up @@ -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'],
Expand Down
21 changes: 21 additions & 0 deletions src/ChurchCRM/model/ChurchCRM/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 6c64581

Please sign in to comment.