ContactSummary - Add SearchKit display for relationships tab
authorcolemanw <coleman@civicrm.org>
Mon, 2 Oct 2023 01:48:59 +0000 (21:48 -0400)
committercolemanw <coleman@civicrm.org>
Wed, 4 Oct 2023 00:52:21 +0000 (20:52 -0400)
ang/afform/afsearchTabRel.aff.html [new file with mode: 0644]
ang/afform/afsearchTabRel.aff.php [new file with mode: 0644]
managed/contactSummary/SavedSearch_Contact_Summary_Relationships.mgd.php [new file with mode: 0644]

diff --git a/ang/afform/afsearchTabRel.aff.html b/ang/afform/afsearchTabRel.aff.html
new file mode 100644 (file)
index 0000000..07fb4f4
--- /dev/null
@@ -0,0 +1,9 @@
+<div af-fieldset="">
+  <div class="alert alert-warning">
+    <strong>{{:: ts('Permissioned Relationships:') }}</strong>
+    <i class="crm-i fa-eye"></i> {{:: ts('This contact can be viewed by the other.') }}
+    <i class="crm-i fa-pencil-square"></i> {{:: ts('This contact can be viewed and edited by the other.') }}
+  </div>
+  <crm-search-display-table search-name="Contact_Summary_Relationships" display-name="Contact_Summary_Relationships_Active" filters="{near_contact_id: options.contact_id, is_current: true}"></crm-search-display-table>
+  <crm-search-display-table search-name="Contact_Summary_Relationships" display-name="Contact_Summary_Relationships_Inactive" filters="{near_contact_id: options.contact_id, is_current: false}"></crm-search-display-table>
+</div>
diff --git a/ang/afform/afsearchTabRel.aff.php b/ang/afform/afsearchTabRel.aff.php
new file mode 100644 (file)
index 0000000..3eb3cb0
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+return [
+  'type' => 'search',
+  'title' => ts('Relationships'),
+  'permission' => [
+    'access CiviCRM',
+  ],
+  'contact_summary' => 'tab',
+  'icon' => 'fa-handshake-o',
+  'summary_weight' => 80,
+  'permission_operator' => 'AND',
+];
diff --git a/managed/contactSummary/SavedSearch_Contact_Summary_Relationships.mgd.php b/managed/contactSummary/SavedSearch_Contact_Summary_Relationships.mgd.php
new file mode 100644 (file)
index 0000000..52c7d2b
--- /dev/null
@@ -0,0 +1,463 @@
+<?php
+
+return [
+  [
+    'name' => 'SavedSearch_Contact_Summary_Relationships',
+    'entity' => 'SavedSearch',
+    'cleanup' => 'unused',
+    'update' => 'unmodified',
+    'params' => [
+      'version' => 4,
+      'values' => [
+        'name' => 'Contact_Summary_Relationships',
+        'label' => ts('Contact Summary Relationships'),
+        'api_entity' => 'RelationshipCache',
+        'api_params' => [
+          'version' => 4,
+          'select' => [
+            'near_relation:label',
+            'RelationshipCache_Contact_far_contact_id_01.display_name',
+            'start_date',
+            'end_date',
+            'RelationshipCache_Contact_far_contact_id_01.address_primary.city',
+            'RelationshipCache_Contact_far_contact_id_01.address_primary.state_province_id:label',
+            'RelationshipCache_Contact_far_contact_id_01.email_primary.email',
+            'RelationshipCache_Contact_far_contact_id_01.phone_primary.phone',
+            'permission_near_to_far:label',
+            'permission_far_to_near:label',
+            'is_active',
+          ],
+          'orderBy' => [],
+          'where' => [],
+          'groupBy' => [],
+          'join' => [
+            [
+              'Contact AS RelationshipCache_Contact_far_contact_id_01',
+              'LEFT',
+              [
+                'far_contact_id',
+                '=',
+                'RelationshipCache_Contact_far_contact_id_01.id',
+              ],
+            ],
+          ],
+          'having' => [],
+        ],
+      ],
+      'match' => [
+        'name',
+      ],
+    ],
+  ],
+  [
+    'name' => 'SavedSearch_Contact_Summary_Relationships_SearchDisplay_Contact_Summary_Relationships_Tab',
+    'entity' => 'SearchDisplay',
+    'cleanup' => 'unused',
+    'update' => 'unmodified',
+    'params' => [
+      'version' => 4,
+      'values' => [
+        'name' => 'Contact_Summary_Relationships_Active',
+        'label' => ts('Contact Summary Relationships Active'),
+        'saved_search_id.name' => 'Contact_Summary_Relationships',
+        'type' => 'table',
+        'settings' => [
+          'description' => NULL,
+          'sort' => [],
+          'limit' => 50,
+          'pager' => [
+            'hide_single' => TRUE,
+            'expose_limit' => TRUE,
+          ],
+          'placeholder' => 5,
+          'columns' => [
+            [
+              'type' => 'field',
+              'key' => 'near_relation:label',
+              'dataType' => 'String',
+              'label' => ts('Relationship'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'field' => 'permission_far_to_near:icon',
+                  'side' => 'left',
+                ],
+              ],
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.display_name',
+              'dataType' => 'String',
+              'label' => ts('With'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'field' => 'RelationshipCache_Contact_far_contact_id_01.contact_sub_type:icon',
+                  'side' => 'left',
+                ],
+                [
+                  'field' => 'RelationshipCache_Contact_far_contact_id_01.contact_type:icon',
+                  'side' => 'left',
+                ],
+                [
+                  'field' => 'permission_near_to_far:icon',
+                  'side' => 'right',
+                ],
+              ],
+              'link' => [
+                'path' => '',
+                'entity' => 'Contact',
+                'action' => 'view',
+                'join' => 'RelationshipCache_Contact_far_contact_id_01',
+                'target' => '_blank',
+              ],
+              'title' => ts('View Related Contact'),
+            ],
+            [
+              'type' => 'field',
+              'key' => 'start_date',
+              'dataType' => 'Date',
+              'label' => ts('Dates'),
+              'sortable' => TRUE,
+              'rewrite' => '[start_date] - [end_date]',
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.address_primary.city',
+              'dataType' => 'String',
+              'label' => ts('City'),
+              'sortable' => TRUE,
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.address_primary.state_province_id:label',
+              'dataType' => 'Integer',
+              'label' => ts('State/Prov'),
+              'sortable' => TRUE,
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.email_primary.email',
+              'dataType' => 'String',
+              'label' => ts('Email'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'icon' => 'fa-ban',
+                  'side' => 'left',
+                  'if' => [
+                    'RelationshipCache_Contact_far_contact_id_01.do_not_email',
+                    '=',
+                    TRUE,
+                  ],
+                ],
+              ],
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.phone_primary.phone',
+              'dataType' => 'String',
+              'label' => ts('Phone'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'icon' => 'fa-ban',
+                  'side' => 'left',
+                  'if' => [
+                    'RelationshipCache_Contact_far_contact_id_01.do_not_phone',
+                    '=',
+                    TRUE,
+                  ],
+                ],
+              ],
+            ],
+            [
+              'text' => '',
+              'style' => 'default',
+              'size' => 'btn-xs',
+              'icon' => 'fa-bars',
+              'links' => [
+                [
+                  'entity' => 'Relationship',
+                  'action' => 'view',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-external-link',
+                  'text' => ts('View Relationship'),
+                  'style' => 'default',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+                [
+                  'entity' => 'Relationship',
+                  'action' => 'update',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-pencil',
+                  'text' => ts('Update Relationship'),
+                  'style' => 'default',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+                [
+                  'task' => 'disable',
+                  'entity' => 'Relationship',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-toggle-off',
+                  'text' => ts('Disable Relationship'),
+                  'style' => 'default',
+                  'path' => '',
+                  'action' => '',
+                  'condition' => [
+                    'is_active',
+                    '=',
+                    TRUE,
+                  ],
+                ],
+                [
+                  'entity' => 'Relationship',
+                  'action' => 'delete',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-trash',
+                  'text' => ts('Delete Relationship'),
+                  'style' => 'danger',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+              ],
+              'type' => 'menu',
+              'alignment' => 'text-right',
+            ],
+          ],
+          'actions' => FALSE,
+          'classes' => [
+            'table',
+            'table-striped',
+          ],
+          'toolbar' => [
+            [
+              'action' => 'add',
+              'entity' => 'Relationship',
+              'text' => ts('Add Relationship'),
+              'icon' => 'fa-plus',
+              'style' => 'primary',
+              'target' => 'crm-popup',
+              'join' => '',
+              'path' => '',
+              'task' => '',
+              'condition' => [],
+            ],
+          ],
+        ],
+      ],
+      'match' => [
+        'name',
+        'saved_search_id',
+      ],
+    ],
+  ],
+  [
+    'name' => 'SavedSearch_Contact_Summary_Relationships_SearchDisplay_Contact_Summary_Relationships_Inactive',
+    'entity' => 'SearchDisplay',
+    'cleanup' => 'unused',
+    'update' => 'unmodified',
+    'params' => [
+      'version' => 4,
+      'values' => [
+        'name' => 'Contact_Summary_Relationships_Inactive',
+        'label' => ts('Contact Summary Relationships Inactive'),
+        'saved_search_id.name' => 'Contact_Summary_Relationships',
+        'type' => 'table',
+        'settings' => [
+          'description' => ts('These relationships are Disabled OR have a past End Date.'),
+          'sort' => [],
+          'limit' => 50,
+          'pager' => [
+            'hide_single' => TRUE,
+            'expose_limit' => TRUE,
+          ],
+          'placeholder' => 5,
+          'columns' => [
+            [
+              'type' => 'field',
+              'key' => 'near_relation:label',
+              'dataType' => 'String',
+              'label' => ts('Relationship'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'field' => 'permission_far_to_near:icon',
+                  'side' => 'left',
+                ],
+              ],
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.display_name',
+              'dataType' => 'String',
+              'label' => ts('With'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'field' => 'RelationshipCache_Contact_far_contact_id_01.contact_sub_type:icon',
+                  'side' => 'left',
+                ],
+                [
+                  'field' => 'RelationshipCache_Contact_far_contact_id_01.contact_type:icon',
+                  'side' => 'left',
+                ],
+                [
+                  'field' => 'permission_near_to_far:icon',
+                  'side' => 'right',
+                ],
+              ],
+              'link' => [
+                'path' => '',
+                'entity' => 'Contact',
+                'action' => 'view',
+                'join' => 'RelationshipCache_Contact_far_contact_id_01',
+                'target' => '_blank',
+              ],
+              'title' => ts('View Related Contact'),
+            ],
+            [
+              'type' => 'field',
+              'key' => 'start_date',
+              'dataType' => 'Date',
+              'label' => ts('Dates'),
+              'sortable' => TRUE,
+              'rewrite' => '[start_date] - [end_date]',
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.address_primary.city',
+              'dataType' => 'String',
+              'label' => ts('City'),
+              'sortable' => TRUE,
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.address_primary.state_province_id:label',
+              'dataType' => 'Integer',
+              'label' => ts('State/Prov'),
+              'sortable' => TRUE,
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.email_primary.email',
+              'dataType' => 'String',
+              'label' => ts('Email'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'icon' => 'fa-ban',
+                  'side' => 'left',
+                  'if' => [
+                    'RelationshipCache_Contact_far_contact_id_01.do_not_email',
+                    '=',
+                    TRUE,
+                  ],
+                ],
+              ],
+            ],
+            [
+              'type' => 'field',
+              'key' => 'RelationshipCache_Contact_far_contact_id_01.phone_primary.phone',
+              'dataType' => 'String',
+              'label' => ts('Phone'),
+              'sortable' => TRUE,
+              'icons' => [
+                [
+                  'icon' => 'fa-ban',
+                  'side' => 'left',
+                  'if' => [
+                    'RelationshipCache_Contact_far_contact_id_01.do_not_phone',
+                    '=',
+                    TRUE,
+                  ],
+                ],
+              ],
+            ],
+            [
+              'text' => '',
+              'style' => 'default',
+              'size' => 'btn-xs',
+              'icon' => 'fa-bars',
+              'links' => [
+                [
+                  'entity' => 'Relationship',
+                  'action' => 'view',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-external-link',
+                  'text' => ts('View Relationship'),
+                  'style' => 'default',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+                [
+                  'entity' => 'Relationship',
+                  'action' => 'update',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-pencil',
+                  'text' => ts('Update Relationship'),
+                  'style' => 'default',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+                [
+                  'task' => 'enable',
+                  'entity' => 'Relationship',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-toggle-on',
+                  'text' => ts('Enable Relationship'),
+                  'style' => 'default',
+                  'path' => '',
+                  'action' => '',
+                  'condition' => [
+                    'is_active',
+                    '=',
+                    FALSE,
+                  ],
+                ],
+                [
+                  'entity' => 'Relationship',
+                  'action' => 'delete',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-trash',
+                  'text' => ts('Delete Relationship'),
+                  'style' => 'danger',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+              ],
+              'type' => 'menu',
+              'alignment' => 'text-right',
+            ],
+          ],
+          'actions' => FALSE,
+          'classes' => [
+            'table',
+            'table-striped',
+            'disabled',
+          ],
+        ],
+      ],
+      'match' => [
+        'name',
+        'saved_search_id',
+      ],
+    ],
+  ],
+];