Skip to content

Commit

Permalink
Make Person List Columns Configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtigerku committed Sep 16, 2024
1 parent d051223 commit c3751cd
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 47 deletions.
21 changes: 21 additions & 0 deletions src/ChurchCRM/dto/ListColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace ChurchCRM\dto;

use ChurchCRM\model\ChurchCRM\Config;

class ListColumn
{
public $name;
public $function;
public $emptyOrUnassigned;
public $visible;

public function __construct($name, $function, $emptyOrUnassigned, $visible)
{
$this->name = $name;
$this->function = $function;
$this->emptyOrUnassigned = $emptyOrUnassigned;
$this->visible = $visible;
}
}
22 changes: 21 additions & 1 deletion src/ChurchCRM/dto/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ public static function getInitialStyleChoices(): array
];
}

public static function getPersonListColumns(): array
{
return [
'Id' => new ListColumn('Id', 'getId', false, false),
'Family Name' => new ListColumn('Family Name', 'getFamilyName', false, false),
'Name' => new ListColumn('Name', 'getFullName', false, false),
'Last Name' => new ListColumn('Last Name', 'getLastName', false, true),
'First Name' => new ListColumn('First Name', 'getFirstName', false, true),
'Birth Date' => new ListColumn('Birth Date', 'getFormattedBirthDate', false, false),
'Address' => new ListColumn('Address', 'getAddress', false, false),
'Home Phone' => new ListColumn('Home Phone', 'getHomePhone', false, true),
'Cell Phone' => new ListColumn('Cell Phone', 'getCellPhone', false, true),
'Email' => new ListColumn('Email', 'getEmail', false, true),
'Gender' => new ListColumn('Gender', 'getGenderName', true, true),
'Classification' => new ListColumn('Classification', 'getClassificationName', true, true),
'Roles' => new ListColumn('Roles', 'getFamilyRoleName', true, true),
];
}

private static function buildConfigs(): array
{
return [
Expand Down Expand Up @@ -279,6 +298,7 @@ private static function buildConfigs(): array
'sGoogleMapsRenderKey' => new ConfigItem(2072, 'sGoogleMapsRenderKey', 'text', '', gettext('Google Maps API Key used for rendering maps in browser'), 'https://developers.google.com/maps/documentation/javascript/get-api-key'),
'sInactiveClassification' => new ConfigItem(2073, 'sInactiveClassification', 'text', '', gettext('Comma separated list of classifications that should appear as inactive')),
'sDefaultZip' => new ConfigItem(2074, 'sDefaultZip', 'text', '', gettext('Default Zip')),
'sPersonListColumns' => new ConfigItem(2075, 'sPersonListColumns', 'json', json_encode(SystemConfig::getPersonListColumns()), gettext('Person List Columns')),
];
}

Expand All @@ -288,7 +308,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', 'iPersonInitialStyle', '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', 'sPersonListColumns'],
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
81 changes: 35 additions & 46 deletions src/v2/templates/people/person-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,22 @@ function emptyOrUnassignedJSON($stuff): string
<?php
}
?>
<td><?= $person->getId() ?></td>
<td><?= $person->getLastName()?></td>
<td><?= $person->getFirstName()?></td>
<td><?= $person->getAddress() ?></td>
<td><?= $person->getHomePhone() ?></td>
<td><?= $person->getCellPhone() ?></td>
<td><?= $person->getEmail() ?></td>
<td><?= emptyOrUnassigned($person->getGenderName()) ?></td>
<td><?= emptyOrUnassigned($person->getClassificationName()) ?></td>
<td><?= emptyOrUnassigned($person->getFamilyRoleName()) ?></td>

<?php
$columns = json_decode(SystemConfig::getValue('sPersonListColumns'), null, 512, JSON_THROW_ON_ERROR);
foreach ($columns as $columnKey => $columnValue) {
echo '<td>';
if ($columnValue->visible === "true") {
$columnData = [$person, $columnValue->function]();
if ($columnValue->emptyOrUnassigned == 1) {
echo emptyOrUnassigned($columnData);
} else {
echo $columnData;
}
}
echo '</td>';
}
?>
<td><?= emptyOrUnassignedJSON($person->getPropertiesString()) ?></td>
<td><?= emptyOrUnassignedJSON($person->getCustomFields($allPersonCustomFields, $CustomMapping, $CustomList, $option_name)) ?></td>
<td><?= emptyOrUnassignedJSON($person->getGroups()) ?></td>
Expand Down Expand Up @@ -201,47 +207,30 @@ function emptyOrUnassignedJSON($stuff): string

// setup datatables
'use strict';
var bVisible = parseInt("<?= SystemConfig::getValue('bHidePersonAddress') ? 0 : 1 ?>");

let dataTableConfig = {
deferRender: true,
search: { regex: true },
columns: [
{
title:i18next.t('Actions'),
},
{
title:i18next.t('Id'),
visible:false
},
{
title:i18next.t('Last Name'),
},
{
title:i18next.t('First Name'),
},
{
title:i18next.t('Address'),
visible:bVisible
},
{
title:i18next.t('Home Phone'),
},
{
title:i18next.t('Cell Phone'),
},
{
title:i18next.t('Email'),
},
{
title:i18next.t('Gender'),
},
{
title:i18next.t('Classification'),
},
{
title:i18next.t('Roles'),
},
<?php
$firstVisibleColumnId = PHP_INT_MAX;
$columnId = 0;
$columns = json_decode(SystemConfig::getValue('sPersonListColumns'), null, 512, JSON_THROW_ON_ERROR);
foreach ($columns as $columnKey => $columnValue) {
$columnId++;
echo '{ title:i18next.t(\'' . $columnValue->name . '\'), ';
if ($columnValue->visible === "false") {
echo 'visible:false';
} else {
if ($firstVisibleColumnId > $columnId) {
$firstVisibleColumnId = $columnId;
}
}
echo '},' . "\n";
}
?>
{
title:i18next.t('Properties'),
visible:false
Expand All @@ -255,8 +244,8 @@ function emptyOrUnassignedJSON($stuff): string
visible:false
}
],
// sortby name
order: [[ 2, "asc" ]]
// sort by first visible column
order: [[ <?php echo $firstVisibleColumnId ?> , "asc" ]]
}

$.extend(dataTableConfig, window.CRM.plugin.dataTable);
Expand Down

0 comments on commit c3751cd

Please sign in to comment.