Allow columns in relationship table to be modified by searchColumns hook
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Thu, 2 May 2019 13:43:25 +0000 (14:43 +0100)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Fri, 4 Oct 2019 14:39:29 +0000 (16:39 +0200)
CRM/Contact/BAO/Relationship.php
CRM/Contact/Page/View/Relationship.php
CRM/Contact/Page/View/UserDashBoard.php
templates/CRM/Contact/Page/View/RelationshipSelector.tpl

index b210da587acac3c2dc8eb687a85c1a3b45bb5637..bf270e363d6d58034bc420fb594a8f7820118374 100644 (file)
@@ -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 @@ AND cc.sort_name LIKE '%$name%'";
       }
     }
 
+    $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 @@ AND cc.sort_name LIKE '%$name%'";
     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
    */
index cc05f439e2906c8e79da93d4eefd77967cb0619e..f6004c1090e9d0bcfee29e6a0a5805a23c31045c 100644 (file)
@@ -158,6 +158,10 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
    */
   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);
   }
 
   /**
index a1cd4da84350ba05fcc3f6b516051844be29528e..91aacb1bba1132d0dccf85b19169b36f8277da74 100644 (file)
@@ -144,6 +144,10 @@ class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
 
     // 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',
index 09210fae477d2afc6d7abad10075ab44b78a8665..69602e62486ae66acd331b22b873b03c118f07d8 100644 (file)
  | 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>