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 49e1d57
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 53 deletions.
19 changes: 19 additions & 0 deletions src/ChurchCRM/dto/ListColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace ChurchCRM\dto;

class ListColumn
{
public string $name;
public string $displayFunction;
public string $emptyOrUnassigned;
public string $visible;

public function __construct(string $name, string $displayFunction, string $emptyOrUnassigned, string $visible)
{
$this->name = $name;
$this->displayFunction = $displayFunction;
$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"),
'Role' => new ListColumn('Role', '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
96 changes: 44 additions & 52 deletions src/v2/templates/people/person-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,20 @@ 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 $column) {
echo '<td>';
$columnData = [$person, $column->displayFunction]();
if ($column->emptyOrUnassigned === "true") {
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,62 +205,50 @@ 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;
$columnIdMap = array();
$columns = json_decode(SystemConfig::getValue('sPersonListColumns'), null, 512, JSON_THROW_ON_ERROR);
foreach ($columns as $column) {
$columnId++;
$columnIdMap[$column->name] = $columnId;
$columnTitle = array('title' => 'i18next.t(\'' . $column->name . '\')');
if ($column->visible === "false") {
$columnTitle['visible'] = 'false';
} else {
if ($firstVisibleColumnId > $columnId) {
$firstVisibleColumnId = $columnId;
}
}
echo str_replace('"','',json_encode($columnTitle)) . ",\n";
}
?>
{
title:i18next.t('Properties'),
visible:false
<?php $columnIdMap['Properties'] = ++$columnId; ?>
},
{
title:i18next.t('Custom'),
visible:false
<?php $columnIdMap['Custom'] = ++$columnId; ?>
},
{
title:i18next.t('Group'),
visible:false
<?php $columnIdMap['Group'] = ++$columnId; ?>
}
],
// sortby name
order: [[ 2, "asc" ]]
// sort by first visible column
order: [[ <?php echo $firstVisibleColumnId ?> , "asc" ]]
}

$.extend(dataTableConfig, window.CRM.plugin.dataTable);
Expand Down Expand Up @@ -289,22 +281,22 @@ function emptyOrUnassignedJSON($stuff): string
});

$('.filter-Gender').on("change", function() {
filterColumn(8, $(this).select2('data'), true);
filterColumn(<?php echo $columnIdMap["Gender"] ?>, $(this).select2('data'), true);
});
$('.filter-Classification').on("change", function() {
filterColumn(9, $(this).select2('data'), true);
filterColumn(<?php echo $columnIdMap["Classification"] ?>, $(this).select2('data'), true);
});
$('.filter-Role').on("change", function() {
filterColumn(10, $(this).select2('data'), true);
filterColumn(<?php echo $columnIdMap["Role"] ?>, $(this).select2('data'), true);
});
$('.filter-Properties').on("change", function() {
filterColumn(11, $(this).select2('data'), false);
filterColumn(<?php echo $columnIdMap["Properties"] ?>, $(this).select2('data'), false);
});
$('.filter-Custom').on("change", function() {
filterColumn(12, $(this).select2('data'), false);
filterColumn(<?php echo $columnIdMap["Custom"] ?>, $(this).select2('data'), false);
});
$('.filter-Group').on("change", function() {
filterColumn(13, $(this).select2('data'), false);
filterColumn(<?php echo $columnIdMap["Group"] ?>, $(this).select2('data'), false);
});

function escapeRegExp(string) {
Expand Down

0 comments on commit 49e1d57

Please sign in to comment.