Replace deprecated activityType/activityStatus functions with buildOptions for cases
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Fri, 28 Dec 2018 12:59:36 +0000 (12:59 +0000)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Fri, 22 Feb 2019 16:41:35 +0000 (16:41 +0000)
CRM/Activity/Selector/Activity.php
CRM/Activity/Selector/Search.php
CRM/Case/BAO/Case.php
Civi/CCase/Analyzer.php
Civi/CCase/SequenceListener.php

index bdc1b18550c0f77b33650f8bd7ef80c8f65ee4f6..544724ffde994e4a22acc8f86fa5d08dbf8d1657 100644 (file)
@@ -112,8 +112,8 @@ class CRM_Activity_Selector_Activity extends CRM_Core_Selector_Base implements C
     $activityId = NULL,
     $key = NULL,
     $compContext = NULL) {
-    static $activityActTypes = NULL;
-    //CRM-14277 added addtitional param to handle activity search
+
+    //CRM-14277 added additional param to handle activity search
     $extraParams = "&searchContext=activity";
 
     $extraParams .= ($key) ? "&key={$key}" : NULL;
@@ -124,11 +124,10 @@ class CRM_Activity_Selector_Activity extends CRM_Core_Selector_Base implements C
     $showView = TRUE;
     $showUpdate = $showDelete = FALSE;
     $qsUpdate = NULL;
+    $url = NULL;
+    $qsView = NULL;
 
-    if (!$activityActTypes) {
-      $activeActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
-    }
-    $activityTypeName = CRM_Utils_Array::value($activityTypeId, $activeActTypes);
+    $activityTypeName = CRM_Core_PseudoConstant::getName('CRM_Activity_BAO_Activity', 'activity_type_id', $activityTypeId);
 
     // CRM-7607
     // Lets allow to have normal operation for only activity types.
index 340dc7588fb7d2c17e9314cb2f73571059b3b3ca..8fb42783349f1787c51fd0fec04a8839a978f82f 100644 (file)
@@ -273,8 +273,7 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
-    // Get all activity types
-    $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
+    $bulkActivityTypeID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Bulk Email');
 
     while ($result->fetch()) {
       $row = array();
@@ -313,7 +312,6 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM
       if ($row['activity_is_test']) {
         $row['activity_type'] = $row['activity_type'] . " (test)";
       }
-      $bulkActivityTypeID = CRM_Utils_Array::key('Bulk Email', $activityTypes);
       $row['mailingId'] = '';
       if (
         $accessCiviMail &&
index 5bebd48eb665db60311eed10265e69c20f1bdabb..fb84b9ce3546ea7ce24985d3a304b20a44dfaf6c 100644 (file)
@@ -1061,7 +1061,6 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
     $caseCount = CRM_Core_DAO::singleValueQuery('SELECT FOUND_ROWS()');
 
     $activityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, TRUE);
-    $activityStatuses = CRM_Core_PseudoConstant::activityStatus();
 
     $url = CRM_Utils_System::url("civicrm/case/activity",
       "reset=1&cid={$contactID}&caseid={$caseID}", FALSE, NULL, FALSE
@@ -1096,7 +1095,6 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
     $caseActivities = array();
 
     while ($dao->fetch()) {
-      $caseActivity = array();
       $caseActivityId = $dao->id;
 
       $allowView = self::checkPermission($caseActivityId, 'view', $dao->activity_type_id, $userID);
@@ -1175,8 +1173,8 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
         }
       }
 
-      //Activity Status
-      $caseActivities[$caseActivityId]['status_id'] = $activityStatuses[$dao->status];
+      // Activity Status Label for Case activities list
+      $caseActivities[$caseActivityId]['status_id'] = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'activity_status_id', $dao->status);
 
       // FIXME: Why are we not using CRM_Core_Action for these links? This is too much manual work and likely to get out-of-sync with core markup.
       $url = "";
@@ -1977,9 +1975,7 @@ SELECT civicrm_contact.id as casemanager_id,
       return array();
     }
 
-    $linkActType = array_search('Link Cases',
-      CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name')
-    );
+    $linkActType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Link Cases');
     if (!$linkActType) {
       return array();
     }
@@ -2138,8 +2134,8 @@ SELECT civicrm_contact.id as casemanager_id,
       return $mainCaseIds;
     }
 
-    $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
-    $activityStatuses = CRM_Core_PseudoConstant::activityStatus('name');
+    $activityTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'validate');
+    $completedActivityStatus = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
     $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
     $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
@@ -2471,11 +2467,11 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
         }
       }
 
-      //Create merge activity record. Source for merge activity is the logged in user's contact ID ($currentUserId).
+      // Create merge activity record. Source for merge activity is the logged in user's contact ID ($currentUserId).
       $activityParams = array(
         'subject' => $mergeActSubject,
         'details' => $mergeActSubjectDetails,
-        'status_id' => array_search('Completed', $activityStatuses),
+        'status_id' => $completedActivityStatus,
         'activity_type_id' => $mergeActType,
         'source_contact_id' => $currentUserId,
         'activity_date_time' => date('YmdHis'),
@@ -2720,10 +2716,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
 
     //do further only when operation is granted.
     if ($allow) {
-      $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
-
-      //get the activity type name.
-      $actTypeName = CRM_Utils_Array::value($actTypeId, $activityTypes);
+      $actTypeName = CRM_Core_PseudoConstant::getName('CRM_Activity_BAO_Activity', 'activity_type_id', $actTypeId);
 
       //do not allow multiple copy / edit action.
       $singletonNames = array(
index 678936040470ede6ec3d265ae9feb8ae157e3b78..f4d1569bb1ea01f07b0140924a7e4d9a1d9c7b12 100644 (file)
@@ -132,6 +132,7 @@ class Analyzer {
 
   /**
    * Get a single activity record by type.
+   * This function is only used by SequenceListenerTest
    *
    * @param string $type
    * @throws \Civi\CCase\Exception\MultipleActivityException
@@ -139,7 +140,7 @@ class Analyzer {
    */
   public function getSingleActivity($type) {
     $idx = $this->getActivityIndex(array('activity_type_id', 'id'));
-    $actTypes = array_flip(\CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'));
+    $actTypes = array_flip(\CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'validate'));
     $typeId = $actTypes[$type];
     $count = isset($idx[$typeId]) ? count($idx[$typeId]) : 0;
 
index cd60e81575bcf5e948dee7629795be0e66193117..7135c84b540c373e094d516dab8951bb060e10b0 100644 (file)
@@ -51,7 +51,7 @@ class SequenceListener implements CaseChangeListener {
       return;
     }
 
-    $actTypes = array_flip(\CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name'));
+    $actTypes = array_flip(\CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'validate'));
     $actStatuses = array_flip(\CRM_Activity_BAO_Activity::getStatusesByType(\CRM_Activity_BAO_Activity::COMPLETED));
 
     $actIndex = $analyzer->getActivityIndex(array('activity_type_id', 'status_id'));