From 16b745b057ca1965994a01f1838bf3680e7f7d48 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Thu, 2 May 2019 14:43:25 +0100 Subject: [PATCH] Allow columns in relationship table to be modified by searchColumns hook --- CRM/Contact/BAO/Relationship.php | 63 +++++++++++++++++++ CRM/Contact/Page/View/Relationship.php | 4 ++ CRM/Contact/Page/View/UserDashBoard.php | 4 ++ .../Page/View/RelationshipSelector.tpl | 27 ++++---- 4 files changed, 85 insertions(+), 13 deletions(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index b210da587ac..bf270e363d6 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -43,6 +43,12 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { */ const NONE = 0, EDIT = 1, VIEW = 2; + /** + * The list of column headers + * @var array + */ + private static $columnHeaders; + /** * Create function - use the API instead. * @@ -2200,6 +2206,10 @@ public static function getContactRelationshipSelector(&$params) { } } + $columnHeaders = self::getColumnHeaders(); + $selector = NULL; + CRM_Utils_Hook::searchColumns('relationship.rows', $columnHeaders, $contactRelationships, $selector); + $relationshipsDT = []; $relationshipsDT['data'] = $contactRelationships; $relationshipsDT['recordsTotal'] = $params['total']; @@ -2208,6 +2218,59 @@ public static function getContactRelationshipSelector(&$params) { return $relationshipsDT; } + /** + * @return array + */ + public static function getColumnHeaders() { + return [ + 'relation' => [ + 'name' => ts('Relationship'), + 'sort' => 'relation', + 'direction' => CRM_Utils_Sort::ASCENDING, + ], + 'sort_name' => [ + 'name' => '', + 'sort' => 'sort_name', + 'direction' => CRM_Utils_Sort::ASCENDING, + ], + 'start_date' => [ + 'name' => ts('Start'), + 'sort' => 'start_date', + 'direction' => CRM_Utils_Sort::DONTCARE, + ], + 'end_date' => [ + 'name' => ts('End'), + 'sort' => 'end_date', + 'direction' => CRM_Utils_Sort::DONTCARE, + ], + 'city' => [ + 'name' => ts('City'), + 'sort' => 'city', + 'direction' => CRM_Utils_Sort::DONTCARE, + ], + 'state' => [ + 'name' => ts('State/Prov'), + 'sort' => 'state', + 'direction' => CRM_Utils_Sort::DONTCARE, + ], + 'email' => [ + 'name' => ts('Email'), + 'sort' => 'email', + 'direction' => CRM_Utils_Sort::DONTCARE, + ], + 'phone' => [ + 'name' => ts('Phone'), + 'sort' => 'phone', + 'direction' => CRM_Utils_Sort::DONTCARE, + ], + 'links' => [ + 'name' => '', + 'sort' => 'links', + 'direction' => CRM_Utils_Sort::DONTCARE, + ], + ]; + } + /** * @inheritdoc */ diff --git a/CRM/Contact/Page/View/Relationship.php b/CRM/Contact/Page/View/Relationship.php index cc05f439e29..f6004c1090e 100644 --- a/CRM/Contact/Page/View/Relationship.php +++ b/CRM/Contact/Page/View/Relationship.php @@ -158,6 +158,10 @@ public function view() { */ public function browse() { // do nothing :) we are using datatable for rendering relationship selectors + $columnHeaders = CRM_Contact_BAO_Relationship::getColumnHeaders(); + $contactRelationships = $selector = NULL; + CRM_Utils_Hook::searchColumns('relationship.columns', $columnHeaders, $contactRelationships, $selector); + $this->assign('columnHeaders', $columnHeaders); } /** diff --git a/CRM/Contact/Page/View/UserDashBoard.php b/CRM/Contact/Page/View/UserDashBoard.php index a1cd4da8435..91aacb1bba1 100644 --- a/CRM/Contact/Page/View/UserDashBoard.php +++ b/CRM/Contact/Page/View/UserDashBoard.php @@ -144,6 +144,10 @@ public function buildUserDashBoard() { // CRM-16512 - Hide related contact table if user lacks permission to view self if (!empty($dashboardOptions['Permissioned Orgs']) && CRM_Core_Permission::check('view my contact')) { + $columnHeaders = CRM_Contact_BAO_Relationship::getColumnHeaders(); + $contactRelationships = $selector = NULL; + CRM_Utils_Hook::searchColumns('relationship.columns', $columnHeaders, $contactRelationships, $selector); + $this->assign('columnHeaders', $columnHeaders); $dashboardElements[] = [ 'class' => 'crm-dashboard-permissionedOrgs', 'templatePath' => 'CRM/Contact/Page/View/RelationshipSelector.tpl', diff --git a/templates/CRM/Contact/Page/View/RelationshipSelector.tpl b/templates/CRM/Contact/Page/View/RelationshipSelector.tpl index 09210fae477..69602e62486 100644 --- a/templates/CRM/Contact/Page/View/RelationshipSelector.tpl +++ b/templates/CRM/Contact/Page/View/RelationshipSelector.tpl @@ -23,24 +23,25 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{* relationship selector *} +{* entity selector *} {crmRegion name="crm-contact-relationshipselector-pre"} {/crmRegion} -
+
+ class="crm-contact-{$entityInClassFormat}-selector-{$context} crm-ajax-table" + data-ajax="{crmURL p="civicrm/ajax/contactrelationships" q="context=$context&cid=$contactId"}" + data-order='[[0,"asc"],[1,"asc"]]' + style="width: 100%;"> - - - - - - - - - + {foreach from=$columnHeaders key=headerkey item=header} + {if $header.sort} + + {else} + + {/if} + + {/foreach}
{ts}Relationship{/ts} {ts}Start{/ts}{ts}End{/ts}{ts}City{/ts}{ts}State/Prov{/ts}{ts}Email{/ts}{ts}Phone{/ts}{$header.name}{$header.name}