@@ -676,13 +676,11 @@ public static function logActivityAction($activity, $logMessage = NULL) {
676
676
*
677
677
* @return array|int
678
678
* Relevant data object values of open activities
679
+ * @throws \CiviCRM_API3_Exception
679
680
*/
680
681
public static function getActivities ($ params , $ getCount = FALSE ) {
681
682
$ activities = array ();
682
683
683
- // fetch all active activity types
684
- $ activityTypes = CRM_Core_OptionGroup::values ('activity_type ' );
685
-
686
684
// Activity.Get API params
687
685
$ activityParams = array (
688
686
'is_deleted ' => 0 ,
@@ -711,37 +709,11 @@ public static function getActivities($params, $getCount = FALSE) {
711
709
),
712
710
);
713
711
714
- // activity type ID clause
715
- if (!empty ($ params ['activity_type_id ' ])) {
716
- if (is_array ($ params ['activity_type_id ' ])) {
717
- foreach ($ params ['activity_type_id ' ] as $ idx => $ value ) {
718
- $ params ['activity_type_id ' ][$ idx ] = CRM_Utils_Type::escape ($ value , 'Positive ' );
719
- }
720
- $ activityParams ['activity_type_id ' ] = array ('IN ' => $ params ['activity_type_id ' ]);
721
- }
722
- else {
723
- $ activityParams ['activity_type_id ' ] = CRM_Utils_Type::escape ($ params ['activity_type_id ' ], 'Positive ' );
724
- }
725
- }
726
- elseif (!empty ($ activityTypes ) && count ($ activityTypes )) {
727
- $ activityParams ['activity_type_id ' ] = array ('IN ' => array_keys ($ activityTypes ));
728
- }
729
-
730
712
if (!empty ($ params ['activity_status_id ' ])) {
731
713
$ activityParams ['activity_status_id ' ] = array ('IN ' => explode (', ' , $ params ['activity_status_id ' ]));
732
714
}
733
715
734
- $ excludeActivityIDs = array ();
735
- if (!empty ($ params ['activity_type_exclude_id ' ])) {
736
- if (is_array ($ params ['activity_type_exclude_id ' ])) {
737
- foreach ($ params ['activity_type_exclude_id ' ] as $ idx => $ value ) {
738
- $ excludeActivityIDs [$ idx ] = CRM_Utils_Type::escape ($ value , 'Positive ' );
739
- }
740
- }
741
- else {
742
- $ excludeActivityIDs [] = CRM_Utils_Type::escape ($ params ['activity_type_exclude_id ' ], 'Positive ' );
743
- }
744
- }
716
+ $ activityParams ['activity_type_id ' ] = self ::filterActivityTypes ($ params );
745
717
746
718
if (!empty ($ params ['rowCount ' ]) &&
747
719
$ params ['rowCount ' ] > 0
@@ -771,8 +743,8 @@ public static function getActivities($params, $getCount = FALSE) {
771
743
$ result = civicrm_api3 ('Activity ' , 'Get ' , $ activityParams );
772
744
773
745
$ enabledComponents = self ::activityComponents ();
746
+ $ bulkActivityTypeID = CRM_Core_PseudoConstant::getKey ('CRM_Activity_BAO_Activity ' , 'activity_type_id ' , 'Bulk Email ' );
774
747
$ allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns (NULL , NULL , FALSE , FALSE , FALSE , TRUE );
775
- $ bulkActivityTypeID = CRM_Core_PseudoConstant::getKey (__CLASS__ , 'activity_type_id ' , 'Bulk Email ' );
776
748
777
749
// CRM-3553, need to check user has access to target groups.
778
750
$ mailingIDs = CRM_Mailing_BAO_Mailing::mailingACLIDs ();
@@ -797,9 +769,7 @@ public static function getActivities($params, $getCount = FALSE) {
797
769
798
770
foreach ($ result ['values ' ] as $ id => $ activity ) {
799
771
// skip case activities if CiviCase is not enabled OR those actvities which are
800
- if ((!empty ($ activity ['case_id ' ]) && !in_array ('CiviCase ' , $ enabledComponents )) ||
801
- (count ($ excludeActivityIDs ) && in_array ($ activity ['activity_type_id ' ], $ excludeActivityIDs ))
802
- ) {
772
+ if (!empty ($ activity ['case_id ' ]) && !in_array ('CiviCase ' , $ enabledComponents )) {
803
773
continue ;
804
774
}
805
775
@@ -840,7 +810,7 @@ public static function getActivities($params, $getCount = FALSE) {
840
810
else {
841
811
$ activities [$ id ][$ expectedName ] = CRM_Utils_Array::value ($ apiKey , $ activity );
842
812
if ($ apiKey == 'activity_type_id ' ) {
843
- $ activities [$ id ]['activity_type ' ] = CRM_Utils_Array:: value ( $ activities [$ id ][$ expectedName ], $ activityTypes );
813
+ $ activities [$ id ]['activity_type ' ] = CRM_Core_PseudoConstant:: getName ( ' CRM_Activity_BAO_Activity ' , ' activity_type_id ' , $ activities [$ id ][$ expectedName ]);
844
814
}
845
815
elseif ($ apiKey == 'campaign_id ' ) {
846
816
$ activities [$ id ]['campaign ' ] = CRM_Utils_Array::value ($ activities [$ id ][$ expectedName ], $ allCampaigns );
@@ -859,6 +829,60 @@ public static function getActivities($params, $getCount = FALSE) {
859
829
return $ getCount ? count ($ activities ) : $ activities ;
860
830
}
861
831
832
+ /**
833
+ * Filter the activity types to only return the ones we actually asked for
834
+ * Uses params['activity_type_id'] and params['activity_type_exclude_id']
835
+ *
836
+ * @param $params
837
+ * @return array|null (Use in Activity.get API activity_type_id)
838
+ */
839
+ public static function filterActivityTypes ($ params ) {
840
+ $ activityTypes = array ();
841
+
842
+ // If no activity types are specified, get all the active ones
843
+ if (empty ($ params ['activity_type_id ' ])) {
844
+ $ activityTypes = CRM_Activity_BAO_Activity::buildOptions ('activity_type_id ' , 'get ' );
845
+ }
846
+
847
+ // If no activity types are specified or excluded, return the list of all active ones
848
+ if (empty ($ params ['activity_type_id ' ]) && empty ($ params ['activity_type_exclude_id ' ])) {
849
+ if (!empty ($ activityTypes )) {
850
+ return array ('IN ' => array_keys ($ activityTypes ));
851
+ }
852
+ return NULL ;
853
+ }
854
+
855
+ // If we have specified activity types, build a list to return, excluding the ones we don't want.
856
+ if (!empty ($ params ['activity_type_id ' ])) {
857
+ if (!is_array ($ params ['activity_type_id ' ])) {
858
+ // Turn it into array if only one specified, so we don't duplicate processing below
859
+ $ params ['activity_type_id ' ] = array ($ params ['activity_type_id ' ] => $ params ['activity_type_id ' ]);
860
+ }
861
+ foreach ($ params ['activity_type_id ' ] as $ value ) {
862
+ // Add each activity type that was specified to list
863
+ $ value = CRM_Utils_Type::escape ($ value , 'Positive ' );
864
+ $ activityTypes [$ value ] = $ value ;
865
+ }
866
+ }
867
+
868
+ // Build the list of activity types to exclude (from $params['activity_type_exclude_id'])
869
+ if (!empty ($ params ['activity_type_exclude_id ' ])) {
870
+ if (!is_array ($ params ['activity_type_exclude_id ' ])) {
871
+ // Turn it into array if only one specified, so we don't duplicate processing below
872
+ $ params ['activity_type_exclude_id ' ] = array ($ params ['activity_type_exclude_id ' ] => $ params ['activity_type_exclude_id ' ]);
873
+ }
874
+ foreach ($ params ['activity_type_exclude_id ' ] as $ value ) {
875
+ // Remove each activity type from list if it should be excluded
876
+ $ value = CRM_Utils_Type::escape ($ value , 'Positive ' );
877
+ if (array_key_exists ($ value , $ activityTypes )) {
878
+ unset($ activityTypes [$ value ]);
879
+ }
880
+ }
881
+ }
882
+
883
+ return array ('IN ' => array_keys ($ activityTypes ));
884
+ }
885
+
862
886
/**
863
887
* Get the list Activities.
864
888
*
@@ -1181,6 +1205,8 @@ public static function getActivitiesCount($input) {
1181
1205
/**
1182
1206
* Get the activity Count.
1183
1207
*
1208
+ * @deprecated
1209
+ *
1184
1210
* @param array $input
1185
1211
* Array of parameters.
1186
1212
* Keys include
@@ -1216,6 +1242,8 @@ public static function deprecatedGetActivitiesCount($input) {
1216
1242
/**
1217
1243
* Get the activity sql clause to pick activities.
1218
1244
*
1245
+ * @deprecated
1246
+ *
1219
1247
* @param array $input
1220
1248
* Array of parameters.
1221
1249
* Keys include
@@ -1476,9 +1504,7 @@ public static function sendEmail(
1476
1504
}
1477
1505
1478
1506
//create the meta level record first ( email activity )
1479
- $ activityTypeID = CRM_Core_PseudoConstant::getKey ('CRM_Activity_BAO_Activity ' , 'activity_type_id ' ,
1480
- 'Email '
1481
- );
1507
+ $ activityTypeID = CRM_Core_PseudoConstant::getKey ('CRM_Activity_BAO_Activity ' , 'activity_type_id ' , 'Email ' );
1482
1508
1483
1509
// CRM-6265: save both text and HTML parts in details (if present)
1484
1510
if ($ html and $ text ) {
@@ -1496,7 +1522,7 @@ public static function sendEmail(
1496
1522
'subject ' => $ subject ,
1497
1523
'details ' => $ details ,
1498
1524
// FIXME: check for name Completed and get ID from that lookup
1499
- 'status_id ' => 2 ,
1525
+ 'status_id ' => CRM_Core_PseudoConstant:: getKey ( ' CRM_Activity_BAO_Activity ' , ' status_id ' , ' Completed ' ) ,
1500
1526
'campaign_id ' => $ campaignId ,
1501
1527
);
1502
1528
@@ -2095,7 +2121,8 @@ public static function addActivity(
2095
2121
}
2096
2122
elseif ($ activity ->__table == 'civicrm_contribution ' ) {
2097
2123
// create activity record only for Completed Contributions
2098
- if ($ activity ->contribution_status_id != 1 ) {
2124
+ $ contributionCompletedStatusId = CRM_Core_PseudoConstant::getKey ('CRM_Contribute_BAO_Contribution ' , 'contribution_status_id ' , 'Completed ' );
2125
+ if ($ activity ->contribution_status_id != $ contributionCompletedStatusId ) {
2099
2126
return NULL ;
2100
2127
}
2101
2128
$ activityType = $ component = 'Contribution ' ;
@@ -2383,10 +2410,7 @@ public static function createFollowupActivity($activityId, $params) {
2383
2410
$ followupParams = array ();
2384
2411
$ followupParams ['parent_id ' ] = $ activityId ;
2385
2412
$ followupParams ['source_contact_id ' ] = CRM_Core_Session::getLoggedInContactID ();
2386
- $ followupParams ['status_id ' ] = CRM_Core_PseudoConstant::getKey ('CRM_Activity_BAO_Activity ' ,
2387
- 'activity_status_id ' ,
2388
- 'Scheduled '
2389
- );
2413
+ $ followupParams ['status_id ' ] = CRM_Core_PseudoConstant::getKey ('CRM_Activity_BAO_Activity ' , 'activity_status_id ' , 'Scheduled ' );
2390
2414
2391
2415
$ followupParams ['activity_type_id ' ] = $ params ['followup_activity_type_id ' ];
2392
2416
// Get Subject of Follow-up Activiity, CRM-4491
0 commit comments