From 96f94695beed8bd791c57278e7b72e3f96e03a62 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 5 Apr 2019 17:48:30 +1300 Subject: [PATCH] Array syntax reformat on activity files --- CRM/Activity/ActionMapping.php | 4 +- CRM/Activity/BAO/Activity.php | 297 +++++++++++++----------- CRM/Activity/BAO/ActivityAssignment.php | 11 +- CRM/Activity/BAO/ActivityContact.php | 28 +-- CRM/Activity/BAO/ActivityTarget.php | 13 +- CRM/Activity/BAO/ICalendar.php | 8 +- CRM/Activity/BAO/Query.php | 126 ++++++---- CRM/Activity/Form/Activity.php | 213 +++++++++-------- CRM/Activity/Import/Form/MapField.php | 104 ++++----- 9 files changed, 444 insertions(+), 360 deletions(-) diff --git a/CRM/Activity/ActionMapping.php b/CRM/Activity/ActionMapping.php index e0577f97e3..9f5dccb1f6 100644 --- a/CRM/Activity/ActionMapping.php +++ b/CRM/Activity/ActionMapping.php @@ -56,7 +56,7 @@ class CRM_Activity_ActionMapping extends \Civi\ActionSchedule\Mapping { * @param \Civi\ActionSchedule\Event\MappingRegisterEvent $registrations */ public static function onRegisterActionMappings(\Civi\ActionSchedule\Event\MappingRegisterEvent $registrations) { - $registrations->register(CRM_Activity_ActionMapping::create(array( + $registrations->register(CRM_Activity_ActionMapping::create([ 'id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID, 'entity' => 'civicrm_activity', 'entity_label' => ts('Activity'), @@ -65,7 +65,7 @@ class CRM_Activity_ActionMapping extends \Civi\ActionSchedule\Mapping { 'entity_status' => 'activity_status', 'entity_status_label' => ts('Activity Status'), 'entity_date_start' => 'activity_date_time', - ))); + ])); } /** diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 9fdcf31dea..dc66751ca4 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -207,7 +207,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { // CRM-4525 log activity delete $logMsg = 'Case Activity deleted for'; - $msgs = array(); + $msgs = []; $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); @@ -236,10 +236,10 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { // delete the recently created Activity if ($result) { - $activityRecent = array( + $activityRecent = [ 'id' => $activity->id, 'type' => 'Activity', - ); + ]; CRM_Utils_Recent::del($activityRecent); } @@ -361,11 +361,11 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $targetID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Targets'); if (isset($params['source_contact_id'])) { - $acParams = array( + $acParams = [ 'activity_id' => $activityId, 'contact_id' => $params['source_contact_id'], 'record_type_id' => $sourceID, - ); + ]; self::deleteActivityContact($activityId, $sourceID); CRM_Activity_BAO_ActivityContact::create($acParams); } @@ -377,7 +377,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $resultAssignment = NULL; if (!empty($params['assignee_contact_id'])) { - $assignmentParams = array('activity_id' => $activityId); + $assignmentParams = ['activity_id' => $activityId]; if (is_array($params['assignee_contact_id'])) { if (CRM_Utils_Array::value('deleteActivityAssignment', $params, TRUE)) { @@ -387,11 +387,11 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { foreach ($params['assignee_contact_id'] as $acID) { if ($acID) { - $assigneeParams = array( + $assigneeParams = [ 'activity_id' => $activityId, 'contact_id' => $acID, 'record_type_id' => $assigneeID, - ); + ]; CRM_Activity_BAO_ActivityContact::create($assigneeParams); } } @@ -430,8 +430,8 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $resultTarget = NULL; if (!empty($params['target_contact_id'])) { - $targetParams = array('activity_id' => $activityId); - $resultTarget = array(); + $targetParams = ['activity_id' => $activityId]; + $resultTarget = []; if (is_array($params['target_contact_id'])) { if (CRM_Utils_Array::value('deleteActivityTarget', $params, TRUE)) { // first delete existing targets if any @@ -440,11 +440,11 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { foreach ($params['target_contact_id'] as $tid) { if ($tid) { - $targetContactParams = array( + $targetContactParams = [ 'activity_id' => $activityId, 'contact_id' => $tid, 'record_type_id' => $targetID, - ); + ]; CRM_Activity_BAO_ActivityContact::create($targetContactParams); } } @@ -483,7 +483,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $logMsg = "Activity created for "; } - $msgs = array(); + $msgs = []; if (isset($params['source_contact_id'])) { $msgs[] = "source={$params['source_contact_id']}"; } @@ -529,7 +529,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $transaction->commit(); if (empty($params['skipRecentView'])) { - $recentOther = array(); + $recentOther = []; if (!empty($params['case_id'])) { $caseContactID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $params['case_id'], 'contact_id', 'case_id'); $url = CRM_Utils_System::url('civicrm/case/activity/view', @@ -597,7 +597,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); // if the subject contains a ‘[case #…]’ string, file that activity on the related case (CRM-5916) - $matches = array(); + $matches = []; $subjectToMatch = CRM_Utils_Array::value('subject', $params); if (preg_match('/\[case #([0-9a-h]{7})\]/', $subjectToMatch, $matches)) { $key = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY); @@ -608,10 +608,10 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $query = "SELECT id FROM civicrm_case WHERE id = '" . CRM_Core_DAO::escapeString($matches[1]) . "'"; } if (!empty($matches)) { - $caseParams = array( + $caseParams = [ 'activity_id' => $activity->id, 'case_id' => CRM_Core_DAO::singleValueQuery($query), - ); + ]; if ($caseParams['case_id']) { CRM_Case_BAO_Case::processCaseActivity($caseParams); } @@ -646,13 +646,13 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $id = self::getActivityContact($activity->id, $sourceID); } - $logParams = array( + $logParams = [ 'entity_table' => 'civicrm_activity', 'entity_id' => $activity->id, 'modified_id' => $id, 'modified_date' => date('YmdHis'), 'data' => $logMessage, - ); + ]; CRM_Core_BAO_Log::add($logParams); return TRUE; } @@ -677,7 +677,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { * @throws \CiviCRM_API3_Exception */ public static function getActivities($params) { - $activities = array(); + $activities = []; // Activity.Get API params $activityParams = self::getActivityParamsForDashboardFunctions($params); @@ -730,7 +730,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings')) ); - $mappingParams = array( + $mappingParams = [ 'id' => 'activity_id', 'source_record_id' => 'source_record_id', 'activity_type_id' => 'activity_type_id', @@ -742,11 +742,11 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { 'source_contact_id' => 'source_contact_id', 'source_contact_name' => 'source_contact_name', 'case_id' => 'case_id', - ); + ]; foreach ($result['values'] as $id => $activity) { - $activities[$id] = array(); + $activities[$id] = []; $isBulkActivity = (!$bulkActivityTypeID || ($bulkActivityTypeID === $activity['activity_type_id'])); $activities[$id]['target_contact_counter'] = count($activity['target_contact_id']); @@ -760,11 +760,14 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } } foreach ($mappingParams as $apiKey => $expectedName) { - if (in_array($apiKey, array('assignee_contact_name', 'target_contact_name'))) { - $activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity, array()); + if (in_array($apiKey, [ + 'assignee_contact_name', + 'target_contact_name', + ])) { + $activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity, []); if ($isBulkActivity) { - $activities[$id]['recipients'] = ts('(%1 recipients)', array(1 => count($activity['target_contact_name']))); + $activities[$id]['recipients'] = ts('(%1 recipients)', [1 => count($activity['target_contact_name'])]); $activities[$id]['mailingId'] = FALSE; if ($accessCiviMail && ($mailingIDs === TRUE || in_array($activity['source_record_id'], $mailingIDs)) @@ -812,7 +815,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { * @return array|null (Use in Activity.get API activity_type_id) */ public static function filterActivityTypes($params) { - $activityTypes = array(); + $activityTypes = []; // If no activity types are specified, get all the active ones if (empty($params['activity_type_id'])) { @@ -822,7 +825,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { // If no activity types are specified or excluded, return the list of all active ones if (empty($params['activity_type_id']) && empty($params['activity_type_exclude_id'])) { if (!empty($activityTypes)) { - return array('IN' => array_keys($activityTypes)); + return ['IN' => array_keys($activityTypes)]; } return NULL; } @@ -831,7 +834,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { if (!empty($params['activity_type_id'])) { if (!is_array($params['activity_type_id'])) { // Turn it into array if only one specified, so we don't duplicate processing below - $params['activity_type_id'] = array($params['activity_type_id'] => $params['activity_type_id']); + $params['activity_type_id'] = [$params['activity_type_id'] => $params['activity_type_id']]; } foreach ($params['activity_type_id'] as $value) { // Add each activity type that was specified to list @@ -844,7 +847,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { if (!empty($params['activity_type_exclude_id'])) { if (!is_array($params['activity_type_exclude_id'])) { // Turn it into array if only one specified, so we don't duplicate processing below - $params['activity_type_exclude_id'] = array($params['activity_type_exclude_id'] => $params['activity_type_exclude_id']); + $params['activity_type_exclude_id'] = [$params['activity_type_exclude_id'] => $params['activity_type_exclude_id']]; } foreach ($params['activity_type_exclude_id'] as $value) { // Remove each activity type from list if it should be excluded @@ -855,7 +858,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } } - return array('IN' => array_keys($activityTypes)); + return ['IN' => array_keys($activityTypes)]; } /** @@ -902,7 +905,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { * Array of component id and name. */ public static function activityComponents($excludeComponentHandledActivities = TRUE) { - $components = array(); + $components = []; $compInfo = CRM_Core_Component::getEnabledComponents(); foreach ($compInfo as $compObj) { $includeComponent = !$excludeComponentHandledActivities || !empty($compObj->info['showActivitiesInCore']); @@ -1002,7 +1005,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { list($fromDisplayName, $fromEmail, $fromDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID); if (!$fromEmail) { - return array(count($contactDetails), 0, count($contactDetails)); + return [count($contactDetails), 0, count($contactDetails)]; } if (!trim($fromDisplayName)) { $fromDisplayName = $fromEmail; @@ -1032,7 +1035,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $details .= $additionalDetails; } - $activityParams = array( + $activityParams = [ 'source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), @@ -1041,7 +1044,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { // FIXME: check for name Completed and get ID from that lookup 'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Completed'), 'campaign_id' => $campaignId, - ); + ]; // CRM-5916: strip [case #…] before saving the activity (if present in subject) $activityParams['subject'] = preg_replace('/\[case #([0-9a-h]{7})\] /', '', $activityParams['subject']); @@ -1060,7 +1063,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id ); - $returnProperties = array(); + $returnProperties = []; if (isset($messageToken['contact'])) { foreach ($messageToken['contact'] as $key => $value) { $returnProperties[$value] = 1; @@ -1076,7 +1079,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } // get token details for contacts, call only if tokens are used - $details = array(); + $details = []; if (!empty($returnProperties) || !empty($tokens) || !empty($allTokens)) { list($details) = CRM_Utils_Token::getTokenDetails( $contactIds, @@ -1088,7 +1091,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } // call token hook - $tokens = array(); + $tokens = []; CRM_Utils_Hook::tokens($tokens); $categories = array_keys($tokens); @@ -1098,7 +1101,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $escapeSmarty = TRUE; } - $contributionDetails = array(); + $contributionDetails = []; if (!empty($contributionIds)) { $contributionDetails = CRM_Contribute_BAO_Contribution::replaceContributionTokens( $contributionIds, @@ -1111,7 +1114,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { ); } - $sent = $notSent = array(); + $sent = $notSent = []; foreach ($contactDetails as $values) { $contactId = $values['contact_id']; $emailAddress = $values['email']; @@ -1177,7 +1180,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } } - return array($sent, $activity->id); + return [$sent, $activity->id]; } /** @@ -1195,7 +1198,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { public static function sendSMS( &$contactDetails = NULL, &$activityParams, - &$smsProviderParams = array(), + &$smsProviderParams = [], &$contactIds = NULL, $sourceContactId = NULL ) { @@ -1210,7 +1213,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { if (is_array($contactIds) && !empty($contactIds) && empty($contactDetails)) { foreach ($contactIds as $id) { try { - $contactDetails[] = civicrm_api3('Contact', 'getsingle', array('contact_id' => $id)); + $contactDetails[] = civicrm_api3('Contact', 'getsingle', ['contact_id' => $id]); } catch (Exception $e) { // Contact Id doesn't exist @@ -1231,14 +1234,14 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $text = &$activityParams['sms_text_message']; // Create the meta level record first ( sms activity ) - $activityParams = array( + $activityParams = [ 'source_contact_id' => $sourceContactId, 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'SMS'), 'activity_date_time' => date('YmdHis'), 'subject' => $activityParams['activity_subject'], 'details' => $text, 'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Completed'), - ); + ]; $activity = self::create($activityParams); $activityID = $activity->id; @@ -1246,18 +1249,18 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { // token replacement of addressee/email/postal greetings // get the tokens added in subject and message $messageToken = CRM_Utils_Token::getTokens($text); - $returnProperties = array(); + $returnProperties = []; if (isset($messageToken['contact'])) { foreach ($messageToken['contact'] as $key => $value) { $returnProperties[$value] = 1; } } // Call tokens hook - $tokens = array(); + $tokens = []; CRM_Utils_Hook::tokens($tokens); $categories = array_keys($tokens); // get token details for contacts, call only if tokens are used - $tokenDetails = array(); + $tokenDetails = []; if (!empty($returnProperties) || !empty($tokens)) { list($tokenDetails) = CRM_Utils_Token::getTokenDetails($contactIds, $returnProperties, @@ -1268,7 +1271,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } $success = 0; - $errMsgs = array(); + $errMsgs = []; foreach ($contactDetails as $contact) { $contactId = $contact['contact_id']; @@ -1326,7 +1329,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $sent = $errMsgs; } - return array($sent, $activity->id, $success); + return [$sent, $activity->id, $success]; } /** @@ -1347,7 +1350,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { public static function sendSMSMessage( $toID, &$tokenText, - $smsProviderParams = array(), + $smsProviderParams = [], $activityID, $sourceContactID = NULL ) { @@ -1358,7 +1361,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } elseif ($toID) { // No phone number specified, so find a suitable one for the contact - $filters = array('is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0); + $filters = ['is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0]; $toPhoneNumbers = CRM_Core_BAO_Phone::allPhones($toID, FALSE, 'Mobile', $filters); // To get primary mobile phonenumber, if not get the first mobile phonenumber if (!empty($toPhoneNumbers)) { @@ -1382,7 +1385,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $smsProviderParams['contact_id'] = $toID; $smsProviderParams['parent_activity_id'] = $activityID; - $providerObj = CRM_SMS_Provider::singleton(array('provider_id' => $smsProviderParams['provider_id'])); + $providerObj = CRM_SMS_Provider::singleton(['provider_id' => $smsProviderParams['provider_id']]); $sendResult = $providerObj->send($recipient, $smsProviderParams, $tokenText, NULL, $sourceContactID); if (PEAR::isError($sendResult)) { return $sendResult; @@ -1390,11 +1393,11 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { // add activity target record for every sms that is sent $targetID = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Targets'); - $activityTargetParams = array( + $activityTargetParams = [ 'activity_id' => $activityID, 'contact_id' => $toID, 'record_type_id' => $targetID, - ); + ]; CRM_Activity_BAO_ActivityContact::create($activityTargetParams); return TRUE; @@ -1454,7 +1457,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); // create the params array - $mailParams = array( + $mailParams = [ 'groupName' => 'Activity Email Sender', 'from' => $from, 'toName' => $toDisplayName, @@ -1465,18 +1468,18 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { 'text' => $text_message, 'html' => $html_message, 'attachments' => $attachments, - ); + ]; if (!CRM_Utils_Mail::send($mailParams)) { return FALSE; } // add activity target record for every mail that is send - $activityTargetParams = array( + $activityTargetParams = [ 'activity_id' => $activityID, 'contact_id' => $toID, 'record_type_id' => $targetID, - ); + ]; CRM_Activity_BAO_ActivityContact::create($activityTargetParams); return TRUE; } @@ -1496,26 +1499,26 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { public static function &importableFields($status = FALSE) { if (!self::$_importableFields) { if (!self::$_importableFields) { - self::$_importableFields = array(); + self::$_importableFields = []; } if (!$status) { - $fields = array('' => array('title' => ts('- do not import -'))); + $fields = ['' => ['title' => ts('- do not import -')]]; } else { - $fields = array('' => array('title' => ts('- Activity Fields -'))); + $fields = ['' => ['title' => ts('- Activity Fields -')]]; } $tmpFields = CRM_Activity_DAO_Activity::import(); $contactFields = CRM_Contact_BAO_Contact::importableFields('Individual', NULL); // Using new Dedupe rule. - $ruleParams = array( + $ruleParams = [ 'contact_type' => 'Individual', 'used' => 'Unsupervised', - ); + ]; $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams); - $tmpConatctField = array(); + $tmpConatctField = []; if (is_array($fieldsArray)) { foreach ($fieldsArray as $value) { $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', @@ -1551,7 +1554,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { */ public static function getContactActivity($contactId) { // @todo remove this function entirely. - $activities = array(); + $activities = []; $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); @@ -1579,7 +1582,7 @@ WHERE contact_id = $contactId $activityIds = array_keys($activities); if (count($activityIds) < 1) { - return array(); + return []; } $activityIds = implode(',', $activityIds); @@ -1628,7 +1631,7 @@ WHERE activity.id IN ($activityIds)"; &$activity, $activityType = 'Membership Signup', $targetContactID = NULL, - $params = array() + $params = [] ) { $date = date('YmdHis'); if ($activity->__table == 'civicrm_membership') { @@ -1650,10 +1653,10 @@ WHERE activity.id IN ($activityIds)"; // retrieve existing activity based on source_record_id and activity_type if (empty($params['id'])) { - $params['id'] = CRM_Utils_Array::value('id', civicrm_api3('Activity', 'Get', array( + $params['id'] = CRM_Utils_Array::value('id', civicrm_api3('Activity', 'Get', [ 'source_record_id' => $activity->id, 'activity_type_id' => $activityType, - ))); + ])); } if (!empty($params['id'])) { // CRM-13237 : if activity record found, update it with campaign id of contribution @@ -1663,7 +1666,7 @@ WHERE activity.id IN ($activityIds)"; $date = CRM_Utils_Date::isoToMysql($activity->receive_date); } - $activityParams = array( + $activityParams = [ 'source_contact_id' => $activity->contact_id, 'source_record_id' => $activity->id, 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', $activityType), @@ -1672,7 +1675,7 @@ WHERE activity.id IN ($activityIds)"; 'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'), 'skipRecentView' => TRUE, 'campaign_id' => $activity->campaign_id, - ); + ]; $activityParams = array_merge($activityParams, $params); if (empty($activityParams['subject'])) { @@ -1771,12 +1774,12 @@ WHERE activity.id IN ($activityIds)"; * Id of parent activity otherwise false. */ public static function getParentActivity($activityId) { - static $parentActivities = array(); + static $parentActivities = []; $activityId = CRM_Utils_Type::escape($activityId, 'Integer'); if (!array_key_exists($activityId, $parentActivities)) { - $parentActivities[$activityId] = array(); + $parentActivities[$activityId] = []; $parentId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityId, @@ -1799,12 +1802,12 @@ WHERE activity.id IN ($activityIds)"; * $params count of prior activities otherwise false. */ public static function getPriorCount($activityID) { - static $priorCounts = array(); + static $priorCounts = []; $activityID = CRM_Utils_Type::escape($activityID, 'Integer'); if (!array_key_exists($activityID, $priorCounts)) { - $priorCounts[$activityID] = array(); + $priorCounts[$activityID] = []; $originalID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'original_id' @@ -1818,7 +1821,7 @@ WHERE ( id = {$originalID} OR original_id = {$originalID} ) AND is_current_revision = 0 AND id < {$activityID} "; - $params = array(1 => array($originalID, 'Integer')); + $params = [1 => [$originalID, 'Integer']]; $count = CRM_Core_DAO::singleValueQuery($query, $params); } $priorCounts[$activityID] = $count ? $count : 0; @@ -1838,13 +1841,13 @@ AND id < {$activityID} * prior activities info. */ public static function getPriorAcitivities($activityID, $onlyPriorRevisions = FALSE) { - static $priorActivities = array(); + static $priorActivities = []; $activityID = CRM_Utils_Type::escape($activityID, 'Integer'); $index = $activityID . '_' . (int) $onlyPriorRevisions; if (!array_key_exists($index, $priorActivities)) { - $priorActivities[$index] = array(); + $priorActivities[$index] = []; $originalID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, @@ -1867,7 +1870,7 @@ AND cl.modified_id = c.id } $query .= " ORDER BY ca.id DESC"; - $params = array(1 => array($originalID, 'Integer')); + $params = [1 => [$originalID, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($query, $params); while ($dao->fetch()) { @@ -1890,12 +1893,12 @@ AND cl.modified_id = c.id * current activity id. */ public static function getLatestActivityId($activityID) { - static $latestActivityIds = array(); + static $latestActivityIds = []; $activityID = CRM_Utils_Type::escape($activityID, 'Integer'); if (!array_key_exists($activityID, $latestActivityIds)) { - $latestActivityIds[$activityID] = array(); + $latestActivityIds[$activityID] = []; $originalID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, @@ -1904,7 +1907,7 @@ AND cl.modified_id = c.id if ($originalID) { $activityID = $originalID; } - $params = array(1 => array($activityID, 'Integer')); + $params = [1 => [$activityID, 'Integer']]; $query = "SELECT id from civicrm_activity where original_id = %1 and is_current_revision = 1"; $latestActivityIds[$activityID] = CRM_Core_DAO::singleValueQuery($query, $params); @@ -1927,7 +1930,7 @@ AND cl.modified_id = c.id return NULL; } - $followupParams = array(); + $followupParams = []; $followupParams['parent_id'] = $activityId; $followupParams['source_contact_id'] = CRM_Core_Session::getLoggedInContactID(); $followupParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Scheduled'); @@ -2011,14 +2014,14 @@ AND cl.modified_id = c.id */ public static function getStatusesByType($type) { if (!isset(Civi::$statics[__CLASS__][__FUNCTION__])) { - $statuses = civicrm_api3('OptionValue', 'get', array( + $statuses = civicrm_api3('OptionValue', 'get', [ 'option_group_id' => 'activity_status', - 'return' => array('value', 'name', 'filter'), - 'options' => array('limit' => 0), - )); + 'return' => ['value', 'name', 'filter'], + 'options' => ['limit' => 0], + ]); Civi::$statics[__CLASS__][__FUNCTION__] = $statuses['values']; } - $ret = array(); + $ret = []; foreach (Civi::$statics[__CLASS__][__FUNCTION__] as $status) { if ($status['filter'] == $type) { $ret[$status['value']] = $status['name']; @@ -2048,7 +2051,7 @@ AND cl.modified_id = c.id * array of exportable Fields */ public static function exportableFields($name = 'Activity') { - self::$_exportableFields[$name] = array(); + self::$_exportableFields[$name] = []; // TODO: ideally we should retrieve all fields from xml, in this case since activity processing is done // my case hence we have defined fields as case_* @@ -2058,53 +2061,77 @@ AND cl.modified_id = c.id 'title' => ts('Source Contact ID'), 'type' => CRM_Utils_Type::T_INT, ]; - $exportableFields['source_contact'] = array( + $exportableFields['source_contact'] = [ 'title' => ts('Source Contact'), 'type' => CRM_Utils_Type::T_STRING, - ); + ]; - $Activityfields = array( - 'activity_type' => array( + $Activityfields = [ + 'activity_type' => [ 'title' => ts('Activity Type'), 'name' => 'activity_type', 'type' => CRM_Utils_Type::T_STRING, 'searchByLabel' => TRUE, - ), - 'activity_status' => array( + ], + 'activity_status' => [ 'title' => ts('Activity Status'), 'name' => 'activity_status', 'type' => CRM_Utils_Type::T_STRING, 'searchByLabel' => TRUE, - ), - 'activity_priority' => array( + ], + 'activity_priority' => [ 'title' => ts('Activity Priority'), 'name' => 'activity_priority', 'type' => CRM_Utils_Type::T_STRING, 'searchByLabel' => TRUE, - ), - ); + ], + ]; $fields = array_merge($Activityfields, $exportableFields); } else { // Set title to activity fields. - $fields = array( - 'case_activity_subject' => array('title' => ts('Activity Subject'), 'type' => CRM_Utils_Type::T_STRING), - 'case_source_contact_id' => array('title' => ts('Activity Reporter'), 'type' => CRM_Utils_Type::T_STRING), - 'case_recent_activity_date' => array('title' => ts('Activity Actual Date'), 'type' => CRM_Utils_Type::T_DATE), - 'case_scheduled_activity_date' => array( + $fields = [ + 'case_activity_subject' => [ + 'title' => ts('Activity Subject'), + 'type' => CRM_Utils_Type::T_STRING, + ], + 'case_source_contact_id' => [ + 'title' => ts('Activity Reporter'), + 'type' => CRM_Utils_Type::T_STRING, + ], + 'case_recent_activity_date' => [ + 'title' => ts('Activity Actual Date'), + 'type' => CRM_Utils_Type::T_DATE, + ], + 'case_scheduled_activity_date' => [ 'title' => ts('Activity Scheduled Date'), 'type' => CRM_Utils_Type::T_DATE, - ), - 'case_recent_activity_type' => array('title' => ts('Activity Type'), 'type' => CRM_Utils_Type::T_STRING), - 'case_activity_status' => array('title' => ts('Activity Status'), 'type' => CRM_Utils_Type::T_STRING), - 'case_activity_duration' => array('title' => ts('Activity Duration'), 'type' => CRM_Utils_Type::T_INT), - 'case_activity_medium_id' => array('title' => ts('Activity Medium'), 'type' => CRM_Utils_Type::T_INT), - 'case_activity_details' => array('title' => ts('Activity Details'), 'type' => CRM_Utils_Type::T_TEXT), - 'case_activity_is_auto' => array( + ], + 'case_recent_activity_type' => [ + 'title' => ts('Activity Type'), + 'type' => CRM_Utils_Type::T_STRING, + ], + 'case_activity_status' => [ + 'title' => ts('Activity Status'), + 'type' => CRM_Utils_Type::T_STRING, + ], + 'case_activity_duration' => [ + 'title' => ts('Activity Duration'), + 'type' => CRM_Utils_Type::T_INT, + ], + 'case_activity_medium_id' => [ + 'title' => ts('Activity Medium'), + 'type' => CRM_Utils_Type::T_INT, + ], + 'case_activity_details' => [ + 'title' => ts('Activity Details'), + 'type' => CRM_Utils_Type::T_TEXT, + ], + 'case_activity_is_auto' => [ 'title' => ts('Activity Auto-generated?'), 'type' => CRM_Utils_Type::T_BOOLEAN, - ), - ); + ], + ]; } // add custom data for case activities @@ -2122,7 +2149,7 @@ AND cl.modified_id = c.id */ public static function getProfileFields() { $exportableFields = self::exportableFields('Activity'); - $skipFields = array( + $skipFields = [ 'activity_id', 'activity_type', 'source_contact_id', @@ -2131,7 +2158,7 @@ AND cl.modified_id = c.id 'activity_is_test', 'is_current_revision', 'activity_is_deleted', - ); + ]; $config = CRM_Core_Config::singleton(); if (!in_array('CiviCampaign', $config->enableComponents)) { $skipFields[] = 'activity_engagement_level'; @@ -2187,7 +2214,7 @@ AND cl.modified_id = c.id // delete activity only if no other contacts connected if (!$activityContactOther->find(TRUE)) { - $activityParams = array('id' => $activityContact->activity_id); + $activityParams = ['id' => $activityContact->activity_id]; $result = self::deleteActivity($activityParams); } @@ -2211,7 +2238,7 @@ AND cl.modified_id = c.id public static function checkPermission($activityId, $action) { if (!$activityId || - !in_array($action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) + !in_array($action, [CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW]) ) { return FALSE; } @@ -2377,7 +2404,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = // @todo - should we move this to activity get api. foreach ([ 'case_id' => 'CiviCase', - 'campaign_id' => 'CiviCampaign' + 'campaign_id' => 'CiviCampaign', ] as $attr => $component) { if (!in_array($component, $enabledComponents)) { $activityParams[$attr] = ['IS NULL' => 1]; @@ -2419,11 +2446,11 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = $params['caseId'] = NULL; $context = CRM_Utils_Array::value('context', $params); $showContactOverlay = !CRM_Utils_String::startsWith($context, "dashlet"); - $activityTypeInfo = civicrm_api3('OptionValue', 'get', array( + $activityTypeInfo = civicrm_api3('OptionValue', 'get', [ 'option_group_id' => "activity_type", - 'options' => array('limit' => 0), - )); - $activityIcons = array(); + 'options' => ['limit' => 0], + ]); + $activityIcons = []; foreach ($activityTypeInfo['values'] as $type) { if (!empty($type['icon'])) { $activityIcons[$type['value']] = $type['icon']; @@ -2438,7 +2465,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = $params['total'] = CRM_Activity_BAO_Activity::getActivitiesCount($params); // Format params and add links. - $contactActivities = array(); + $contactActivities = []; if (!empty($activities)) { $activityStatus = CRM_Core_PseudoConstant::activityStatus(); @@ -2446,7 +2473,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = // Check logged in user for permission. $page = new CRM_Core_Page(); CRM_Contact_Page_View::checkUserPermission($page, $params['contact_id']); - $permissions = array($page->_permission); + $permissions = [$page->_permission]; if (CRM_Core_Permission::check('delete activities')) { $permissions[] = CRM_Core_Permission::DELETE; } @@ -2465,7 +2492,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = $activity['DT_RowClass'] .= ' status-ontime'; } - $activity['DT_RowAttr'] = array(); + $activity['DT_RowAttr'] = []; $activity['DT_RowAttr']['data-entity'] = 'activity'; $activity['DT_RowAttr']['data-id'] = $activityId; @@ -2484,7 +2511,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = $values['source_contact_id']); } $activity['source_contact_name'] = $srcTypeImage . CRM_Utils_System::href($values['source_contact_name'], - 'civicrm/contact/view', "reset=1&cid={$values['source_contact_id']}"); + 'civicrm/contact/view', "reset=1&cid={$values['source_contact_id']}"); } else { $activity['source_contact_name'] = 'n/a'; @@ -2516,7 +2543,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = } if ($extraCount = $values['target_contact_counter'] - 1) { - $activity['target_contact_name'] .= ";
" . "(" . ts('%1 more', array(1 => $extraCount)) . ")"; + $activity['target_contact_name'] .= ";
" . "(" . ts('%1 more', [1 => $extraCount]) . ")"; } if ($showContactOverlay) { $activity['target_contact_name'] .= " "; @@ -2585,12 +2612,12 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = $activity['links'] = CRM_Core_Action::formLink($actionLinks, $actionMask, - array( + [ 'id' => $values['activity_id'], 'cid' => $params['contact_id'], 'cxt' => $context, 'caseid' => CRM_Utils_Array::value('case_id', $values), - ), + ], ts('more'), FALSE, 'activity.tab.row', @@ -2606,7 +2633,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = } } - $activitiesDT = array(); + $activitiesDT = []; $activitiesDT['data'] = $contactActivities; $activitiesDT['recordsTotal'] = $params['total']; $activitiesDT['recordsFiltered'] = $params['total']; @@ -2623,7 +2650,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = */ public static function copyExtendedActivityData($params) { // attach custom data to the new activity - $customParams = $htmlType = array(); + $customParams = $htmlType = []; $customValues = CRM_Core_BAO_CustomValueTable::getEntityValues($params['activityID'], 'Activity'); if (!empty($customValues)) { @@ -2640,10 +2667,10 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = // CRM-10542 if (in_array($key, $htmlType)) { $fileValues = CRM_Core_BAO_File::path($value, $params['activityID']); - $customParams["custom_{$key}_-1"] = array( + $customParams["custom_{$key}_-1"] = [ 'name' => $fileValues[0], 'type' => $fileValues[1], - ); + ]; } else { $customParams["custom_{$key}_-1"] = $value; @@ -2726,7 +2753,7 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name = * * @return bool */ - public static function sendToAssignee($activity, $mailToContacts, $params = array()) { + public static function sendToAssignee($activity, $mailToContacts, $params = []) { if (!CRM_Utils_Array::crmIsEmptyArray($mailToContacts)) { $clientID = CRM_Utils_Array::value('client_id', $params); $caseID = CRM_Utils_Array::value('case_id', $params); diff --git a/CRM/Activity/BAO/ActivityAssignment.php b/CRM/Activity/BAO/ActivityAssignment.php index dab57c94e6..87420a3dc7 100644 --- a/CRM/Activity/BAO/ActivityAssignment.php +++ b/CRM/Activity/BAO/ActivityAssignment.php @@ -71,7 +71,7 @@ class CRM_Activity_BAO_ActivityAssignment extends CRM_Activity_DAO_ActivityConta * @return array */ public static function retrieveAssigneeIdsByActivityId($activity_id) { - $assigneeArray = array(); + $assigneeArray = []; if (!CRM_Utils_Rule::positiveInteger($activity_id)) { return $assigneeArray; } @@ -87,7 +87,12 @@ WHERE activity_id = %1 AND record_type_id = $assigneeID AND civicrm_contact.is_deleted = 0 "; - $assignment = CRM_Core_DAO::executeQuery($sql, array(1 => array($activity_id, 'Integer'))); + $assignment = CRM_Core_DAO::executeQuery($sql, [ + 1 => [ + $activity_id, + 'Integer', + ], + ]); while ($assignment->fetch()) { $assigneeArray[] = $assignment->contact_id; } @@ -108,7 +113,7 @@ AND civicrm_contact.is_deleted = 0 * @return array */ public static function getAssigneeNames($activityIDs, $isDisplayName = FALSE, $skipDetails = TRUE) { - $assigneeNames = array(); + $assigneeNames = []; if (empty($activityIDs)) { return $assigneeNames; } diff --git a/CRM/Activity/BAO/ActivityContact.php b/CRM/Activity/BAO/ActivityContact.php index 393f3bbb48..f12a86b205 100644 --- a/CRM/Activity/BAO/ActivityContact.php +++ b/CRM/Activity/BAO/ActivityContact.php @@ -72,11 +72,11 @@ class CRM_Activity_BAO_ActivityContact extends CRM_Activity_DAO_ActivityContact * @return array */ public static function getNames($activityID, $recordTypeID, $alsoIDs = FALSE) { - $names = array(); - $ids = array(); + $names = []; + $ids = []; if (empty($activityID)) { - return $alsoIDs ? array($names, $ids) : $names; + return $alsoIDs ? [$names, $ids] : $names; } $query = " @@ -87,10 +87,10 @@ WHERE civicrm_activity_contact.activity_id = %1 AND civicrm_activity_contact.record_type_id = %2 AND contact_a.is_deleted = 0 "; - $params = array( - 1 => array($activityID, 'Integer'), - 2 => array($recordTypeID, 'Integer'), - ); + $params = [ + 1 => [$activityID, 'Integer'], + 2 => [$recordTypeID, 'Integer'], + ]; $dao = CRM_Core_DAO::executeQuery($query, $params); while ($dao->fetch()) { @@ -98,7 +98,7 @@ AND contact_a.is_deleted = 0 $ids[] = $dao->id; } - return $alsoIDs ? array($names, $ids) : $names; + return $alsoIDs ? [$names, $ids] : $names; } /** @@ -110,7 +110,7 @@ AND contact_a.is_deleted = 0 * @return mixed */ public static function retrieveContactIdsByActivityId($activityID, $recordTypeID) { - $activityContact = array(); + $activityContact = []; if (!CRM_Utils_Rule::positiveInteger($activityID) || !CRM_Utils_Rule::positiveInteger($recordTypeID) ) { @@ -124,10 +124,10 @@ WHERE activity_id = %1 AND record_type_id = %2 AND civicrm_contact.is_deleted = 0 "; - $params = array( - 1 => array($activityID, 'Integer'), - 2 => array($recordTypeID, 'Integer'), - ); + $params = [ + 1 => [$activityID, 'Integer'], + 2 => [$recordTypeID, 'Integer'], + ]; $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { @@ -152,7 +152,7 @@ AND civicrm_contact.is_deleted = 0 * null - if no links.ini exists for this database (hence try auto_links). */ public function links() { - $link = array('activity_id' => 'civicrm_activity:id'); + $link = ['activity_id' => 'civicrm_activity:id']; return $link; } diff --git a/CRM/Activity/BAO/ActivityTarget.php b/CRM/Activity/BAO/ActivityTarget.php index 7aba449f78..167857d1c3 100644 --- a/CRM/Activity/BAO/ActivityTarget.php +++ b/CRM/Activity/BAO/ActivityTarget.php @@ -69,7 +69,7 @@ class CRM_Activity_BAO_ActivityTarget extends CRM_Activity_DAO_ActivityContact { * @return mixed */ public static function retrieveTargetIdsByActivityId($activity_id) { - $targetArray = array(); + $targetArray = []; if (!CRM_Utils_Rule::positiveInteger($activity_id)) { return $targetArray; } @@ -85,7 +85,12 @@ WHERE activity_id = %1 AND record_type_id = $targetID AND civicrm_contact.is_deleted = 0 "; - $target = CRM_Core_DAO::executeQuery($sql, array(1 => array($activity_id, 'Integer'))); + $target = CRM_Core_DAO::executeQuery($sql, [ + 1 => [ + $activity_id, + 'Integer', + ], + ]); while ($target->fetch()) { $targetArray[] = $target->contact_id; } @@ -100,7 +105,7 @@ AND civicrm_contact.is_deleted = 0 * @return array */ public static function getTargetNames($activityID) { - $targetNames = array(); + $targetNames = []; if (empty($activityID)) { return $targetNames; @@ -116,7 +121,7 @@ WHERE civicrm_activity_contact.activity_id = %1 AND civicrm_activity_contact.record_type_id = $targetID AND contact_a.is_deleted = 0 "; - $queryParam = array(1 => array($activityID, 'Integer')); + $queryParam = [1 => [$activityID, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($query, $queryParam); while ($dao->fetch()) { diff --git a/CRM/Activity/BAO/ICalendar.php b/CRM/Activity/BAO/ICalendar.php index 41b5698c32..4ebc2b0b54 100644 --- a/CRM/Activity/BAO/ICalendar.php +++ b/CRM/Activity/BAO/ICalendar.php @@ -86,14 +86,14 @@ class CRM_Activity_BAO_ICalendar { $calendar = $template->fetch('CRM/Activity/Calendar/ICal.tpl'); if (file_put_contents($this->icsfile, $calendar) !== FALSE) { if (empty($attachments)) { - $attachments = array(); + $attachments = []; } - $attachments['activity_ics'] = array( + $attachments['activity_ics'] = [ 'mime_type' => 'text/calendar', 'fileName' => $icsFileName, 'cleanName' => $icsFileName, 'fullPath' => $this->icsfile, - ); + ]; return 'activity_ics'; } } @@ -105,7 +105,7 @@ class CRM_Activity_BAO_ICalendar { * Remove temp file. */ public function cleanup() { - if (!empty ($this->icsfile)) { + if (!empty($this->icsfile)) { @unlink($this->icsfile); } } diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 3477ffef6a..8851d2fe35 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -211,22 +211,30 @@ class CRM_Activity_BAO_Query { case 'activity_subject': $qillName = $name; - if (in_array($name, array('activity_engagement_level', 'activity_id'))) { + if (in_array($name, ['activity_engagement_level', 'activity_id'])) { $name = $qillName = str_replace('activity_', '', $name); } - if (in_array($name, array('activity_status_id', 'activity_subject', 'activity_priority_id'))) { + if (in_array($name, [ + 'activity_status_id', + 'activity_subject', + 'activity_priority_id', + ])) { $name = str_replace('activity_', '', $name); $qillName = str_replace('_id', '', $qillName); } if ($name == 'activity_campaign_id') { - $name = 'campaign_id'; + $name = 'campaign_id'; } $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String'; $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.$name", $op, $value, $dataType); list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op); - $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value)); + $query->_qill[$grouping][] = ts('%1 %2 %3', [ + 1 => $fields[$qillName]['title'], + 2 => $op, + 3 => $value, + ]); break; case 'activity_text': @@ -238,7 +246,11 @@ class CRM_Activity_BAO_Query { case 'activity_priority': $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, 'String'); list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op); - $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value)); + $query->_qill[$grouping][] = ts('%1 %2 %3', [ + 1 => $fields[$name]['title'], + 2 => $op, + 3 => $value, + ]); $query->_tables[$name] = $query->_whereTables[$name] = 1; break; @@ -291,13 +303,16 @@ class CRM_Activity_BAO_Query { case 'activity_date_time_low': case 'activity_date_time_high': $query->dateQueryBuilder($values, - 'civicrm_activity', str_replace(['_high', '_low'], '', $name), 'activity_date_time', ts('Activity Date') + 'civicrm_activity', str_replace([ + '_high', + '_low', + ], '', $name), 'activity_date_time', ts('Activity Date') ); break; case 'activity_taglist': $taglist = $value; - $value = array(); + $value = []; foreach ($taglist as $val) { if ($val) { $val = explode(',', $val); @@ -311,16 +326,16 @@ class CRM_Activity_BAO_Query { case 'activity_tags': $value = array_keys($value); - $activityTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); + $activityTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]); - $names = array(); + $names = []; if (is_array($value)) { foreach ($value as $k => $v) { $names[] = $activityTags[$v]; } } $query->_where[$grouping][] = "civicrm_activity_tag.tag_id IN (" . implode(",", $value) . ")"; - $query->_qill[$grouping][] = ts('Activity Tag %1', array(1 => $op)) . ' ' . implode(' ' . ts('OR') . ' ', $names); + $query->_qill[$grouping][] = ts('Activity Tag %1', [1 => $op]) . ' ' . implode(' ' . ts('OR') . ' ', $names); $query->_tables['civicrm_activity_tag'] = $query->_whereTables['civicrm_activity_tag'] = 1; break; @@ -331,7 +346,7 @@ class CRM_Activity_BAO_Query { $safe[] = "'" . CRM_Utils_Type::escape($k, 'String') . "'"; } $query->_where[$grouping][] = "civicrm_activity.result IN (" . implode(',', $safe) . ")"; - $query->_qill[$grouping][] = ts("Activity Result - %1", array(1 => implode(' or ', $safe))); + $query->_qill[$grouping][] = ts("Activity Result - %1", [1 => implode(' or ', $safe)]); } break; @@ -362,7 +377,11 @@ class CRM_Activity_BAO_Query { $columnName = strstr($name, '_id') ? 'id' : 'sort_name'; $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("source_contact.{$columnName}", $op, $value, CRM_Utils_Type::typeToString($fields[$name]['type'])); list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contact_DAO_Contact', $columnName, $value, $op); - $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value)); + $query->_qill[$grouping][] = ts('%1 %2 %3', [ + 1 => $fields[$name]['title'], + 2 => $op, + 3 => $value, + ]); break; } } @@ -456,39 +475,53 @@ class CRM_Activity_BAO_Query { $form->addSearchFieldMetadata(['Activity' => self::getSearchFieldMetadata()]); $form->addFormFieldsFromMetadata(); - $followUpActivity = array( + $followUpActivity = [ 1 => ts('Yes'), 2 => ts('No'), - ); - $form->addRadio('parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); - $form->addRadio('followup_parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); - $activityRoles = array( + ]; + $form->addRadio('parent_id', NULL, $followUpActivity, ['allowClear' => TRUE]); + $form->addRadio('followup_parent_id', NULL, $followUpActivity, ['allowClear' => TRUE]); + $activityRoles = [ 3 => ts('With'), 2 => ts('Assigned to'), 1 => ts('Added by'), - ); - $form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE)); - $form->setDefaults(array('activity_role' => 3)); - $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name')); + ]; + $form->addRadio('activity_role', NULL, $activityRoles, ['allowClear' => TRUE]); + $form->setDefaults(['activity_role' => 3]); + $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', [ + 'flip' => 1, + 'labelColumn' => 'name', + ]); $form->addSelect('status_id', - array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) + [ + 'entity' => 'activity', + 'multiple' => 'multiple', + 'option_url' => NULL, + 'placeholder' => ts('- any -'), + ] ); $ssID = $form->get('ssID'); - $status = array($activityStatus['Completed'], $activityStatus['Scheduled']); + $status = [$activityStatus['Completed'], $activityStatus['Scheduled']]; //If status is saved in smart group. if (!empty($ssID) && !empty($form->_formValues['activity_status_id'])) { $status = $form->_formValues['activity_status_id']; } - $form->setDefaults(array('status_id' => $status)); + $form->setDefaults(['status_id' => $status]); $form->addElement('text', 'activity_text', ts('Activity Text'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addRadio('activity_option', '', CRM_Core_SelectValues::activityTextOptions()); - $form->setDefaults(array('activity_option' => 'both')); + $form->setDefaults(['activity_option' => 'both']); $priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); $form->addSelect('priority_id', - array('entity' => 'activity', 'label' => ts('Priority'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -')) + [ + 'entity' => 'activity', + 'label' => ts('Priority'), + 'multiple' => 'multiple', + 'option_url' => NULL, + 'placeholder' => ts('- any -'), + ] ); $form->addYesNo('activity_test', ts('Activity is a Test?')); @@ -507,12 +540,12 @@ class CRM_Activity_BAO_Query { $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); if ($surveys) { $form->add('select', 'activity_survey_id', ts('Survey / Petition'), - array('' => ts('- none -')) + $surveys, FALSE, - array('class' => 'crm-select2') - ); + ['' => ts('- none -')] + $surveys, FALSE, + ['class' => 'crm-select2'] + ); } - CRM_Core_BAO_Query::addCustomFormFields($form, array('Activity')); + CRM_Core_BAO_Query::addCustomFormFields($form, ['Activity']); CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); @@ -523,11 +556,14 @@ class CRM_Activity_BAO_Query { CRM_Campaign_BAO_Campaign::accessCampaign() ) { $buildEngagementLevel = TRUE; - $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search')); + $form->addSelect('activity_engagement_level', [ + 'entity' => 'activity', + 'context' => 'search', + ]); // Add survey result field. $optionGroups = CRM_Campaign_BAO_Survey::getResultSets('name'); - $resultOptions = array(); + $resultOptions = []; foreach ($optionGroups as $gid => $name) { if ($name) { $value = CRM_Core_OptionGroup::values($name); @@ -545,14 +581,18 @@ class CRM_Activity_BAO_Query { asort($resultOptions); $form->add('select', 'activity_result', ts("Survey Result"), $resultOptions, FALSE, - array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2') + [ + 'id' => 'activity_result', + 'multiple' => 'multiple', + 'class' => 'crm-select2', + ] ); } } $form->assign('buildEngagementLevel', $buildEngagementLevel); $form->assign('buildSurveyResult', $buildSurveyResult); - $form->setDefaults(array('activity_test' => 0)); + $form->setDefaults(['activity_test' => 0]); } /** @@ -564,7 +604,7 @@ class CRM_Activity_BAO_Query { public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) { - $properties = array( + $properties = [ 'activity_id' => 1, 'contact_type' => 1, 'contact_sub_type' => 1, @@ -586,7 +626,7 @@ class CRM_Activity_BAO_Query { 'result' => 1, 'activity_engagement_level' => 1, 'parent_id' => 1, - ); + ]; if ($includeCustomFields) { // also get all the custom activity properties @@ -609,7 +649,7 @@ class CRM_Activity_BAO_Query { * kills a small kitten so add carefully. */ public static function selectorReturnProperties() { - $properties = array( + $properties = [ 'activity_id' => 1, 'contact_type' => 1, 'contact_sub_type' => 1, @@ -624,7 +664,7 @@ class CRM_Activity_BAO_Query { 'activity_is_test' => 1, 'activity_campaign_id' => 1, 'activity_engagement_level' => 1, - ); + ]; return $properties; } @@ -641,8 +681,8 @@ class CRM_Activity_BAO_Query { $query->_useDistinct = TRUE; - $label = ts('Activity Text (%1)', array(1 => CRM_Utils_Array::value($activityOption, CRM_Core_SelectValues::activityTextOptions()))); - $clauses = array(); + $label = ts('Activity Text (%1)', [1 => CRM_Utils_Array::value($activityOption, CRM_Core_SelectValues::activityTextOptions())]); + $clauses = []; if ($activityOption % 2 == 0) { $clauses[] = $query->buildClause('civicrm_activity.details', $op, $value, 'String'); } @@ -652,7 +692,11 @@ class CRM_Activity_BAO_Query { $query->_where[$grouping][] = "( " . implode(' OR ', $clauses) . " )"; list($qillOp, $qillVal) = $query->buildQillForFieldValue(NULL, $name, $value, $op); - $query->_qill[$grouping][] = ts("%1 %2 '%3'", array(1 => $label, 2 => $qillOp, 3 => $qillVal)); + $query->_qill[$grouping][] = ts("%1 %2 '%3'", [ + 1 => $label, + 2 => $qillOp, + 3 => $qillVal, + ]); } } diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 94f68c1203..b3e65e0c87 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -48,7 +48,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { * * @var int */ - public $_activityIds = array(); + public $_activityIds = []; /** * The id of activity type. @@ -115,7 +115,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { */ protected $_isSurveyActivity; - protected $_values = array(); + protected $_values = []; protected $unsavedWarn = TRUE; @@ -154,88 +154,84 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $unwanted = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, "AND v.name = 'Print PDF Letter'"); $activityTypes = array_diff_key(CRM_Core_PseudoConstant::ActivityType(FALSE), $unwanted); - $this->_fields = array( - 'subject' => array( + $this->_fields = [ + 'subject' => [ 'type' => 'text', 'label' => ts('Subject'), - 'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', - 'activity_subject' - ), - ), - 'duration' => array( + 'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'activity_subject'), + ], + 'duration' => [ 'type' => 'number', 'label' => ts('Duration'), - 'attributes' => array('class' => 'four', 'min' => 1), + 'attributes' => ['class' => 'four', 'min' => 1], 'required' => FALSE, - ), - 'location' => array( + ], + 'location' => [ 'type' => 'text', 'label' => ts('Location'), 'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'location'), 'required' => FALSE, - ), - 'details' => array( + ], + 'details' => [ 'type' => 'wysiwyg', 'label' => ts('Details'), - 'attributes' => array('class' => 'huge'), + 'attributes' => ['class' => 'huge'], 'required' => FALSE, - ), - 'status_id' => array( + ], + 'status_id' => [ 'type' => 'select', 'required' => TRUE, - ), - 'priority_id' => array( + ], + 'priority_id' => [ 'type' => 'select', 'required' => TRUE, - ), - 'source_contact_id' => array( + ], + 'source_contact_id' => [ 'type' => 'entityRef', 'label' => ts('Added By'), 'required' => FALSE, - ), - 'target_contact_id' => array( + ], + 'target_contact_id' => [ 'type' => 'entityRef', 'label' => ts('With Contact'), - 'attributes' => array('multiple' => TRUE, 'create' => TRUE), - ), - 'assignee_contact_id' => array( + 'attributes' => ['multiple' => TRUE, 'create' => TRUE], + ], + 'assignee_contact_id' => [ 'type' => 'entityRef', 'label' => ts('Assigned to'), - 'attributes' => array( + 'attributes' => [ 'multiple' => TRUE, 'create' => TRUE, - 'api' => array('params' => array('is_deceased' => 0)), - ), - ), - 'activity_date_time' => array( + 'api' => ['params' => ['is_deceased' => 0]], + ], + ], + 'activity_date_time' => [ 'type' => 'datepicker', 'label' => ts('Date'), 'required' => TRUE, - ), - 'followup_assignee_contact_id' => array( + ], + 'followup_assignee_contact_id' => [ 'type' => 'entityRef', 'label' => ts('Assigned to'), - 'attributes' => array( + 'attributes' => [ 'multiple' => TRUE, 'create' => TRUE, - 'api' => array('params' => array('is_deceased' => 0)), - ), - ), - 'followup_activity_type_id' => array( + 'api' => ['params' => ['is_deceased' => 0]], + ], + ], + 'followup_activity_type_id' => [ 'type' => 'select', 'label' => ts('Followup Activity'), - 'attributes' => array('' => '- ' . ts('select activity') . ' -') + $activityTypes, - 'extra' => array('class' => 'crm-select2'), - ), + 'attributes' => ['' => '- ' . ts('select activity') . ' -'] + $activityTypes, + 'extra' => ['class' => 'crm-select2'], + ], // Add optional 'Subject' field for the Follow-up Activiity, CRM-4491 - 'followup_activity_subject' => array( + 'followup_activity_subject' => [ 'type' => 'text', 'label' => ts('Subject'), - 'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', - 'subject' - ), - ), - ); + 'attributes' => CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'subject'), + ], + ]; } /** @@ -264,7 +260,11 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if (CRM_Contact_Form_Search::isSearchContext($this->_context)) { $this->_context = 'search'; } - elseif (!in_array($this->_context, array('dashlet', 'case', 'dashletFullscreen')) + elseif (!in_array($this->_context, [ + 'dashlet', + 'case', + 'dashletFullscreen', + ]) && $this->_currentlyViewedContactId ) { $this->_context = 'activity'; @@ -301,10 +301,10 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // Check for required permissions, CRM-6264. if ($this->_activityId && - in_array($this->_action, array( + in_array($this->_action, [ CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW, - )) && + ]) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action) ) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); @@ -345,7 +345,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { CRM_Utils_System::setTitle($displayName . ' - ' . $activityName); } else { - CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName))); + CRM_Utils_System::setTitle(ts('%1 Activity', [1 => $activityName])); } } @@ -437,12 +437,12 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } $this->assign('searchKey', $qfKey); } - elseif (in_array($this->_context, array( + elseif (in_array($this->_context, [ 'standalone', 'home', 'dashlet', 'dashletFullscreen', - )) + ]) ) { $urlParams = 'reset=1'; $urlString = 'civicrm/dashboard'; @@ -516,9 +516,9 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->_values = $this->get('values'); if (!is_array($this->_values)) { - $this->_values = array(); + $this->_values = []; if (isset($this->_activityId) && $this->_activityId) { - $params = array('id' => $this->_activityId); + $params = ['id' => $this->_activityId]; CRM_Activity_BAO_Activity::retrieve($params, $this->_values); } @@ -606,7 +606,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if ($this->_action == 2 && !empty($defaults['target_contact_id'])) { $count = count(is_array($defaults['target_contact_id']) ? $defaults['target_contact_id'] : explode(',', $defaults['target_contact_id'])); if ($count > 50) { - $this->freeze(array('target_contact_id')); + $this->freeze(['target_contact_id']); } } @@ -637,18 +637,18 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if ($this->_action & CRM_Core_Action::RENEW) { $button = ts('Restore'); } - $this->addButtons(array( - array( + $this->addButtons([ + [ 'type' => 'next', 'name' => $button, 'spacing' => '         ', 'isDefault' => TRUE, - ), - array( + ], + [ 'type' => 'cancel', 'name' => ts('Cancel'), - ), - )); + ], + ]); return; } @@ -659,11 +659,11 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->assign('suppressForm', FALSE); $element = &$this->add('select', 'activity_type_id', ts('Activity Type'), - array('' => '- ' . ts('select') . ' -') + $this->_fields['followup_activity_type_id']['attributes'], - FALSE, array( + ['' => '- ' . ts('select') . ' -'] + $this->_fields['followup_activity_type_id']['attributes'], + FALSE, [ 'onchange' => "CRM.buildCustomData( 'Activity', this.value );", 'class' => 'crm-select2 required', - ) + ] ); // Freeze for update mode. @@ -682,7 +682,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $required = !empty($values['required']); if ($values['type'] == 'select' && empty($attribute)) { - $this->addSelect($field, array('entity' => 'activity'), $required); + $this->addSelect($field, ['entity' => 'activity'], $required); } elseif ($values['type'] == 'entityRef') { $this->addEntityRef($field, $values['label'], $attribute, $required); @@ -702,7 +702,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { CRM_Campaign_BAO_Campaign::accessCampaign() ) { $buildEngagementLevel = TRUE; - $this->addSelect('engagement_level', array('entity' => 'activity')); + $this->addSelect('engagement_level', ['entity' => 'activity']); $this->addRule('engagement_level', ts('Please enter the engagement index as a number (integers only).'), 'positiveInteger' @@ -726,7 +726,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $responseOptions = CRM_Campaign_BAO_Survey::getResponsesOptions($surveyId); if ($responseOptions) { $this->add('select', 'result', ts('Result'), - array('' => ts('- select -')) + array_combine($responseOptions, $responseOptions) + ['' => ts('- select -')] + array_combine($responseOptions, $responseOptions) ); } $surveyTitle = NULL; @@ -745,10 +745,10 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $this->addRadio( 'separation', ts('Activity Separation'), - array( + [ 'separate' => ts('Create separate activities for each contact'), 'combined' => ts('Create one activity with all contacts together'), - ) + ] ); } @@ -772,11 +772,15 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $tags = CRM_Core_BAO_Tag::getColorTags('civicrm_activity'); if (!empty($tags)) { - $this->add('select2', 'tag', ts('Tags'), $tags, FALSE, array('class' => 'huge', 'placeholder' => ts('- select -'), 'multiple' => TRUE)); + $this->add('select2', 'tag', ts('Tags'), $tags, FALSE, [ + 'class' => 'huge', + 'placeholder' => ts('- select -'), + 'multiple' => TRUE, + ]); } // we need to hide activity tagset for special activities - $specialActivities = array('Open Case'); + $specialActivities = ['Open Case']; if (!in_array($this->_activityTypeName, $specialActivities)) { // build tag widget @@ -818,13 +822,15 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}"; $className::buildQuickForm($this); - $this->addFormRule(array($className, 'formRule'), $this); + $this->addFormRule([$className, 'formRule'], $this); } - $this->addFormRule(array('CRM_Activity_Form_Activity', 'formRule'), $this); + $this->addFormRule(['CRM_Activity_Form_Activity', 'formRule'], $this); - $doNotNotifyAssigneeFor = (array) Civi::settings()->get('do_not_notify_assignees_for'); - if (($this->_activityTypeId && in_array($this->_activityTypeId, $doNotNotifyAssigneeFor)) || !Civi::settings()->get('activity_assignee_notification')) { + $doNotNotifyAssigneeFor = (array) Civi::settings() + ->get('do_not_notify_assignees_for'); + if (($this->_activityTypeId && in_array($this->_activityTypeId, $doNotNotifyAssigneeFor)) || !Civi::settings() + ->get('activity_assignee_notification')) { $this->assign('activityAssigneeNotification', FALSE); } else { @@ -850,7 +856,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { if (CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Delete') { return TRUE; } - $errors = array(); + $errors = []; if ((array_key_exists('activity_type_id', $fields) || !$self->_single) && empty($fields['activity_type_id'])) { $errors['activity_type_id'] = ts('Activity Type is a required field'); } @@ -895,15 +901,15 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { - $deleteParams = array('id' => $this->_activityId); + $deleteParams = ['id' => $this->_activityId]; $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity - $tagParams = array( + $tagParams = [ 'entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId, - ); + ]; CRM_Core_BAO_EntityTag::del($tagParams); @@ -939,12 +945,12 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } // format params as arrays - foreach (array('target', 'assignee', 'followup_assignee') as $name) { + foreach (['target', 'assignee', 'followup_assignee'] as $name) { if (!empty($params["{$name}_contact_id"])) { $params["{$name}_contact_id"] = explode(',', $params["{$name}_contact_id"]); } else { - $params["{$name}_contact_id"] = array(); + $params["{$name}_contact_id"] = []; } } @@ -966,13 +972,13 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $params['is_multi_activity'] = CRM_Utils_Array::value('separation', $params) == 'separate'; - $activity = array(); + $activity = []; if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id']) ) { $targetContacts = $params['target_contact_id']; foreach ($targetContacts as $targetContactId) { - $params['target_contact_id'] = array($targetContactId); + $params['target_contact_id'] = [$targetContactId]; // save activity $activity[] = $this->processActivity($params); } @@ -982,7 +988,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $activity = $this->processActivity($params); } - $activityIds = empty($this->_activityIds) ? array($this->_activityId) : $this->_activityIds; + $activityIds = empty($this->_activityIds) ? [$this->_activityId] : $this->_activityIds; foreach ($activityIds as $activityId) { // set params for repeat configuration in create mode $params['entity_id'] = $activityId; @@ -1001,7 +1007,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $params['schedule_reminder_id'] = $scheduleReminderDetails->id; } } - $params['dateColumns'] = array('activity_date_time'); + $params['dateColumns'] = ['activity_date_time']; // Set default repetition start if it was not provided. if (empty($params['repetition_start_date'])) { @@ -1010,20 +1016,20 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // unset activity id unset($params['id']); - $linkedEntities = array( - array( + $linkedEntities = [ + [ 'table' => 'civicrm_activity_contact', - 'findCriteria' => array( + 'findCriteria' => [ 'activity_id' => $activityId, - ), - 'linkedColumns' => array('activity_id'), + ], + 'linkedColumns' => ['activity_id'], 'isRecurringEntityRecord' => FALSE, - ), - ); + ], + ]; CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities); } - return array('activity' => $activity); + return ['activity' => $activity]; } /** @@ -1035,7 +1041,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { * @return self|null|object */ protected function processActivity(&$params) { - $activityAssigned = array(); + $activityAssigned = []; $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); // format assignee params @@ -1056,7 +1062,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists - $tagParams = array(); + $tagParams = []; if (!empty($params['tag'])) { if (!is_array($params['tag'])) { $params['tag'] = explode(',', $params['tag']); @@ -1097,15 +1103,16 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { $mailStatus = ''; if (Civi::settings()->get('activity_assignee_notification') - && !in_array($activity->activity_type_id, Civi::settings()->get('do_not_notify_assignees_for'))) { - $activityIDs = array($activity->id); + && !in_array($activity->activity_type_id, Civi::settings() + ->get('do_not_notify_assignees_for'))) { + $activityIDs = [$activity->id]; if ($followupActivity) { - $activityIDs = array_merge($activityIDs, array($followupActivity->id)); + $activityIDs = array_merge($activityIDs, [$followupActivity->id]); } $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { - $mailToContacts = array(); + $mailToContacts = []; // Build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { @@ -1122,7 +1129,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // Also send email to follow-up activity assignees if set if ($followupActivity) { - $mailToFollowupContacts = array(); + $mailToFollowupContacts = []; foreach ($assigneeContacts as $values) { if ($values['activity_id'] == $followupActivity->id) { $mailToFollowupContacts[$values['email']] = $values; @@ -1143,11 +1150,11 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2 %3', - array( + [ 1 => $subject, 2 => $followupStatus, 3 => $mailStatus, - ) + ] ), ts('Saved'), 'success'); return $activity; diff --git a/CRM/Activity/Import/Form/MapField.php b/CRM/Activity/Import/Form/MapField.php index aa97c4dc15..9cbb7d7e27 100644 --- a/CRM/Activity/Import/Form/MapField.php +++ b/CRM/Activity/Import/Form/MapField.php @@ -62,14 +62,14 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { else { $this->assign('rowDisplayCount', 2); } - $highlightedFields = array(); - $requiredFields = array( + $highlightedFields = []; + $requiredFields = [ 'activity_date_time', 'activity_type_id', 'activity_label', 'target_contact_id', 'activity_subject', - ); + ]; foreach ($requiredFields as $val) { $highlightedFields[] = $val; } @@ -103,8 +103,8 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $this->assign('loadedMapping', $savedMapping); $this->set('loadedMapping', $savedMapping); - $params = array('id' => $savedMapping); - $temp = array(); + $params = ['id' => $savedMapping]; + $temp = []; $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp); $this->assign('savedName', $mappingDetails->name); @@ -117,13 +117,13 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $this->add('text', 'saveMappingDesc', ts('Description')); } - $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)")); + $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, ['onclick' => "showSaveDetails(this)"]); - $this->addFormRule(array('CRM_Activity_Import_Form_MapField', 'formRule')); + $this->addFormRule(['CRM_Activity_Import_Form_MapField', 'formRule']); //-------- end of saved mapping stuff --------- - $defaults = array(); + $defaults = []; $mapperKeys = array_keys($this->_mapperFields); $hasHeaders = !empty($this->_columnHeaders); @@ -148,7 +148,7 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $warning = 0; for ($i = 0; $i < $this->_columnCount; $i++) { - $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', array(1 => $i)), NULL); + $sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', [1 => $i]), NULL); $jsSet = FALSE; if ($this->get('savedMapping')) { if (isset($mappingName[$i])) { @@ -165,15 +165,15 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { } $js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n"; - $defaults["mapper[$i]"] = array( + $defaults["mapper[$i]"] = [ $mappingHeader[0], (isset($locationId)) ? $locationId : "", (isset($phoneType)) ? $phoneType : "", - ); + ]; $jsSet = TRUE; } else { - $defaults["mapper[$i]"] = array(); + $defaults["mapper[$i]"] = []; } if (!$jsSet) { for ($k = 1; $k < 4; $k++) { @@ -186,14 +186,10 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_" . $i . "_');\n"; if ($hasHeaders) { - $defaults["mapper[$i]"] = array( - $this->defaultFromHeader($this->_columnHeaders[$i], - $headerPatterns - ), - ); + $defaults["mapper[$i]"] = [$this->defaultFromHeader($this->_columnHeaders[$i], $headerPatterns)]; } else { - $defaults["mapper[$i]"] = array($this->defaultFromData($dataPatterns, $i)); + $defaults["mapper[$i]"] = [$this->defaultFromData($dataPatterns, $i)]; } } // End of load mapping. @@ -202,23 +198,23 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_" . $i . "_');\n"; if ($hasHeaders) { // Infer the default from the skipped headers if we have them - $defaults["mapper[$i]"] = array( - $this->defaultFromHeader($this->_columnHeaders[$i], - $headerPatterns - ), + $defaults["mapper[$i]"] = [ + $this->defaultFromHeader($this->_columnHeaders[$i], $headerPatterns), 0, - ); + ]; } else { // Otherwise guess the default from the form of the data - $defaults["mapper[$i]"] = array( - $this->defaultFromData($dataPatterns, $i), - 0, - ); + $defaults["mapper[$i]"] = [$this->defaultFromData($dataPatterns, $i), 0]; } } - $sel->setOptions(array($sel1, $sel2, (isset($sel3)) ? $sel3 : "", (isset($sel4)) ? $sel4 : "")); + $sel->setOptions([ + $sel1, + $sel2, + (isset($sel3)) ? $sel3 : "", + (isset($sel4)) ? $sel4 : "", + ]); } $js .= "\n"; $this->assign('initHideBoxes', $js); @@ -240,22 +236,22 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $this->setDefaults($defaults); - $this->addButtons(array( - array( + $this->addButtons([ + [ 'type' => 'back', 'name' => ts('Previous'), - ), - array( + ], + [ 'type' => 'next', 'name' => ts('Continue'), 'spacing' => '          ', 'isDefault' => TRUE, - ), - array( + ], + [ 'type' => 'cancel', 'name' => ts('Cancel'), - ), - ) + ], + ] ); } @@ -269,28 +265,28 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { * list of errors to be posted back to the form */ public static function formRule($fields) { - $errors = array(); + $errors = []; // define so we avoid notices below $errors['_qf_default'] = ''; $fieldMessage = NULL; if (!array_key_exists('savedMapping', $fields)) { - $importKeys = array(); + $importKeys = []; foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } // FIXME: should use the schema titles, not redeclare them - $requiredFields = array( + $requiredFields = [ 'target_contact_id' => ts('Contact ID'), 'activity_date_time' => ts('Activity Date'), 'activity_subject' => ts('Activity Subject'), 'activity_type_id' => ts('Activity Type ID'), - ); + ]; - $params = array( + $params = [ 'used' => 'Unsupervised', 'contact_type' => 'Individual', - ); + ]; list($ruleFields, $threshold) = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($params); $weightSum = 0; foreach ($importKeys as $key => $val) { @@ -310,7 +306,7 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { else { $errors['_qf_default'] .= ts('Missing required contact matching fields.') . $fieldMessage . ' ' - . ts('(Sum of all weights should be greater than or equal to threshold: %1).', array(1 => $threshold)) + . ts('(Sum of all weights should be greater than or equal to threshold: %1).', [1 => $threshold]) . '
'; } } @@ -320,14 +316,14 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { } else { $errors['_qf_default'] .= ts('Missing required field: Provide %1 or %2', - array( + [ 1 => $title, 2 => 'Activity Type Label', - )) . '
'; + ]) . '
'; } } else { - $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => $title)) . '
'; + $errors['_qf_default'] .= ts('Missing required field: %1', [1 => $title]) . '
'; } } } @@ -378,12 +374,12 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $seperator = $this->controller->exportValue('DataSource', 'fieldSeparator'); $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader'); - $mapperKeys = array(); - $mapper = array(); + $mapperKeys = []; + $mapper = []; $mapperKeys = $this->controller->exportValue($this->_name, 'mapper'); - $mapperKeysMain = array(); - $mapperLocType = array(); - $mapperPhoneType = array(); + $mapperKeysMain = []; + $mapperLocType = []; + $mapperPhoneType = []; for ($i = 0; $i < $this->_columnCount; $i++) { $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]]; @@ -417,7 +413,7 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { $mappingFields->mapping_id = $params['mappingId']; $mappingFields->find(); - $mappingFieldsId = array(); + $mappingFieldsId = []; while ($mappingFields->fetch()) { if ($mappingFields->id) { $mappingFieldsId[$mappingFields->column_number] = $mappingFields->id; @@ -437,11 +433,11 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField { // Saving Mapping Details and Records. if (!empty($params['saveMapping'])) { - $mappingParams = array( + $mappingParams = [ 'name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', 'Import Activity'), - ); + ]; $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams); for ($i = 0; $i < $this->_columnCount; $i++) { -- 2.25.1