Skip to content

Commit

Permalink
Merge pull request #14184 from mattwire/relationshipcolumns
Browse files Browse the repository at this point in the history
Allow columns in relationship table to be modified by searchColumns hook
  • Loading branch information
seamuslee001 authored Oct 6, 2019
2 parents e09b101 + 16b745b commit 49f945a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 13 deletions.
63 changes: 63 additions & 0 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'];
Expand All @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions CRM/Contact/Page/View/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions CRM/Contact/Page/View/UserDashBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
27 changes: 14 additions & 13 deletions templates/CRM/Contact/Page/View/RelationshipSelector.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
<div class="crm-contact-relationship-{$context}">
<div class="crm-contact-{$entityInClassFormat}-{$context}">
<table
class="crm-contact-relationship-selector-{$context} crm-ajax-table"
data-ajax="{crmURL p="civicrm/ajax/contactrelationships" q="context=$context&cid=$contactId"}" style="width: 100%;">
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%;">
<thead>
<tr>
<th data-data="relation" class='crm-contact-relationship-type'>{ts}Relationship{/ts}</th>
<th data-data="sort_name" class='crm-contact-relationship-contact_name'>&nbsp;</th>
<th data-data="start_date" class='crm-contact-relationship-start_date'>{ts}Start{/ts}</th>
<th data-data="end_date" class='crm-contact-relationship-end_date'>{ts}End{/ts}</th>
<th data-data="city" class='crm-contact-relationship-city'>{ts}City{/ts}</th>
<th data-data="state" class='crm-contact-relationship-state'>{ts}State/Prov{/ts}</th>
<th data-data="email" class='crm-contact-relationship-email'>{ts}Email{/ts}</th>
<th data-data="phone" class='crm-contact-relationship-phone'>{ts}Phone{/ts}</th>
<th data-data="links" data-orderable="false" class='crm-contact-relationship-links'></th>
{foreach from=$columnHeaders key=headerkey item=header}
{if $header.sort}
<th data-data="{$header.sort}" class="crm-contact-{$entityInClassFormat}-{$header.sort}">{$header.name}</th>
{else}
<th data-data="{$headerkey}" data-orderable="false" class="crm-contact-{$entityInClassFormat}-{$headerkey}">{$header.name}</th>
{/if}

{/foreach}
</tr>
</thead>
</table>
Expand Down

0 comments on commit 49f945a

Please sign in to comment.