From: eileen Date: Sun, 8 Sep 2019 22:15:30 +0000 (+1200) Subject: [NFC] array formatting: X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f6b81482079259b79c59c743e5de495d9e0ef4c0;p=civicrm-core.git [NFC] array formatting: --- diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index fce78b7aff..2e5927e9cb 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -34,12 +34,14 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { /** * SQL function used to format the phone_numeric field via trigger. + * * @see self::triggerInfo() * * Note that this is also used by the 4.3 upgrade script. * @see CRM_Upgrade_Incremental_php_FourThree */ const DROP_STRIP_FUNCTION_43 = "DROP FUNCTION IF EXISTS civicrm_strip_non_numeric"; + const CREATE_STRIP_FUNCTION_43 = " CREATE FUNCTION civicrm_strip_non_numeric(input VARCHAR(255) CHARACTER SET utf8) RETURNS VARCHAR(255) CHARACTER SET utf8 @@ -62,31 +64,31 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { * * @var array */ - public static $_commPrefs = array( + public static $_commPrefs = [ 'do_not_phone', 'do_not_email', 'do_not_mail', 'do_not_sms', 'do_not_trade', - ); + ]; /** * Types of greetings. * * @var array */ - public static $_greetingTypes = array( + public static $_greetingTypes = [ 'addressee', 'email_greeting', 'postal_greeting', - ); + ]; /** * Static field for all the contact information that we can potentially import. * * @var array */ - public static $_importableFields = array(); + public static $_importableFields = []; /** * Static field for all the contact information that we can potentially export. @@ -115,6 +117,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { * @return CRM_Contact_BAO_Contact|CRM_Core_Error|NULL * Created or updated contact object or error object. * (error objects are being phased out in favour of exceptions) + * @throws \Exception */ public static function add(&$params) { $contact = new CRM_Contact_DAO_Contact(); @@ -162,7 +165,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { $contact->id = CRM_Utils_Array::value('contact_id', $params); - if ($contact->contact_type == 'Individual') { + if ($contact->contact_type === 'Individual') { $allNull = FALSE; // @todo allow the lines below to be overridden by input or hooks & add tests, // as has been done for households and organizations. @@ -210,7 +213,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { ); } - if ($contact->contact_type == 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) { + if ($contact->contact_type === 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) { // Create current employer. $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params); @@ -229,7 +232,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { } // Update cached employer name. - if ($contact->contact_type == 'Organization') { + if ($contact->contact_type === 'Organization') { CRM_Contact_BAO_Contact_Utils::updateCurrentEmployer($contact->id); } @@ -254,12 +257,12 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { * @param bool $skipDelete * Unclear parameter, passed to website create * - * @todo explain this parameter - * - * @throws Exception * @return CRM_Contact_BAO_Contact|CRM_Core_Error * Created or updated contribution object. We are deprecating returning an error in * favour of exceptions + * @throws Exception + * @todo explain this parameter + * */ public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE, $skipDelete = FALSE) { $contact = NULL; @@ -325,13 +328,13 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { $params['group'][$domainGroupID] = 1; } else { - $params['group'] = array($domainGroupID => 1); + $params['group'] = [$domainGroupID => 1]; } } } if (array_key_exists('group', $params)) { - $contactIds = array($params['contact_id']); + $contactIds = [$params['contact_id']]; foreach ($params['group'] as $groupId => $flag) { if ($flag == 1) { CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId); @@ -369,13 +372,13 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { $contactId = $userID; } - $noteParams = array( + $noteParams = [ 'entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $note['note'], 'subject' => CRM_Utils_Array::value('subject', $note), 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Note::add($noteParams); } } @@ -386,13 +389,13 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { $contactId = $userID; } - $noteParams = array( + $noteParams = [ 'entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', 'note' => $params['note'], 'subject' => CRM_Utils_Array::value('subject', $params), 'contact_id' => $contactId, - ); + ]; CRM_Core_BAO_Note::add($noteParams); } } @@ -408,11 +411,11 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { // make a civicrm_subscription_history entry only on contact create (CRM-777) if (empty($params['contact_id'])) { - $subscriptionParams = array( + $subscriptionParams = [ 'contact_id' => $contact->id, 'status' => 'Added', 'method' => 'Admin', - ); + ]; CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams); } @@ -454,6 +457,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { /** * Format the output of the create contact function + * * @param CRM_Contact_DAO_Contact[]|array[] $contacts */ public static function unsetProtectedFields(&$contacts) { @@ -481,10 +485,12 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { * (ie. knowing we have definitely tried disambiguates between NULL & not loaded.) * * @param array $params + * + * @throws \CiviCRM_API3_Exception */ public static function ensureGreetingParamsAreSet(&$params) { - $allGreetingParams = array('addressee' => 'addressee_id', 'postal_greeting' => 'postal_greeting_id', 'email_greeting' => 'email_greeting_id'); - $missingGreetingParams = array(); + $allGreetingParams = ['addressee' => 'addressee_id', 'postal_greeting' => 'postal_greeting_id', 'email_greeting' => 'email_greeting_id']; + $missingGreetingParams = []; foreach ($allGreetingParams as $greetingIndex => $greetingParam) { if (empty($params[$greetingParam])) { @@ -493,11 +499,10 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { } if (!empty($params['contact_id']) && !empty($missingGreetingParams)) { - $savedGreetings = civicrm_api3('Contact', 'getsingle', array( + $savedGreetings = civicrm_api3('Contact', 'getsingle', [ 'id' => $params['contact_id'], 'return' => array_keys($missingGreetingParams), - ) - ); + ]); foreach (array_keys($missingGreetingParams) as $missingGreetingParam) { if (!empty($savedGreetings[$missingGreetingParam . '_custom'])) { @@ -547,10 +552,10 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $dao->query($sql); if ($dao->fetch()) { $image = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? - $dao->contact_sub_type : $dao->contact_type, FALSE, $id + $dao->contact_sub_type : $dao->contact_type, FALSE, $id ); $imageUrl = CRM_Contact_BAO_Contact_Utils::getImage($dao->contact_sub_type ? - $dao->contact_sub_type : $dao->contact_type, TRUE, $id + $dao->contact_sub_type : $dao->contact_type, TRUE, $id ); // use email if display_name is empty @@ -563,13 +568,13 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); CRM_Utils_Hook::alterDisplayName($displayName, $id, $dao); - return $includeTypeInReturnParameters ? array( + return $includeTypeInReturnParameters ? [ $displayName, $image, $dao->contact_type, $dao->contact_sub_type, $imageUrl, - ) : array($displayName, $image, $imageUrl); + ] : [$displayName, $image, $imageUrl]; } return NULL; } @@ -589,7 +594,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * @fixme How does this relate to almost the same thing being done in CRM_Core_Form::formatParamsForPaymentProcessor() */ public static function addBillingNameFieldsIfOtherwiseNotSet(&$params) { - $nameFields = array('first_name', 'middle_name', 'last_name', 'nick_name', 'prefix_id', 'suffix_id'); + $nameFields = ['first_name', 'middle_name', 'last_name', 'nick_name', 'prefix_id', 'suffix_id']; foreach ($nameFields as $field) { if (!empty($params[$field])) { return; @@ -644,7 +649,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); // The underlying lookupValue function needs some de-fanging. Until that has been unravelled we // continue to resolve stateprovince lists in descending order of preference & just 'keep trying'. // prefer matching country.. - $stateProvinceList = CRM_Core_BAO_Address::buildOptions('state_province_id', NULL, array('country_id' => Civi::settings()->get('defaultContactCountry'))); + $stateProvinceList = CRM_Core_BAO_Address::buildOptions('state_province_id', NULL, ['country_id' => Civi::settings()->get('defaultContactCountry')]); if (CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, @@ -720,26 +725,26 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); public function createDefaultCrudLink($crudLinkSpec) { switch ($crudLinkSpec['action']) { case CRM_Core_Action::VIEW: - $result = array( + $result = [ 'title' => $this->display_name, 'path' => 'civicrm/contact/view', - 'query' => array( + 'query' => [ 'reset' => 1, 'cid' => $this->id, - ), - ); + ], + ]; return $result; case CRM_Core_Action::UPDATE: - $result = array( + $result = [ 'title' => $this->display_name, 'path' => 'civicrm/contact/add', - 'query' => array( + 'query' => [ 'reset' => 1, 'action' => 'update', 'cid' => $this->id, - ), - ); + ], + ]; return $result; } return NULL; @@ -748,15 +753,16 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); /** * Get the values for pseudoconstants for name->value and reverse. * + * @param array $defaults + * (reference) the default values, some of which need to be resolved. + * @param bool $reverse + * Always true as this function is only called from one place.. + * * @deprecated * * This is called specifically from the contact import parser & should be moved there * as it is not truly a generic function. * - * @param array $defaults - * (reference) the default values, some of which need to be resolved. - * @param bool $reverse - * Always true as this function is only called from one place.. */ public static function resolveDefaults(&$defaults, $reverse = FALSE) { // Hack for birth_date. @@ -773,16 +779,16 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); //lookup value of email/postal greeting, addressee, CRM-4575 foreach (self::$_greetingTypes as $greeting) { - $filterCondition = array( + $filterCondition = [ 'contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => $greeting, - ); + ]; CRM_Utils_Array::lookupValue($defaults, $greeting, CRM_Core_PseudoConstant::greeting($filterCondition), $reverse ); } - $blocks = array('address', 'im', 'phone'); + $blocks = ['address', 'im', 'phone']; foreach ($blocks as $name) { if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) { continue; @@ -795,7 +801,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); if ($name == 'address') { // FIXME: lookupValue doesn't work for vcard_name if (!empty($values['location_type_id'])) { - $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name')); + $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', ['labelColumn' => 'vcard_name']); $values['vcard_name'] = $vcardNames[$values['location_type_id']]; } @@ -878,7 +884,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); unset($params['id']); //get the block information for this contact - $entityBlock = array('contact_id' => $params['contact_id']); + $entityBlock = ['contact_id' => $params['contact_id']]; $blocks = CRM_Core_BAO_Location::getValues($entityBlock, $microformat); $defaults = array_merge($defaults, $blocks); foreach ($blocks as $block => $value) { @@ -949,7 +955,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); // make sure we have edit permission for this contact // before we delete if ($checkPermissions && (($skipUndelete && !CRM_Core_Permission::check('delete contacts')) || - ($restore && !CRM_Core_Permission::check('access deleted contacts'))) + ($restore && !CRM_Core_Permission::check('access deleted contacts'))) ) { return FALSE; } @@ -957,7 +963,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); // CRM-12929 // Restrict contact to be delete if contact has financial trxns $error = NULL; - if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($id), $error)) { + if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent([$id], $error)) { return FALSE; } @@ -1078,7 +1084,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); // a table-locking query. It still seems a bit inadequate as it assumes the acl users can't see deleted // but this should not cause any change as long as contacts are not being trashed outside the // main functions for that. - CRM_Core_DAO::executeQuery('DELETE FROM civicrm_acl_contact_cache WHERE contact_id = %1', array(1 => array($contactID, 'Integer'))); + CRM_Core_DAO::executeQuery('DELETE FROM civicrm_acl_contact_cache WHERE contact_id = %1', [1 => [$contactID, 'Integer']]); } else { CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush(); @@ -1136,7 +1142,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $imageThumbWidth = round($thumbWidth * $imageRatio); } - return array($imageThumbWidth, $imageThumbHeight); + return [$imageThumbWidth, $imageThumbHeight]; } /** @@ -1159,7 +1165,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $statusMsg = NULL, $opType = 'status' ) { - $mimeType = array( + $mimeType = [ 'image/jpeg', 'image/jpg', 'image/png', @@ -1167,7 +1173,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); 'image/p-jpeg', 'image/gif', 'image/x-png', - ); + ]; if (in_array($params[$imageIndex]['type'], $mimeType)) { $photo = basename($params[$imageIndex]['name']); @@ -1220,14 +1226,14 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * @return bool */ public static function contactTrashRestore($contact, $restore = FALSE) { - $updateParams = array( + $updateParams = [ 'id' => $contact->id, 'is_deleted' => $restore ? 0 : 1, - ); + ]; CRM_Utils_Hook::pre('update', $contact->contact_type, $contact->id, $updateParams); - $params = array(1 => array($contact->id, 'Integer')); + $params = [1 => [$contact->id, 'Integer']]; if (!$restore) { $query = "DELETE FROM civicrm_uf_match WHERE contact_id = %1"; CRM_Core_DAO::executeQuery($query, $params); @@ -1269,7 +1275,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); public static function getContactSubType($id, $implodeDelimiter = NULL) { $subtype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $id, 'contact_sub_type'); if (!$subtype) { - return $implodeDelimiter ? NULL : array(); + return $implodeDelimiter ? NULL : []; } $subtype = CRM_Utils_Array::explodePadded($subtype); @@ -1289,16 +1295,16 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * @return array */ public static function getContactTypes($id) { - $params = array('id' => $id); - $details = array(); + $params = ['id' => $id]; + $details = []; $contact = CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, $details, - array('contact_type', 'contact_sub_type') + ['contact_type', 'contact_sub_type'] ); if ($contact) { - $contactTypes = array(); + $contactTypes = []; if ($contact->contact_sub_type) { $contactTypes = CRM_Utils_Array::explodePadded($contact->contact_sub_type); } @@ -1357,12 +1363,12 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $fields = CRM_Contact_DAO_Contact::import(); // get the fields thar are meant for contact types - if (in_array($contactType, array( + if (in_array($contactType, [ 'Individual', 'Household', 'Organization', 'All', - ))) { + ])) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } @@ -1407,14 +1413,14 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); ); //unset the fields, which are not related to their //contact type. - $commonValues = array( - 'Individual' => array( + $commonValues = [ + 'Individual' => [ 'household_name', 'legal_name', 'sic_code', 'organization_name', - ), - 'Household' => array( + ], + 'Household' => [ 'first_name', 'middle_name', 'last_name', @@ -1431,8 +1437,8 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); 'home_URL', 'is_deceased', 'deceased_date', - ), - 'Organization' => array( + ], + 'Organization' => [ 'first_name', 'middle_name', 'last_name', @@ -1445,14 +1451,14 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); 'household_name', 'is_deceased', 'deceased_date', - ), - ); + ], + ]; foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } else { - foreach (array('Individual', 'Household', 'Organization') as $type) { + foreach (['Individual', 'Household', 'Organization'] as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll, @@ -1466,24 +1472,24 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); } if ($isProfile) { - $fields = array_merge($fields, array( - 'group' => array( + $fields = array_merge($fields, [ + 'group' => [ 'title' => ts('Group(s)'), 'name' => 'group', - ), - 'tag' => array( + ], + 'tag' => [ 'title' => ts('Tag(s)'), 'name' => 'tag', - ), - 'note' => array( + ], + 'note' => [ 'title' => ts('Note'), 'name' => 'note', - ), - 'communication_style_id' => array( + ], + 'communication_style_id' => [ 'title' => ts('Communication Style'), 'name' => 'communication_style_id', - ), - )); + ], + ]); } //Sorting fields in alphabetical order(CRM-1507) @@ -1496,12 +1502,12 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); if (!$isProfile) { if (!$status) { - $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), + $fields = array_merge(['do_not_import' => ['title' => ts('- do not import -')]], self::$_importableFields[$cacheKeyString] ); } else { - $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), + $fields = array_merge(['' => ['title' => ts('- Contact Fields -')]], self::$_importableFields[$cacheKeyString] ); } @@ -1524,6 +1530,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * * @param bool $withMultiRecord * @param bool $checkPermissions + * * @return array * array of exportable Fields */ @@ -1543,7 +1550,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) { if (!self::$_exportableFields) { - self::$_exportableFields = array(); + self::$_exportableFields = []; } // check if we can retrieve from database cache @@ -1553,38 +1560,38 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $fields = CRM_Contact_DAO_Contact::export(); // The fields are meant for contact types. - if (in_array($contactType, array( + if (in_array($contactType, [ 'Individual', 'Household', 'Organization', 'All', - ))) { + ])) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } // add current employer for individuals - $fields = array_merge($fields, array( + $fields = array_merge($fields, [ 'current_employer' => - array( + [ 'name' => 'organization_name', 'title' => ts('Current Employer'), - ), - )); + ], + ]); - $locationType = array( - 'location_type' => array( + $locationType = [ + 'location_type' => [ 'name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type'), - ), - ); + ], + ]; - $IMProvider = array( - 'im_provider' => array( + $IMProvider = [ + 'im_provider' => [ 'name' => 'im_provider', 'where' => 'civicrm_im.provider_id', 'title' => ts('IM Provider'), - ), - ); + ], + ]; $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), @@ -1623,11 +1630,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); ); } else { - foreach (array( - 'Individual', - 'Household', - 'Organization', - ) as $type) { + foreach (['Individual', 'Household', 'Organization'] as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, $checkPermissions, $withMultiRecord) ); @@ -1636,36 +1639,36 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $fields['current_employer_id']['title'] = ts('Current Employer ID'); //fix for CRM-791 if ($export) { - $fields = array_merge($fields, array( - 'groups' => array( + $fields = array_merge($fields, [ + 'groups' => [ 'title' => ts('Group(s)'), 'name' => 'groups', - ), - 'tags' => array( + ], + 'tags' => [ 'title' => ts('Tag(s)'), 'name' => 'tags', - ), - 'notes' => array( + ], + 'notes' => [ 'title' => ts('Note(s)'), 'name' => 'notes', - ), - )); + ], + ]); } else { - $fields = array_merge($fields, array( - 'group' => array( + $fields = array_merge($fields, [ + 'group' => [ 'title' => ts('Group(s)'), 'name' => 'group', - ), - 'tag' => array( + ], + 'tag' => [ 'title' => ts('Tag(s)'), 'name' => 'tag', - ), - 'note' => array( + ], + 'note' => [ 'title' => ts('Note(s)'), 'name' => 'note', - ), - )); + ], + ]); } //Sorting fields in alphabetical order(CRM-1507) @@ -1676,8 +1679,8 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $fields = array_merge($sortArray, $fields); //unset the field which are not related to their contact type. if ($contactType != 'All') { - $commonValues = array( - 'Individual' => array( + $commonValues = [ + 'Individual' => [ 'household_name', 'legal_name', 'sic_code', @@ -1685,8 +1688,8 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', - ), - 'Household' => array( + ], + 'Household' => [ 'first_name', 'middle_name', 'last_name', @@ -1709,8 +1712,8 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); 'addressee_custom', 'prefix_id', 'suffix_id', - ), - 'Organization' => array( + ], + 'Organization' => [ 'first_name', 'middle_name', 'last_name', @@ -1730,8 +1733,8 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); 'is_deceased', 'deceased_date', 'current_employer', - ), - ); + ], + ]; foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } @@ -1746,7 +1749,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $fields = self::$_exportableFields[$cacheKeyString]; } else { - $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), + $fields = array_merge(['' => ['title' => ts('- Contact Fields -')]], self::$_exportableFields[$cacheKeyString] ); } @@ -1766,8 +1769,8 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); * Contact details */ public static function getHierContactDetails($contactId, $fields) { - $params = array(array('contact_id', '=', $contactId, 0, 0)); - $options = array(); + $params = [['contact_id', '=', $contactId, 0, 0]]; + $options = []; $returnProperties = self::makeHierReturnProperties($fields, $contactId); @@ -1796,9 +1799,9 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); public static function &makeHierReturnProperties($fields, $contactId = NULL) { $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); - $returnProperties = array(); + $returnProperties = []; - $multipleFields = array('website' => 'url'); + $multipleFields = ['website' => 'url']; foreach ($fields as $name => $dontCare) { if (strpos($name, '-') !== FALSE) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3); @@ -1815,19 +1818,19 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); } if (empty($returnProperties['location'])) { - $returnProperties['location'] = array(); + $returnProperties['location'] = []; } if (empty($returnProperties['location'][$locationTypeName])) { - $returnProperties['location'][$locationTypeName] = array(); + $returnProperties['location'][$locationTypeName] = []; $returnProperties['location'][$locationTypeName]['location_type'] = $id; } - if (in_array($fieldName, array( + if (in_array($fieldName, [ 'phone', 'im', 'email', 'openid', 'phone_ext', - ))) { + ])) { if ($type) { $returnProperties['location'][$locationTypeName][$fieldName . '-' . $type] = 1; } @@ -1870,7 +1873,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); */ public static function getPrimaryLocationType($contactId, $skipDefaultPriamry = FALSE, $block = NULL) { if ($block) { - $entityBlock = array('contact_id' => $contactId); + $entityBlock = ['contact_id' => $contactId]; $blocks = CRM_Core_BAO_Location::getValues($entityBlock); foreach ($blocks[$block] as $key => $value) { if (!empty($value['is_primary'])) { @@ -1898,7 +1901,7 @@ FROM civicrm_contact LEFT JOIN civicrm_openid ON ( civicrm_openid.is_primary = 1 AND civicrm_openid.contact_id = civicrm_contact.id) WHERE civicrm_contact.id = %1 "; - $params = array(1 => array($contactId, 'Integer')); + $params = [1 => [$contactId, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($query, $params); @@ -1942,7 +1945,7 @@ SELECT $nameFields, civicrm_email.email, civicrm_contact.do_not_email, civicrm_e FROM civicrm_contact LEFT JOIN civicrm_email ON (civicrm_contact.id = civicrm_email.contact_id) WHERE civicrm_contact.id = %1 ORDER BY civicrm_email.is_primary DESC"; - $params = array(1 => array($id, 'Integer')); + $params = [1 => [$id, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { @@ -1961,9 +1964,9 @@ ORDER BY civicrm_email.is_primary DESC"; $doNotEmail = $dao->do_not_email ? TRUE : FALSE; $onHold = $dao->on_hold ? TRUE : FALSE; $isDeceased = $dao->is_deceased ? TRUE : FALSE; - return array($name, $email, $doNotEmail, $onHold, $isDeceased); + return [$name, $email, $doNotEmail, $onHold, $isDeceased]; } - return array(NULL, NULL, NULL, NULL, NULL); + return [NULL, NULL, NULL, NULL, NULL]; } /** @@ -2028,11 +2031,11 @@ ORDER BY civicrm_email.is_primary DESC"; $data['is_opt_out'] = $isOptOut; // on change, create new civicrm_subscription_history entry if (($wasOptOut != $isOptOut) && !empty($contactDetails['contact_id'])) { - $shParams = array( + $shParams = [ 'contact_id' => $contactDetails['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web', - ); + ]; CRM_Contact_BAO_SubscriptionHistory::create($shParams); } } @@ -2067,13 +2070,13 @@ ORDER BY civicrm_email.is_primary DESC"; //to add profile in default group if (is_array($addToGroupID)) { - $contactIds = array($contactID); + $contactIds = [$contactID]; foreach ($addToGroupID as $groupId) { CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId); } } elseif ($addToGroupID) { - $contactIds = array($contactID); + $contactIds = [$contactID]; CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $addToGroupID); } @@ -2109,7 +2112,7 @@ ORDER BY civicrm_email.is_primary DESC"; $skipCustom = FALSE ) { - $data = $contactDetails = array(); + $data = $contactDetails = []; // get the contact details (hier) if ($contactID) { @@ -2172,7 +2175,7 @@ ORDER BY civicrm_email.is_primary DESC"; $data['household_name'] = CRM_Utils_Array::value('household_name', $contactDetails); } - $locationType = array(); + $locationType = []; $count = 1; if ($contactID) { @@ -2187,9 +2190,9 @@ ORDER BY civicrm_email.is_primary DESC"; $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling(); - $blocks = array('email', 'phone', 'im', 'openid'); + $blocks = ['email', 'phone', 'im', 'openid']; - $multiplFields = array('url'); + $multiplFields = ['url']; // prevent overwritten of formatted array, reset all block from // params if it is not in valid format (since import pass valid format) foreach ($blocks as $blk) { @@ -2255,7 +2258,7 @@ ORDER BY civicrm_email.is_primary DESC"; $data[$blockName][$loc]['is_primary'] = 1; } - if (in_array($fieldName, array('phone'))) { + if (in_array($fieldName, ['phone'])) { if ($typeId) { $data['phone'][$loc]['phone_type_id'] = $typeId; } @@ -2399,20 +2402,20 @@ ORDER BY civicrm_email.is_primary DESC"; FALSE ); } - elseif ($key == 'edit') { + elseif ($key === 'edit') { continue; } else { - if ($key == 'location') { + if ($key === 'location') { foreach ($value as $locationTypeId => $field) { foreach ($field as $block => $val) { - if ($block == 'address' && array_key_exists('address_name', $val)) { + if ($block === 'address' && array_key_exists('address_name', $val)) { $value[$locationTypeId][$block]['name'] = $value[$locationTypeId][$block]['address_name']; } } } } - if ($key == 'phone' && isset($params['phone_ext'])) { + if ($key === 'phone' && isset($params['phone_ext'])) { $data[$key] = $value; foreach ($value as $cnt => $phoneBlock) { if ($params[$key][$cnt]['location_type_id'] == $params['phone_ext'][$cnt]['location_type_id']) { @@ -2420,18 +2423,10 @@ ORDER BY civicrm_email.is_primary DESC"; } } } - elseif (in_array($key, array( - 'nick_name', - 'job_title', - 'middle_name', - 'birth_date', - 'gender_id', - 'current_employer', - 'prefix_id', - 'suffix_id', - )) && ($value == '' || !isset($value)) && - ($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 || - ($key == 'current_employer' && empty($params['current_employer']))) { + elseif (in_array($key, ['nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id']) + && ($value == '' || !isset($value)) && + ($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 || + ($key === 'current_employer' && empty($params['current_employer']))) { // CRM-10128: if auth source is not checksum / login && $value is blank, do not fill $data with empty value // to avoid update with empty values continue; @@ -2464,7 +2459,7 @@ ORDER BY civicrm_email.is_primary DESC"; } } - return array($data, $contactDetails); + return [$data, $contactDetails]; } /** @@ -2504,11 +2499,11 @@ INNER JOIN civicrm_group_contact gc ON $query .= " WHERE civicrm_email.email = %1 AND civicrm_contact.is_deleted=0"; - $p = array(1 => array($mail, 'String')); + $p = [1 => [$mail, 'String']]; if ($ctype) { $query .= " AND civicrm_contact.contact_type = %3"; - $p[3] = array($ctype, 'String'); + $p[3] = [$ctype, 'String']; } $query .= " ORDER BY civicrm_email.is_primary DESC"; @@ -2543,11 +2538,11 @@ SELECT civicrm_contact.id as contact_id, FROM civicrm_contact INNER JOIN civicrm_openid ON ( civicrm_contact.id = civicrm_openid.contact_id ) WHERE civicrm_openid.openid = %1"; - $p = array(1 => array($openId, 'String')); + $p = [1 => [$openId, 'String']]; if ($ctype) { $query .= " AND civicrm_contact.contact_type = %3"; - $p[3] = array($ctype, 'String'); + $p[3] = [$ctype, 'String']; } $query .= " ORDER BY civicrm_openid.is_primary DESC"; @@ -2577,7 +2572,7 @@ WHERE civicrm_openid.openid = %1"; LEFT JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id ) WHERE civicrm_email.is_primary = 1 AND civicrm_contact.id = %1"; - $p = array(1 => array($contactID, 'Integer')); + $p = [1 => [$contactID, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($query, $p); $email = NULL; @@ -2604,7 +2599,7 @@ FROM civicrm_contact LEFT JOIN civicrm_openid ON ( civicrm_contact.id = civicrm_openid.contact_id ) WHERE civicrm_contact.id = %1 AND civicrm_openid.is_primary = 1"; - $p = array(1 => array($contactID, 'Integer')); + $p = [1 => [$contactID, 'Integer']]; $dao = CRM_Core_DAO::executeQuery($query, $p); $openId = NULL; @@ -2634,7 +2629,7 @@ AND civicrm_openid.is_primary = 1"; CRM_Core_DAO::storeValues($contact, $values); - $privacy = array(); + $privacy = []; foreach (self::$_commPrefs as $name) { if (isset($contact->$name)) { $privacy[$name] = $contact->$name; @@ -2646,21 +2641,21 @@ AND civicrm_openid.is_primary = 1"; } // communication Prefferance - $preffComm = $comm = array(); + $preffComm = $comm = []; $comm = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contact->preferred_communication_method ); foreach ($comm as $value) { $preffComm[$value] = 1; } - $temp = array('preferred_communication_method' => $contact->preferred_communication_method); + $temp = ['preferred_communication_method' => $contact->preferred_communication_method]; - $names = array( - 'preferred_communication_method' => array( + $names = [ + 'preferred_communication_method' => [ 'newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method', - ), - ); + ], + ]; // @todo This can be figured out from metadata & we can avoid the uncached query. CRM_Core_OptionGroup::lookupValues($temp, $names, FALSE); @@ -2755,16 +2750,16 @@ AND civicrm_openid.is_primary = 1"; return CRM_Grant_BAO_Grant::getContactGrantCount($contactId); case 'activity': - $input = array( + $input = [ 'contact_id' => $contactId, 'admin' => FALSE, 'caseId' => NULL, 'context' => 'activity', - ); + ]; return CRM_Activity_BAO_Activity::getActivitiesCount($input); case 'mailing': - $params = array('contact_id' => $contactId); + $params = ['contact_id' => $contactId]; return CRM_Mailing_BAO_Mailing::getContactMailingsCount($params); default: @@ -2825,12 +2820,12 @@ AND civicrm_openid.is_primary = 1"; } // store object values to an array - $contactDetails = array(); + $contactDetails = []; CRM_Core_DAO::storeValues($contact, $contactDetails); - $contactDetails = array(array($contact->id => $contactDetails)); + $contactDetails = [[$contact->id => $contactDetails]]; $emailGreetingString = $postalGreetingString = $addresseeString = NULL; - $updateQueryString = array(); + $updateQueryString = []; //cache email and postal greeting to greeting display if ($contact->email_greeting_custom != 'null' && $contact->email_greeting_custom) { @@ -2838,10 +2833,10 @@ AND civicrm_openid.is_primary = 1"; } elseif ($contact->email_greeting_id != 'null' && $contact->email_greeting_id) { // the filter value for Individual contact type is set to 1 - $filter = array( + $filter = [ 'contact_type' => $contact->contact_type, 'greeting_type' => 'email_greeting', - ); + ]; $emailGreeting = CRM_Core_PseudoConstant::greeting($filter); $emailGreetingString = $emailGreeting[$contact->email_greeting_id]; @@ -2864,14 +2859,14 @@ AND civicrm_openid.is_primary = 1"; } //postal greetings - if ($contact->postal_greeting_custom != 'null' && $contact->postal_greeting_custom) { + if ($contact->postal_greeting_custom !== 'null' && $contact->postal_greeting_custom) { $postalGreetingString = $contact->postal_greeting_custom; } - elseif ($contact->postal_greeting_id != 'null' && $contact->postal_greeting_id) { - $filter = array( + elseif ($contact->postal_greeting_id !== 'null' && $contact->postal_greeting_id) { + $filter = [ 'contact_type' => $contact->contact_type, 'greeting_type' => 'postal_greeting', - ); + ]; $postalGreeting = CRM_Core_PseudoConstant::greeting($filter); $postalGreetingString = $postalGreeting[$contact->postal_greeting_id]; $updateQueryString[] = " postal_greeting_custom = NULL "; @@ -2893,14 +2888,14 @@ AND civicrm_openid.is_primary = 1"; } // addressee - if ($contact->addressee_custom != 'null' && $contact->addressee_custom) { + if ($contact->addressee_custom !== 'null' && $contact->addressee_custom) { $addresseeString = $contact->addressee_custom; } - elseif ($contact->addressee_id != 'null' && $contact->addressee_id) { - $filter = array( + elseif ($contact->addressee_id !== 'null' && $contact->addressee_id) { + $filter = [ 'contact_type' => $contact->contact_type, 'greeting_type' => 'addressee', - ); + ]; $addressee = CRM_Core_PseudoConstant::greeting($filter); $addresseeString = $addressee[$contact->addressee_id]; @@ -2943,13 +2938,13 @@ AND civicrm_openid.is_primary = 1"; * @return array * loc block ids which fulfill condition. */ - public static function getLocBlockIds($contactId, $criteria = array(), $condOperator = 'AND') { - $locBlockIds = array(); + public static function getLocBlockIds($contactId, $criteria = [], $condOperator = 'AND') { + $locBlockIds = []; if (!$contactId) { return $locBlockIds; } - foreach (array('Email', 'OpenID', 'Phone', 'Address', 'IM') as $block) { + foreach (['Email', 'OpenID', 'Phone', 'Address', 'IM'] as $block) { $name = strtolower($block); $className = "CRM_Core_DAO_$block"; $blockDAO = new $className(); @@ -2957,12 +2952,12 @@ AND civicrm_openid.is_primary = 1"; // build the condition. if (is_array($criteria)) { $fields = $blockDAO->fields(); - $conditions = array(); + $conditions = []; foreach ($criteria as $field => $value) { if (array_key_exists($field, $fields)) { $cond = "( $field = $value )"; // value might be zero or null. - if (!$value || strtolower($value) == 'null') { + if (!$value || strtolower($value) === 'null') { $cond = "( $field = 0 OR $field IS NULL )"; } $conditions[] = $cond; @@ -2992,31 +2987,31 @@ AND civicrm_openid.is_primary = 1"; * Array of context menu for logged in user. */ public static function contextMenu($contactId = NULL) { - $menu = array( - 'view' => array( + $menu = [ + 'view' => [ 'title' => ts('View Contact'), 'weight' => 0, 'ref' => 'view-contact', 'class' => 'no-popup', 'key' => 'view', - 'permissions' => array('view all contacts'), - ), - 'add' => array( + 'permissions' => ['view all contacts'], + ], + 'add' => [ 'title' => ts('Edit Contact'), 'weight' => 0, 'ref' => 'edit-contact', 'class' => 'no-popup', 'key' => 'add', - 'permissions' => array('edit all contacts'), - ), - 'delete' => array( + 'permissions' => ['edit all contacts'], + ], + 'delete' => [ 'title' => ts('Delete Contact'), 'weight' => 0, 'ref' => 'delete-contact', 'key' => 'delete', - 'permissions' => array('access deleted contacts', 'delete contacts'), - ), - 'contribution' => array( + 'permissions' => ['access deleted contacts', 'delete contacts'], + ], + 'contribution' => [ 'title' => ts('Add Contribution'), 'weight' => 5, 'ref' => 'new-contribution', @@ -3026,12 +3021,12 @@ AND civicrm_openid.is_primary = 1"; 'href' => CRM_Utils_System::url('civicrm/contact/view/contribution', 'reset=1&action=add&context=contribution' ), - 'permissions' => array( + 'permissions' => [ 'access CiviContribute', 'edit contributions', - ), - ), - 'participant' => array( + ], + ], + 'participant' => [ 'title' => ts('Register for Event'), 'weight' => 10, 'ref' => 'new-participant', @@ -3039,19 +3034,19 @@ AND civicrm_openid.is_primary = 1"; 'tab' => 'participant', 'component' => 'CiviEvent', 'href' => CRM_Utils_System::url('civicrm/contact/view/participant', 'reset=1&action=add&context=participant'), - 'permissions' => array( + 'permissions' => [ 'access CiviEvent', 'edit event participants', - ), - ), - 'activity' => array( + ], + ], + 'activity' => [ 'title' => ts('Record Activity'), 'weight' => 35, 'ref' => 'new-activity', 'key' => 'activity', - 'permissions' => array('edit all contacts'), - ), - 'pledge' => array( + 'permissions' => ['edit all contacts'], + ], + 'pledge' => [ 'title' => ts('Add Pledge'), 'weight' => 15, 'ref' => 'new-pledge', @@ -3061,12 +3056,12 @@ AND civicrm_openid.is_primary = 1"; 'reset=1&action=add&context=pledge' ), 'component' => 'CiviPledge', - 'permissions' => array( + 'permissions' => [ 'access CiviPledge', 'edit pledges', - ), - ), - 'membership' => array( + ], + ], + 'membership' => [ 'title' => ts('Add Membership'), 'weight' => 20, 'ref' => 'new-membership', @@ -3076,12 +3071,12 @@ AND civicrm_openid.is_primary = 1"; 'href' => CRM_Utils_System::url('civicrm/contact/view/membership', 'reset=1&action=add&context=membership' ), - 'permissions' => array( + 'permissions' => [ 'access CiviMember', 'edit memberships', - ), - ), - 'case' => array( + ], + ], + 'case' => [ 'title' => ts('Add Case'), 'weight' => 25, 'ref' => 'new-case', @@ -3089,9 +3084,9 @@ AND civicrm_openid.is_primary = 1"; 'tab' => 'case', 'component' => 'CiviCase', 'href' => CRM_Utils_System::url('civicrm/case/add', 'reset=1&action=add&context=case'), - 'permissions' => array('add cases'), - ), - 'grant' => array( + 'permissions' => ['add cases'], + ], + 'grant' => [ 'title' => ts('Add Grant'), 'weight' => 26, 'ref' => 'new-grant', @@ -3101,9 +3096,9 @@ AND civicrm_openid.is_primary = 1"; 'href' => CRM_Utils_System::url('civicrm/contact/view/grant', 'reset=1&action=add&context=grant' ), - 'permissions' => array('edit grants'), - ), - 'rel' => array( + 'permissions' => ['edit grants'], + ], + 'rel' => [ 'title' => ts('Add Relationship'), 'weight' => 30, 'ref' => 'new-relationship', @@ -3112,9 +3107,9 @@ AND civicrm_openid.is_primary = 1"; 'href' => CRM_Utils_System::url('civicrm/contact/view/rel', 'reset=1&action=add' ), - 'permissions' => array('edit all contacts'), - ), - 'note' => array( + 'permissions' => ['edit all contacts'], + ], + 'note' => [ 'title' => ts('Add Note'), 'weight' => 40, 'ref' => 'new-note', @@ -3124,35 +3119,35 @@ AND civicrm_openid.is_primary = 1"; 'href' => CRM_Utils_System::url('civicrm/contact/view/note', 'reset=1&action=add' ), - 'permissions' => array('edit all contacts'), - ), - 'email' => array( + 'permissions' => ['edit all contacts'], + ], + 'email' => [ 'title' => ts('Send an Email'), 'weight' => 45, 'ref' => 'new-email', 'key' => 'email', - 'permissions' => array('view all contacts'), - ), - 'group' => array( + 'permissions' => ['view all contacts'], + ], + 'group' => [ 'title' => ts('Add to Group'), 'weight' => 50, 'ref' => 'group-add-contact', 'key' => 'group', 'tab' => 'group', - 'permissions' => array('edit groups'), - ), - 'tag' => array( + 'permissions' => ['edit groups'], + ], + 'tag' => [ 'title' => ts('Tag Contact'), 'weight' => 55, 'ref' => 'tag-contact', 'key' => 'tag', 'tab' => 'tag', - 'permissions' => array('edit all contacts'), - ), - ); + 'permissions' => ['edit all contacts'], + ], + ]; - $menu['otherActions'] = array( - 'print' => array( + $menu['otherActions'] = [ + 'print' => [ 'title' => ts('Print Summary'), 'description' => ts('Printer-friendly view of this page.'), 'weight' => 5, @@ -3164,8 +3159,8 @@ AND civicrm_openid.is_primary = 1"; ), 'class' => 'print', 'icon' => 'crm-i fa-print', - ), - 'vcard' => array( + ], + 'vcard' => [ 'title' => ts('vCard'), 'description' => ts('vCard record for this contact.'), 'weight' => 10, @@ -3177,11 +3172,11 @@ AND civicrm_openid.is_primary = 1"; ), 'class' => 'vcard', 'icon' => 'crm-i fa-list-alt', - ), - ); + ], + ]; if (CRM_Core_Permission::check('access Contact Dashboard')) { - $menu['otherActions']['dashboard'] = array( + $menu['otherActions']['dashboard'] = [ 'title' => ts('Contact Dashboard'), 'description' => ts('Contact Dashboard'), 'weight' => 15, @@ -3193,12 +3188,12 @@ AND civicrm_openid.is_primary = 1"; // as CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($contactId) 'href' => CRM_Utils_System::url('civicrm/user', "reset=1&id={$contactId}"), 'icon' => 'crm-i fa-tachometer', - ); + ]; } $uid = CRM_Core_BAO_UFMatch::getUFId($contactId); if ($uid) { - $menu['otherActions']['user-record'] = array( + $menu['otherActions']['user-record'] = [ 'title' => ts('User Record'), 'description' => ts('User Record'), 'weight' => 20, @@ -3208,10 +3203,10 @@ AND civicrm_openid.is_primary = 1"; 'class' => 'user-record', 'href' => CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($contactId), 'icon' => 'crm-i fa-user', - ); + ]; } elseif (CRM_Core_Config::singleton()->userSystem->checkPermissionAddUser()) { - $menu['otherActions']['user-add'] = array( + $menu['otherActions']['user-add'] = [ 'title' => ts('Create User Record'), 'description' => ts('Create User Record'), 'weight' => 25, @@ -3221,7 +3216,7 @@ AND civicrm_openid.is_primary = 1"; 'class' => 'user-add', 'href' => CRM_Utils_System::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $contactId), 'icon' => 'crm-i fa-user-plus', - ); + ]; } CRM_Utils_Hook::summaryActions($menu, $contactId); @@ -3230,7 +3225,7 @@ AND civicrm_openid.is_primary = 1"; //3. check for acls. //3. edit and view contact are directly accessible to user. - $aclPermissionedTasks = array( + $aclPermissionedTasks = [ 'view-contact', 'edit-contact', 'new-activity', @@ -3238,40 +3233,40 @@ AND civicrm_openid.is_primary = 1"; 'group-add-contact', 'tag-contact', 'delete-contact', - ); + ]; $corePermission = CRM_Core_Permission::getPermission(); - $contextMenu = array(); + $contextMenu = []; foreach ($menu as $key => $values) { - if ($key != 'otherActions') { + if ($key !== 'otherActions') { // user does not have necessary permissions. if (!self::checkUserMenuPermissions($aclPermissionedTasks, $corePermission, $values)) { continue; } // build directly accessible action menu. - if (in_array($values['ref'], array( + if (in_array($values['ref'], [ 'view-contact', 'edit-contact', - ))) { - $contextMenu['primaryActions'][$key] = array( + ])) { + $contextMenu['primaryActions'][$key] = [ 'title' => $values['title'], 'ref' => $values['ref'], 'class' => CRM_Utils_Array::value('class', $values), 'key' => $values['key'], - ); + ]; continue; } // finally get menu item for -more- action widget. - $contextMenu['moreActions'][$values['weight']] = array( + $contextMenu['moreActions'][$values['weight']] = [ 'title' => $values['title'], 'ref' => $values['ref'], 'href' => CRM_Utils_Array::value('href', $values), 'tab' => CRM_Utils_Array::value('tab', $values), 'class' => CRM_Utils_Array::value('class', $values), 'key' => $values['key'], - ); + ]; } else { foreach ($values as $value) { @@ -3281,7 +3276,7 @@ AND civicrm_openid.is_primary = 1"; } // finally get menu item for -more- action widget. - $contextMenu['otherActions'][$value['weight']] = array( + $contextMenu['otherActions'][$value['weight']] = [ 'title' => $value['title'], 'ref' => $value['ref'], 'href' => CRM_Utils_Array::value('href', $value), @@ -3289,7 +3284,7 @@ AND civicrm_openid.is_primary = 1"; 'class' => CRM_Utils_Array::value('class', $value), 'icon' => CRM_Utils_Array::value('icon', $value), 'key' => $value['key'], - ); + ]; } } } @@ -3343,15 +3338,15 @@ AND civicrm_openid.is_primary = 1"; } // if still user does not have required permissions, check acl. - if (!$hasAllPermissions && $menuOptions['ref'] != 'delete-contact') { + if (!$hasAllPermissions && $menuOptions['ref'] !== 'delete-contact') { if (in_array($menuOptions['ref'], $aclPermissionedTasks) && - $corePermission == CRM_Core_Permission::EDIT - ) { + $corePermission == CRM_Core_Permission::EDIT + ) { $hasAllPermissions = TRUE; } - elseif (in_array($menuOptions['ref'], array( + elseif (in_array($menuOptions['ref'], [ 'new-email', - ))) { + ])) { // grant permissions for these tasks. $hasAllPermissions = TRUE; } @@ -3402,15 +3397,15 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) 'SELECT created_date, modified_date FROM civicrm_contact WHERE id = %1', - array( - 1 => array($contactId, 'Integer'), - ) + [ + 1 => [$contactId, 'Integer'], + ] ); if ($timestamps->fetch()) { - return array( + return [ 'created_date' => $timestamps->created_date, 'modified_date' => $timestamps->modified_date, - ); + ]; } else { return NULL; @@ -3420,12 +3415,13 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) /** * Get a list of triggers for the contact table. * - * @see hook_civicrm_triggerInfo - * @see CRM_Core_DAO::triggerRebuild - * @see http://issues.civicrm.org/jira/browse/CRM-10554 - * * @param $info * @param null $tableName + * + * @see http://issues.civicrm.org/jira/browse/CRM-10554 + * + * @see hook_civicrm_triggerInfo + * @see CRM_Core_DAO::triggerRebuild */ public static function triggerInfo(&$info, $tableName = NULL) { //during upgrade, first check for valid version and then create triggers @@ -3440,13 +3436,13 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) // Modifications to these records should update the contact timestamps. \Civi\Core\SqlTrigger\TimestampTriggers::create('civicrm_contact', 'Contact') - ->setRelations(array( - array('table' => 'civicrm_address', 'column' => 'contact_id'), - array('table' => 'civicrm_email', 'column' => 'contact_id'), - array('table' => 'civicrm_im', 'column' => 'contact_id'), - array('table' => 'civicrm_phone', 'column' => 'contact_id'), - array('table' => 'civicrm_website', 'column' => 'contact_id'), - )) + ->setRelations([ + ['table' => 'civicrm_address', 'column' => 'contact_id'], + ['table' => 'civicrm_email', 'column' => 'contact_id'], + ['table' => 'civicrm_im', 'column' => 'contact_id'], + ['table' => 'civicrm_phone', 'column' => 'contact_id'], + ['table' => 'civicrm_website', 'column' => 'contact_id'], + ]) ->alterTriggerInfo($info, $tableName); // Update phone table to populate phone_numeric field @@ -3455,12 +3451,12 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) $sqlTriggers = Civi::service('sql_triggers'); $sqlTriggers->enqueueQuery(self::DROP_STRIP_FUNCTION_43); $sqlTriggers->enqueueQuery(self::CREATE_STRIP_FUNCTION_43); - $info[] = array( - 'table' => array('civicrm_phone'), + $info[] = [ + 'table' => ['civicrm_phone'], 'when' => 'BEFORE', - 'event' => array('INSERT', 'UPDATE'), + 'event' => ['INSERT', 'UPDATE'], 'sql' => "\nSET NEW.phone_numeric = civicrm_strip_non_numeric(NEW.phone);\n", - ); + ]; } } @@ -3490,21 +3486,21 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) /** * Get options for a given contact field. * - * @see CRM_Core_DAO::buildOptions - * - * TODO: Should we always assume chainselect? What fn should be responsible for controlling that flow? - * TODO: In context of chainselect, what to return if e.g. a country has no states? - * * @param string $fieldName * @param string $context - * @see CRM_Core_DAO::buildOptionsContext * @param array $props * whatever is known about this dao object. * * @return array|bool + * @see CRM_Core_DAO::buildOptions + * + * TODO: Should we always assume chainselect? What fn should be responsible for controlling that flow? + * TODO: In context of chainselect, what to return if e.g. a country has no states? + * + * @see CRM_Core_DAO::buildOptionsContext */ - public static function buildOptions($fieldName, $context = NULL, $props = array()) { - $params = array(); + public static function buildOptions($fieldName, $context = NULL, $props = []) { + $params = []; // Special logic for fields whose options depend on context or properties switch ($fieldName) { case 'contact_sub_type': @@ -3553,6 +3549,7 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) * * @param string $type * @param int $id + * * @return bool */ public static function deleteObjectWithPrimary($type, $id) { @@ -3597,10 +3594,10 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) public function addSelectWhereClause() { // We always return an array with these keys, even if they are empty, // because this tells the query builder that we have considered these fields for acls - $clauses = array( + $clauses = [ 'id' => (array) CRM_Contact_BAO_Contact_Permission::cacheSubquery(), - 'is_deleted' => CRM_Core_Permission::check('access deleted contacts') ? array() : array('!= 1'), - ); + 'is_deleted' => CRM_Core_Permission::check('access deleted contacts') ? [] : ['!= 1'], + ]; CRM_Utils_Hook::selectWhereClause($this, $clauses); return $clauses; } @@ -3715,13 +3712,13 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) ]; foreach ($retrieved['values'] as $id => $profile) { if (in_array($profile['name'], $profiles)) { - $links[] = array( + $links[] = [ 'label' => $profile['title'], 'url' => CRM_Utils_System::url('civicrm/profile/create', "reset=1&context=dialog&gid=$id", NULL, NULL, FALSE, FALSE, TRUE), 'type' => ucfirst(str_replace('new_', '', $profile['name'])), 'icon' => CRM_Utils_Array::value(str_replace('new_', '', $profile['name']), $icons), - ); + ]; } else { $append[] = $id; diff --git a/CRM/Contact/BAO/Individual.php b/CRM/Contact/BAO/Individual.php index e0ada62e16..754b2bd1fc 100644 --- a/CRM/Contact/BAO/Individual.php +++ b/CRM/Contact/BAO/Individual.php @@ -47,7 +47,7 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact { * * @param array $params * (reference ) an assoc array of name/value pairs. - * @param CRM $contact + * @param CRM_Contact_BAO_Contact $contact * Contact object. * * @return CRM_Contact_BAO_Contact