Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Person's Initial Format #7141

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// <reference types="cypress" />

context("API Private Admin Person Initial Setting", () => {
it("Delete Person Image / Generate Initial Image", () => {
cy.makePrivateAdminAPICall(
"DELETE",
"/api/person/2/photo",
null,
200,
);

cy.request({
method: "GET",
url: "/api/person/2/photo",
headers: {
"content-type": "application/json",
"x-api-key": Cypress.env("admin.api.key"),
},
}).then((resp) => {
expect(resp.status).to.eq(200);
});
});

it("Change Person Initial Style / Delete Person Image / Generate Initial Image", () => {
let json = { value: "1" };
cy.makePrivateAdminAPICall(
"POST",
"/api/system/config/iPersonInitialStyle",
json,
200,
);

cy.request({
method: "GET",
url: "/api/system/config/iPersonInitialStyle",
headers: {
"content-type": "application/json",
"x-api-key": Cypress.env("admin.api.key"),
},
}).then((resp) => {
expect(resp.status).to.eq(200);
const result = JSON.parse(JSON.stringify(resp.body));
expect(result.value).to.eq(json.value);
});

cy.makePrivateAdminAPICall(
"DELETE",
"/api/person/2/photo",
null,
200,
);

cy.request({
method: "GET",
url: "/api/person/2/photo",
headers: {
"content-type": "application/json",
"x-api-key": Cypress.env("admin.api.key"),
},
}).then((resp) => {
expect(resp.status).to.eq(200);
});
});
});
5 changes: 1 addition & 4 deletions src/ChurchCRM/dto/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,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',
DawoudIO marked this conversation as resolved.
Show resolved Hide resolved
],
];
}

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));
DawoudIO marked this conversation as resolved.
Show resolved Hide resolved
$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;
}
}
Loading