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

Allow columns in relationship table to be modified by searchColumns hook #14184

Merged
merged 1 commit into from
Oct 6, 2019
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the hook here - in other places it is very centralised - but they do seem to be actually using the selector whereas I think you are mocking it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are mocking it and there are two different functions - the page loads with the columns here. Later the datatable loads the rows via an ajax call.

$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