Relationship permissions: move icons to template, change to stacked on squares
authorAndrew Hunt <andrew@aghstrategies.com>
Fri, 20 Jul 2018 19:09:06 +0000 (15:09 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Fri, 20 Jul 2018 19:09:06 +0000 (15:09 -0400)
CRM/Contact/BAO/Relationship.php
templates/CRM/Contact/Form/Relationship.tpl
templates/CRM/Contact/Page/View/RelationshipPerm.tpl [new file with mode: 0644]

index b1f74bd69372f097af67cd1543992514012c2c8f..df64ddcbba8d435f6435ec401c5e185a54ef5f14 100644 (file)
@@ -2130,36 +2130,36 @@ AND cc.sort_name LIKE '%$name%'";
         }
 
         if ($params['context'] == 'current') {
-          if (($params['contact_id'] == $values['contact_id_a'] and $values['is_permission_a_b'] == CRM_Contact_BAO_Relationship::EDIT) or
-            ($params['contact_id'] == $values['contact_id_b'] and $values['is_permission_b_a'] == CRM_Contact_BAO_Relationship::EDIT)
-          ) {
-            $relationship['sort_name'] .= <<<HEREDOC
-              <i class="crm-i fa-asterisk" title="{$values['display_name']} can be viewed and edited by $displayName"></i>
-HEREDOC;
-          }
-
-          if (($params['contact_id'] == $values['contact_id_a'] and $values['is_permission_a_b'] == CRM_Contact_BAO_Relationship::VIEW) or
-            ($params['contact_id'] == $values['contact_id_b'] and $values['is_permission_b_a'] == CRM_Contact_BAO_Relationship::VIEW)
-          ) {
-            $relationship['sort_name'] .= <<<HEREDOC
-              <i class="crm-i fa-eye" title="{$values['display_name']} can be viewed by $displayName"></i>
-HEREDOC;
-          }
-
-          if (($values['cid'] == $values['contact_id_a'] and $values['is_permission_a_b'] == CRM_Contact_BAO_Relationship::EDIT) or
-            ($values['cid'] == $values['contact_id_b'] and $values['is_permission_b_a'] == CRM_Contact_BAO_Relationship::EDIT)
-          ) {
-            $relationship['relation'] .= <<<HEREDOC
-              <i class="crm-i fa-asterisk" title="$displayName can be viewed and edited by {$values['display_name']}"></i>
-HEREDOC;
-          }
-
-          if (($values['cid'] == $values['contact_id_a'] and $values['is_permission_a_b'] == CRM_Contact_BAO_Relationship::VIEW) or
-            ($values['cid'] == $values['contact_id_b'] and $values['is_permission_b_a'] == CRM_Contact_BAO_Relationship::VIEW)
-          ) {
-            $relationship['relation'] .= <<<HEREDOC
-              <i class="crm-i fa-eye" title="$displayName can be viewed by {$values['display_name']}"></i>
-HEREDOC;
+          $smarty = CRM_Core_Smarty::singleton();
+
+          $contactCombos = [
+            [
+              'permContact' => $params['contact_id'],
+              'permDisplayName' => $displayName,
+              'otherContact' => $values['cid'],
+              'otherDisplayName' => $values['display_name'],
+              'columnKey' => 'sort_name',
+            ],
+            [
+              'permContact' => $values['cid'],
+              'permDisplayName' => $values['display_name'],
+              'otherContact' => $params['contact_id'],
+              'otherDisplayName' => $displayName,
+              'columnKey' => 'relation',
+            ],
+          ];
+
+          foreach ($contactCombos as $combo) {
+            foreach ([CRM_Contact_BAO_Relationship::EDIT, CRM_Contact_BAO_Relationship::VIEW] as $permType) {
+              $smarty->assign('permType', $permType);
+              if (($combo['permContact'] == $values['contact_id_a'] and $values['is_permission_a_b'] == $permType)
+                || ($combo['permContact'] == $values['contact_id_b'] and $values['is_permission_b_a'] == $permType)
+              ) {
+                $smarty->assign('permDisplayName', $combo['permDisplayName']);
+                $smarty->assign('otherDisplayName', $combo['otherDisplayName']);
+                $relationship[$combo['columnKey']] .= $smarty->fetch('CRM/Contact/Page/View/RelationshipPerm.tpl');
+              }
+            }
           }
         }
 
index 55bb4060ff5f79ad18bfa2fda15edfc7cf244b5c..cfc33721af7d871dee99f85b1bb6018557d5e1fc 100644 (file)
                   <div>
                   {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
                     {if $row.is_permission_a_b == 1}
-                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} <i class="crm-i fa-asterisk"></i>
+                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=1 permDisplayName=$displayName otherDisplayName=$row.display_name}
                     {else}
-                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} <i class="crm-i fa-eye"></i>
+                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=2 permDisplayName=$displayName otherDisplayName=$row.display_name}
                     {/if}
                   {else}
                     {if $row.is_permission_a_b == 1}
-                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} <i class="crm-i fa-asterisk"></i>
+                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=1 otherDisplayName=$displayName permDisplayName=$row.display_name}
                     {else}
-                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} <i class="crm-i fa-eye"></i>
+                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=2 otherDisplayName=$displayName permDisplayName=$row.display_name}
                     {/if}
                   {/if}
                   </div>
                   <div>
                   {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
                     {if $row.is_permission_b_a == 1}
-                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} <i class="crm-i fa-asterisk"></i>
+                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=1 otherDisplayName=$displayName permDisplayName=$row.display_name}
                     {else}
-                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} <i class="crm-i fa-eye"></i>
+                      {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=2 otherDisplayName=$displayName permDisplayName=$row.display_name}
                     {/if}
                   {else}
                     {if $row.is_permission_b_a == 1}
-                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} <i class="crm-i fa-asterisk"></i>
+                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=1 permDisplayName=$displayName otherDisplayName=$row.display_name}
                     {else}
-                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} <i class="crm-i fa-eye"></i>
+                      {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view information about <strong>%2</strong>{/ts} {include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=2 permDisplayName=$displayName otherDisplayName=$row.display_name}
                     {/if}
                   {/if}
                   </div>
diff --git a/templates/CRM/Contact/Page/View/RelationshipPerm.tpl b/templates/CRM/Contact/Page/View/RelationshipPerm.tpl
new file mode 100644 (file)
index 0000000..691bc78
--- /dev/null
@@ -0,0 +1,43 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 5                                                  |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{* Partial for displaying permissions associated with a relationship *}
+
+{if $permType eq 1}
+{include file="CRM/Contact/Page/View/RelationshipPerm.tpl" permType=2}
+{/if}
+
+{capture assign="permText"}
+{if $permType eq 1}
+{ts 1=$permDisplayName 2=$otherDisplayName}%2 can be edited by %1{/ts}
+{else}
+{ts 1=$permDisplayName 2=$otherDisplayName}%2 can be viewed by %1{/ts}
+{/if}
+{/capture}
+
+<span class="fa-stack" title="{$permText}">
+  <i class="crm-i fa-square fa-stack-2x"></i>
+  <i class="crm-i {if $permType eq 1}fa-pencil{else}fa-eye{/if} fa-inverse fa-stack-1x"></i>
+</span>