Merge pull request #20136 from eileenmcnaughton/dom
authorcolemanw <coleman@civicrm.org>
Sun, 25 Apr 2021 23:03:15 +0000 (19:03 -0400)
committerGitHub <noreply@github.com>
Sun, 25 Apr 2021 23:03:15 +0000 (19:03 -0400)
[REF] Move functions back to class that uses it

CRM/Activity/BAO/Activity.php
CRM/Contact/BAO/GroupContactCache.php
ext/afform/admin/afformEntities/Household.php
ext/afform/admin/afformEntities/Individual.php
ext/afform/admin/afformEntities/Organization.php
ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js
ext/afform/admin/ang/afGuiEditor/afGuiEntity.html
ext/afform/admin/ang/afGuiEditor/entityConfig/Activity.html [deleted file]
templates/CRM/Member/Form/Membership.tpl

index 0f410c8d80f0d8fedba0e6830b094cf740532a80..80542d9493fd4c01b40ce03b63536644a93edf21 100644 (file)
@@ -2499,7 +2499,6 @@ INNER JOIN  civicrm_option_group grp ON (grp.id = option_group_id AND grp.name =
       }
 
       $mask = CRM_Core_Action::mask($permissions);
-      $userID = CRM_Core_Session::getLoggedInContactID();
 
       foreach ($activities as $activityId => $values) {
         $activity = ['source_contact_name' => '', 'target_contact_name' => ''];
@@ -2618,84 +2617,24 @@ INNER JOIN  civicrm_option_group grp ON (grp.id = option_group_id AND grp.name =
         $activity['activity_date_time'] = CRM_Utils_Date::customFormat($values['activity_date_time']);
         $activity['status_id'] = $activityStatus[$values['status_id']];
 
-        // build links
-        $activity['links'] = '';
-
         // Get action links.
-
-        // If this is a case activity, then we hand off to Case's actionLinks instead.
-        if (!empty($values['case_id']) && Civi::settings()->get('civicaseShowCaseActivities')) {
-          // This activity belongs to a case.
-          $caseId = current($values['case_id']);
-
-          // Get the view and edit (update) links:
-          $caseActionLinks =
-            $actionLinks = array_intersect_key(
-              CRM_Case_Selector_Search::actionLinks(),
-              array_fill_keys([CRM_Core_Action::VIEW, CRM_Core_Action::UPDATE], NULL));
-
-          // Create a Manage Case link (using ADVANCED as can't use two VIEW ones)
-          $actionLinks[CRM_Core_Action::ADVANCED] = [
-            "name"  => 'Manage Case',
-            "url"   => 'civicrm/contact/view/case',
-            'qs'    => 'reset=1&id=%%caseid%%&cid=%%cid%%&action=view&context=&selectedChild=case',
-            "title" => ts('Manage Case %1', [1 => $caseId]),
-            'class' => 'no-popup',
-          ];
-
-          $caseLinkValues = [
-            'aid'    => $activityId,
-            'caseid' => $caseId,
-            'cid'    => current(CRM_Case_BAO_Case::getCaseClients($caseId) ?? []),
-            // Unlike other 'context' params, this 'ctx' param is appended raw to the URL.
-            'cxt'    => '',
-          ];
-
-          $caseActivityPermissions = CRM_Core_Action::VIEW | CRM_Core_Action::ADVANCED;
-          // Allow Edit link if:
-          // 1. Activity type is NOT view-only type. CRM-5871
-          // 2. User has edit permission.
-          if (!isset($viewOnlyCaseActivityTypeIDs[$values['activity_type_id']])
-            && CRM_Case_BAO_Case::checkPermission($activityId, 'edit', $values['activity_type_id'], $userID)) {
-            // We're allowed to edit.
-            $caseActivityPermissions |= CRM_Core_Action::UPDATE;
-          }
-
-          $activity['links'] = CRM_Core_Action::formLink($actionLinks,
-            $caseActivityPermissions,
-            $caseLinkValues,
-            ts('more'),
-            FALSE,
-            'activity.tab.row',
-            'Activity',
-            $values['activity_id']
-          );
-        }
-        else {
-          // Non-case activity
-          $actionLinks = CRM_Activity_Selector_Activity::actionLinks(
-            $values['activity_type_id'] ?? NULL,
-            $values['source_record_id'] ?? NULL,
-            !empty($values['mailingId']),
-            $values['activity_id'] ?? NULL
-          );
-          $actionMask = array_sum(array_keys($actionLinks)) & $mask;
-
-          $activity['links'] = CRM_Core_Action::formLink($actionLinks,
-            $actionMask,
-            [
-              'id' => $values['activity_id'],
-              'cid' => $params['contact_id'],
-              'cxt' => $context,
-              'caseid' => NULL,
-            ],
-            ts('more'),
-            FALSE,
-            'activity.tab.row',
-            'Activity',
-            $values['activity_id']
-          );
-        }
+        //
+        // Note that $viewOnlyCaseActivityTypeIDs, while not a super-heavy
+        // calculation, makes some sense to calculate outside the loop above.
+        // We could recalculate it each time inside getActionLinks if we wanted
+        // to avoid passing it along. Or use caching inside getAcionLinks.
+        //   - Ditto $mask.
+        $activity['links'] = self::getActionLinks(
+          $values,
+          $activityId,
+          $params['contact_id'],
+          isset($viewOnlyCaseActivityTypeIDs[$values['activity_type_id']]),
+          $context,
+          $mask,
+          // I think this parameter should be ignored completely for the purpose
+          // of generating a link but am leaving it as-is for now.
+          (bool) Civi::settings()->get('civicaseShowCaseActivities')
+        );
 
         if ($values['is_recurring_activity']) {
           $activity['is_recurring_activity'] = CRM_Core_BAO_RecurringEntity::getPositionAndCount($values['activity_id'], 'civicrm_activity');
@@ -2713,6 +2652,109 @@ INNER JOIN  civicrm_option_group grp ON (grp.id = option_group_id AND grp.name =
     return $activitiesDT;
   }
 
+  /**
+   * Get the right links depending on the activity type and other factors.
+   * @param array $values
+   * @param int $activityId
+   * @param ?int $contactId
+   * @param bool $isViewOnly Is this a special type that shouldn't be edited
+   * @param ?string $context
+   * @param ?int $mask
+   * @param bool $dontBreakCaseActivities Originally this function was
+   *   part of another function that was only used on the contact's activity
+   *   tab and this parameter would only be false when you're not displaying
+   *   case activities anyway and so was effectively never used. And I'm not
+   *   sure why for the purposes of links you would ever want a case activity
+   *   to link to the regular form, so I think this can be removed, but am
+   *   leaving it as-is for now.
+   * @return string HTML string
+   */
+  public static function getActionLinks(
+    array $values,
+    int $activityId,
+    ?int $contactId,
+    bool $isViewOnly,
+    ?string $context,
+    ?int $mask,
+    bool $dontBreakCaseActivities = TRUE): string {
+
+    $linksToReturn = '';
+    // If this is a case activity, then we hand off to Case's actionLinks instead.
+    if (!empty($values['case_id']) && $dontBreakCaseActivities) {
+      // This activity belongs to a case.
+      $caseId = current($values['case_id']);
+
+      // Get the view and edit (update) links:
+      $caseActionLinks =
+        $actionLinks = array_intersect_key(
+          CRM_Case_Selector_Search::actionLinks(),
+          array_fill_keys([CRM_Core_Action::VIEW, CRM_Core_Action::UPDATE], NULL));
+
+      // Create a Manage Case link (using ADVANCED as can't use two VIEW ones)
+      $actionLinks[CRM_Core_Action::ADVANCED] = [
+        "name"  => 'Manage Case',
+        "url"   => 'civicrm/contact/view/case',
+        'qs'    => 'reset=1&id=%%caseid%%&cid=%%cid%%&action=view&context=&selectedChild=case',
+        "title" => ts('Manage Case %1', [1 => $caseId]),
+        'class' => 'no-popup',
+      ];
+
+      $caseLinkValues = [
+        'aid'    => $activityId,
+        'caseid' => $caseId,
+        'cid'    => current(CRM_Case_BAO_Case::getCaseClients($caseId) ?? []),
+        // Unlike other 'context' params, this 'ctx' param is appended raw to the URL.
+        'cxt'    => '',
+      ];
+
+      $caseActivityPermissions = CRM_Core_Action::VIEW | CRM_Core_Action::ADVANCED;
+      // Allow Edit link if:
+      // 1. Activity type is NOT view-only type. CRM-5871
+      // 2. User has edit permission.
+      if (!$isViewOnly
+        && CRM_Case_BAO_Case::checkPermission($activityId, 'edit', $values['activity_type_id'], CRM_Core_Session::getLoggedInContactID())) {
+        // We're allowed to edit.
+        $caseActivityPermissions |= CRM_Core_Action::UPDATE;
+      }
+
+      $linksToReturn = CRM_Core_Action::formLink($actionLinks,
+        $caseActivityPermissions,
+        $caseLinkValues,
+        ts('more'),
+        FALSE,
+        'activity.tab.row',
+        'Activity',
+        $values['activity_id']
+      );
+    }
+    else {
+      // Non-case activity
+      $actionLinks = CRM_Activity_Selector_Activity::actionLinks(
+        $values['activity_type_id'] ?? NULL,
+        $values['source_record_id'] ?? NULL,
+        !empty($values['mailingId']),
+        $values['activity_id'] ?? NULL
+      );
+      $actionMask = array_sum(array_keys($actionLinks)) & $mask;
+
+      $linksToReturn = CRM_Core_Action::formLink($actionLinks,
+        $actionMask,
+        [
+          'id' => $values['activity_id'],
+          'cid' => $contactId,
+          'cxt' => $context,
+          'caseid' => NULL,
+        ],
+        ts('more'),
+        FALSE,
+        'activity.tab.row',
+        'Activity',
+        $values['activity_id']
+      );
+    }
+    return $linksToReturn;
+  }
+
   /**
    * Copy custom fields and attachments from an existing activity to another.
    *
index 3e75e851333f98904533878b740a256337636c67..876b6dfd68557d146a2fa585e23cd1cb561ca6f2 100644 (file)
@@ -578,7 +578,7 @@ ORDER BY   gc.contact_id, g.children
   public static function invalidateGroupContactCache($groupID) {
     CRM_Core_DAO::executeQuery("UPDATE civicrm_group
       SET cache_date = NULL
-      WHERE id = %1", [
+      WHERE id = %1 AND (saved_search_id IS NOT NULL OR children IS NOT NULL)", [
         1 => [$groupID, 'Positive'],
       ]);
   }
index 00173428d7c18e12840fe13a796f1726ef2bb04c..cf569b3432ce2f54dbbd554f125f47244299e9ef 100644 (file)
@@ -13,4 +13,5 @@ return [
   'boilerplate' => [
     ['#tag' => 'afblock-name-household'],
   ],
+  'admin_tpl' => '~/afGuiEditor/entityConfig/Contact.html',
 ];
index b6c972754bf41c11c357215d4526824ff18d5326..cc580425e4ee434c1eff6d1b57efd33c4698134c 100644 (file)
@@ -13,4 +13,5 @@ return [
   'boilerplate' => [
     ['#tag' => 'afblock-name-individual'],
   ],
+  'admin_tpl' => '~/afGuiEditor/entityConfig/Contact.html',
 ];
index aba69f9f44d5fddfbb27bed75439edda44dee13a..5335b6ddc212e7bbeba6283c7c18c4d3c1753e7b 100644 (file)
@@ -13,4 +13,5 @@ return [
   'boilerplate' => [
     ['#tag' => 'afblock-name-organization'],
   ],
+  'admin_tpl' => '~/afGuiEditor/entityConfig/Contact.html',
 ];
index 721c41ec6ea4641c287d5612f46f02a7c347e789..e2d2c249a833d7a5f968373f2635fc9a12eb6e0b 100644 (file)
         return afGui.meta.entities[getEntityType()];
       };
 
+      $scope.getAdminTpl = function() {
+        return $scope.getMeta().admin_tpl || '~/afGuiEditor/entityConfig/Generic.html';
+      };
+
       $scope.getField = afGui.getField;
 
       $scope.valuesFields = function() {
index eed6f6e7c9c560df12bebe27c10b02bb79c4b57a..1c337c553dc0a3c4f1388389b762f5d3774dc3d2 100644 (file)
@@ -56,5 +56,5 @@
 
 <fieldset ng-if="!$ctrl.entity.loading && $ctrl.editor.allowEntityConfig">
   <legend>{{:: ts('Options') }}</legend>
-  <div ng-include="::'~/afGuiEditor/entityConfig/' + $ctrl.entity.type + '.html'"></div>
+  <div ng-include=":: getAdminTpl()"></div>
 </fieldset>
diff --git a/ext/afform/admin/ang/afGuiEditor/entityConfig/Activity.html b/ext/afform/admin/ang/afGuiEditor/entityConfig/Activity.html
deleted file mode 100644 (file)
index 15e56f1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<div ng-include="'~/afGuiEditor/entityConfig/Generic.html'"></div>
index 6f61bba51aede8b07132f5aa7eba1f09a51348bc..2da528bd352321f1c038a048344749da93f72d87 100644 (file)
 
         // skip this for test and live modes because financial type is set automatically
         cj("#financial_type_id").val(membershipType['financial_type_id']);
-        var term = cj('#num_terms').val();
+        // Get the number of terms from the form, default to 1 if no num_terms element.
+        var term = cj('#num_terms').val() || 1;
         var taxTerm = {/literal}{$taxTerm|@json_encode}{literal};
         var currency = {/literal}{$currency_symbol|@json_encode}{literal};
         var taxExclusiveAmount = membershipType['total_amount_numeric'] * term;