From b864360dd0ac06714c3dc66cb19423dec14f867d Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Fri, 28 Dec 2018 12:59:36 +0000 Subject: [PATCH] Replace deprecated activityType/activityStatus functions with buildOptions for cases --- CRM/Activity/Selector/Activity.php | 11 +++++------ CRM/Activity/Selector/Search.php | 4 +--- CRM/Case/BAO/Case.php | 23 ++++++++--------------- Civi/CCase/Analyzer.php | 3 ++- Civi/CCase/SequenceListener.php | 2 +- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/CRM/Activity/Selector/Activity.php b/CRM/Activity/Selector/Activity.php index bdc1b18550..544724ffde 100644 --- a/CRM/Activity/Selector/Activity.php +++ b/CRM/Activity/Selector/Activity.php @@ -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. diff --git a/CRM/Activity/Selector/Search.php b/CRM/Activity/Selector/Search.php index 340dc7588f..8fb4278334 100644 --- a/CRM/Activity/Selector/Search.php +++ b/CRM/Activity/Selector/Search.php @@ -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 && diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 5bebd48eb6..fb84b9ce35 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -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( diff --git a/Civi/CCase/Analyzer.php b/Civi/CCase/Analyzer.php index 6789360404..f4d1569bb1 100644 --- a/Civi/CCase/Analyzer.php +++ b/Civi/CCase/Analyzer.php @@ -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; diff --git a/Civi/CCase/SequenceListener.php b/Civi/CCase/SequenceListener.php index cd60e81575..7135c84b54 100644 --- a/Civi/CCase/SequenceListener.php +++ b/Civi/CCase/SequenceListener.php @@ -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')); -- 2.25.1