From: Tim Otten Date: Tue, 6 Jan 2015 19:58:04 +0000 (-0800) Subject: INFRA-132 - CRM/Contact/BAO/Contact.php - Cleanup via PHPStorm X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9bb77b8e15e15949eaf61abbd9d50fb9b0ee7ab5;p=civicrm-core.git INFRA-132 - CRM/Contact/BAO/Contact.php - Cleanup via PHPStorm --- diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 96f461e1ba..1477e1cc92 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -122,14 +122,15 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { } //fix for validate contact sub type CRM-5143 - if ( isset( $params['contact_sub_type'] ) ) { - if ( empty($params['contact_sub_type']) ) { + if (isset($params['contact_sub_type'])) { + if (empty($params['contact_sub_type'])) { $params['contact_sub_type'] = 'null'; } else { if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'], $params['contact_type'], TRUE - )) { + ) + ) { // we'll need to fix tests to handle this // CRM-7925 CRM_Core_Error::fatal(ts('The Contact Sub Type does not match the Contact type for this record')); @@ -280,117 +281,95 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { * @static */ public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE, $skipDelete = FALSE) { - $contact = NULL; - if (empty($params['contact_type']) && empty($params['contact_id'])) { - return $contact; - } + $contact = NULL; + if (empty($params['contact_type']) && empty($params['contact_id'])) { + return $contact; + } - $isEdit = TRUE; - if ($invokeHooks) { - if (!empty($params['contact_id'])) { - CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); - } - else { - CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params); - $isEdit = FALSE; - } + $isEdit = TRUE; + if ($invokeHooks) { + if (!empty($params['contact_id'])) { + CRM_Utils_Hook::pre('edit', $params['contact_type'], $params['contact_id'], $params); + } + else { + CRM_Utils_Hook::pre('create', $params['contact_type'], NULL, $params); + $isEdit = FALSE; } + } - $config = CRM_Core_Config::singleton(); + $config = CRM_Core_Config::singleton(); - // CRM-6942: set preferred language to the current language if it’s unset (and we’re creating a contact) - if (empty($params['contact_id']) && empty($params['preferred_language'])) { - $params['preferred_language'] = $config->lcMessages; - } + // CRM-6942: set preferred language to the current language if it’s unset (and we’re creating a contact) + if (empty($params['contact_id']) && empty($params['preferred_language'])) { + $params['preferred_language'] = $config->lcMessages; + } - // CRM-9739: set greeting & addressee if unset and we’re creating a contact - if (empty($params['contact_id'])) { - foreach (self::$_greetingTypes as $greeting) { - if (empty($params[$greeting . '_id'])) { - if ($defaultGreetingTypeId = - CRM_Contact_BAO_Contact_Utils::defaultGreeting($params['contact_type'], $greeting) - ) { - $params[$greeting . '_id'] = $defaultGreetingTypeId; - } + // CRM-9739: set greeting & addressee if unset and we’re creating a contact + if (empty($params['contact_id'])) { + foreach (self::$_greetingTypes as $greeting) { + if (empty($params[$greeting . '_id'])) { + if ($defaultGreetingTypeId = + CRM_Contact_BAO_Contact_Utils::defaultGreeting($params['contact_type'], $greeting) + ) { + $params[$greeting . '_id'] = $defaultGreetingTypeId; } } } + } - $transaction = new CRM_Core_Transaction(); + $transaction = new CRM_Core_Transaction(); - $contact = self::add($params); - if (!$contact) { - // not dying here is stupid, since we get into wierd situation and into a bug that - // is impossible to figure out for the user or for us - // CRM-7925 - CRM_Core_Error::fatal(); - } + $contact = self::add($params); + if (!$contact) { + // not dying here is stupid, since we get into wierd situation and into a bug that + // is impossible to figure out for the user or for us + // CRM-7925 + CRM_Core_Error::fatal(); + } - $params['contact_id'] = $contact->id; + $params['contact_id'] = $contact->id; - if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, - 'is_enabled' - )) { - // Enabling multisite causes the contact to be added to the domain group - $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); - if(!empty($domainGroupID)){ - if (!empty($params['group']) && is_array($params['group'])) { - $params['group'][$domainGroupID] = 1; - } - else { - $params['group'] = array($domainGroupID => 1); - } + if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled')) { + // Enabling multisite causes the contact to be added to the domain group + $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); + if (!empty($domainGroupID)) { + if (!empty($params['group']) && is_array($params['group'])) { + $params['group'][$domainGroupID] = 1; } - } - - if (array_key_exists('group', $params)) { - $contactIds = array($params['contact_id']); - foreach ($params['group'] as $groupId => $flag) { - if ($flag == 1) { - CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId); - } - elseif ($flag == -1) { - CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId); - } + else { + $params['group'] = array($domainGroupID => 1); } } + } - //add location Block data - $blocks = CRM_Core_BAO_Location::create($params, $fixAddress); - foreach ($blocks as $name => $value) { - $contact->$name = $value; + if (array_key_exists('group', $params)) { + $contactIds = array($params['contact_id']); + foreach ($params['group'] as $groupId => $flag) { + if ($flag == 1) { + CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId); + } + elseif ($flag == -1) { + CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $groupId); + } } + } - //add website - CRM_Core_BAO_Website::create($params['website'], $contact->id, $skipDelete); + //add location Block data + $blocks = CRM_Core_BAO_Location::create($params, $fixAddress); + foreach ($blocks as $name => $value) { + $contact->$name = $value; + } - //get userID from session - $session = CRM_Core_Session::singleton(); - $userID = $session->get('userID'); - // add notes - if (!empty($params['note'])) { - if (is_array($params['note'])) { - foreach ($params['note'] as $note) { - $contactId = $contact->id; - if (isset($note['contact_id'])) { - $contactId = $note['contact_id']; - } - //if logged in user, overwrite contactId - if ($userID) { - $contactId = $userID; - } + //add website + CRM_Core_BAO_Website::create($params['website'], $contact->id, $skipDelete); - $noteParams = array( - '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, CRM_Core_DAO::$_nullArray); - } - } - else { + //get userID from session + $session = CRM_Core_Session::singleton(); + $userID = $session->get('userID'); + // add notes + if (!empty($params['note'])) { + if (is_array($params['note'])) { + foreach ($params['note'] as $note) { $contactId = $contact->id; if (isset($note['contact_id'])) { $contactId = $note['contact_id']; @@ -403,65 +382,85 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact { $noteParams = array( 'entity_id' => $contact->id, 'entity_table' => 'civicrm_contact', - 'note' => $params['note'], - 'subject' => CRM_Utils_Array::value('subject', $params), + 'note' => $note['note'], + 'subject' => CRM_Utils_Array::value('subject', $note), 'contact_id' => $contactId, ); CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray); } } + else { + $contactId = $contact->id; + if (isset($note['contact_id'])) { + $contactId = $note['contact_id']; + } + //if logged in user, overwrite contactId + if ($userID) { + $contactId = $userID; + } - - // update the UF user_unique_id if that has changed - CRM_Core_BAO_UFMatch::updateUFName($contact->id); - - if (!empty($params['custom']) && - is_array($params['custom']) - ) { - CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contact', $contact->id); - } - - // make a civicrm_subscription_history entry only on contact create (CRM-777) - if (empty($params['contact_id'])) { - $subscriptionParams = array( - 'contact_id' => $contact->id, - 'status' => 'Added', - 'method' => 'Admin', + $noteParams = array( + 'entity_id' => $contact->id, + 'entity_table' => 'civicrm_contact', + 'note' => $params['note'], + 'subject' => CRM_Utils_Array::value('subject', $params), + 'contact_id' => $contactId, ); - CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams); + CRM_Core_BAO_Note::add($noteParams, CRM_Core_DAO::$_nullArray); } + } - $transaction->commit(); - // CRM-6367: fetch the right label for contact type’s display - $contact->contact_type_display = CRM_Core_DAO::getFieldValue( - 'CRM_Contact_DAO_ContactType', - $contact->contact_type, - 'label', - 'name' + // update the UF user_unique_id if that has changed + CRM_Core_BAO_UFMatch::updateUFName($contact->id); + + if (!empty($params['custom']) && + is_array($params['custom']) + ) { + CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contact', $contact->id); + } + + // make a civicrm_subscription_history entry only on contact create (CRM-777) + if (empty($params['contact_id'])) { + $subscriptionParams = array( + 'contact_id' => $contact->id, + 'status' => 'Added', + 'method' => 'Admin', ); + CRM_Contact_BAO_SubscriptionHistory::create($subscriptionParams); + } - if (!$config->doNotResetCache) { - // Note: doNotResetCache flag is currently set by import contact process and merging, - // since resetting and - // rebuilding cache could be expensive (for many contacts). We might come out with better - // approach in future. - CRM_Contact_BAO_Contact_Utils::clearContactCaches($contact->id); - } + $transaction->commit(); - if ($invokeHooks) { - if ($isEdit) { - CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); - } - else { - CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); - } + // CRM-6367: fetch the right label for contact type’s display + $contact->contact_type_display = CRM_Core_DAO::getFieldValue( + 'CRM_Contact_DAO_ContactType', + $contact->contact_type, + 'label', + 'name' + ); + + if (!$config->doNotResetCache) { + // Note: doNotResetCache flag is currently set by import contact process and merging, + // since resetting and + // rebuilding cache could be expensive (for many contacts). We might come out with better + // approach in future. + CRM_Contact_BAO_Contact_Utils::clearContactCaches($contact->id); + } + + if ($invokeHooks) { + if ($isEdit) { + CRM_Utils_Hook::post('edit', $params['contact_type'], $contact->id, $contact); + } + else { + CRM_Utils_Hook::post('create', $params['contact_type'], $contact->id, $contact); } + } - // process greetings CRM-4575, cache greetings - self::processGreetings($contact); + // process greetings CRM-4575, cache greetings + self::processGreetings($contact); - return $contact; + return $contact; } /** @@ -578,7 +577,8 @@ 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('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), + $filterCondition = array( + 'contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => $greeting, ); CRM_Utils_Array::lookupValue($defaults, $greeting, @@ -711,9 +711,11 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); //get the block information for this contact $entityBlock = array('contact_id' => $params['contact_id']); - $blocks = CRM_Core_BAO_Location::getValues($entityBlock, $microformat); - $defaults = array_merge($defaults, $blocks); - foreach ($blocks as $block => $value) $contact->$block = $value; + $blocks = CRM_Core_BAO_Location::getValues($entityBlock, $microformat); + $defaults = array_merge($defaults, $blocks); + foreach ($blocks as $block => $value) { + $contact->$block = $value; + } if (!isset($params['noNotes'])) { $contact->notes = CRM_Core_BAO_Note::getValues($params, $defaults); @@ -938,10 +940,11 @@ WHERE id={$id}; "; $baseUrl, str_replace('\\', '/', $absolutePath) ); - } else if ( $config->userFramework == 'WordPress' ) { - $userFrameworkBaseURL = trim( str_replace( '/wp-admin/', '', $config->userFrameworkBaseURL ) ); - $customFileUploadDirectory = strstr( str_replace('\\', '/', $absolutePath), '/wp-content/' ); - $relativePath = $userFrameworkBaseURL . $customFileUploadDirectory; + } + else if ($config->userFramework == 'WordPress') { + $userFrameworkBaseURL = trim(str_replace('/wp-admin/', '', $config->userFrameworkBaseURL)); + $customFileUploadDirectory = strstr(str_replace('\\', '/', $absolutePath), '/wp-content/'); + $relativePath = $userFrameworkBaseURL . $customFileUploadDirectory; } return $relativePath; @@ -991,10 +994,11 @@ WHERE id={$id}; "; * * @return boolean true if valid image extension */ - public static function processImageParams(&$params, + public static function processImageParams( + &$params, $imageIndex = 'image_URL', - $statusMsg = NULL, - $opType = 'status' + $statusMsg = NULL, + $opType = 'status' ) { $mimeType = array( 'image/jpeg', @@ -1008,7 +1012,7 @@ WHERE id={$id}; "; if (in_array($params[$imageIndex]['type'], $mimeType)) { $photo = basename($params[$imageIndex]['name']); - $params[$imageIndex] = CRM_Utils_System::url('civicrm/contact/imagefile', 'photo='.$photo, TRUE, NULL, TRUE, TRUE); + $params[$imageIndex] = CRM_Utils_System::url('civicrm/contact/imagefile', 'photo=' . $photo, TRUE, NULL, TRUE, TRUE); return TRUE; } else { @@ -1048,11 +1052,11 @@ WHERE id={$id}; "; /** * Function to set is_delete true or restore deleted contact * - * @param int $contact Contact DAO object - * @param boolean $restore true to set the is_delete = 1 else false to restore deleted contact, + * @param int $contact Contact DAO object + * @param boolean $restore true to set the is_delete = 1 else false to restore deleted contact, * i.e. is_delete = 0 * - * @return void + * @return void * @static */ public static function contactTrashRestore($contact, $restore = FALSE) { @@ -1132,7 +1136,7 @@ WHERE id={$id}; "; * */ public static function getContactTypes($id) { - $params = array('id' => $id); + $params = array('id' => $id); $details = array(); $contact = CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Contact', $params, @@ -1174,10 +1178,11 @@ WHERE id={$id}; "; * @return array array of importable Fields * @static */ - static function importableFields($contactType = 'Individual', - $status = FALSE, - $showAll = FALSE, - $isProfile = FALSE, + static function importableFields( + $contactType = 'Individual', + $status = FALSE, + $showAll = FALSE, + $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE ) { @@ -1203,7 +1208,11 @@ WHERE id={$id}; "; // get the fields thar are meant for contact types if (in_array($contactType, array( - 'Individual', 'Household', 'Organization', 'All'))) { + 'Individual', + 'Household', + 'Organization', + 'All' + ))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } @@ -1293,8 +1302,7 @@ WHERE id={$id}; "; } } else { - foreach (array( - 'Individual', 'Household', 'Organization') as $type) { + foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll, @@ -1395,12 +1403,7 @@ WHERE id={$id}; "; $fields = CRM_Contact_DAO_Contact::export(); // the fields are meant for contact types - if ( - in_array( - $contactType, - array('Individual', 'Household', 'Organization', 'All') - ) - ) { + if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } // add current employer for individuals @@ -1410,21 +1413,23 @@ WHERE id={$id}; "; 'name' => 'organization_name', 'title' => ts('Current Employer'), ), - )); + )); $locationType = array( 'location_type' => array( 'name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type'), - )); + ) + ); $IMProvider = array( 'im_provider' => array( 'name' => 'im_provider', 'where' => 'civicrm_im.provider_id', 'title' => ts('IM Provider'), - )); + ) + ); $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), @@ -1465,7 +1470,10 @@ WHERE id={$id}; "; } else { foreach (array( - 'Individual', 'Household', 'Organization') as $type) { + 'Individual', + 'Household', + 'Organization' + ) as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, TRUE, $withMultiRecord) ); @@ -1612,10 +1620,10 @@ WHERE id={$id}; "; // we dont know the contents of return properties, but we need the lower level ids of the contact // so add a few fields $returnProperties['first_name'] = - $returnProperties['organization_name'] = - $returnProperties['household_name'] = - $returnProperties['contact_type'] = - $returnProperties['contact_sub_type'] = 1; + $returnProperties['organization_name'] = + $returnProperties['household_name'] = + $returnProperties['contact_type'] = + $returnProperties['contact_sub_type'] = 1; return list($query, $options) = CRM_Contact_BAO_Query::apiQuery($params, $returnProperties, $options); } @@ -1635,7 +1643,7 @@ WHERE id={$id}; "; $returnProperties = array(); - $multipleFields = array('website' => 'url'); + $multipleFields = array('website' => 'url'); foreach ($fields as $name => $dontCare) { if (strpos($name, '-') !== FALSE) { list($fieldName, $id, $type) = CRM_Utils_System::explode('-', $name, 3); @@ -1659,7 +1667,12 @@ WHERE id={$id}; "; $returnProperties['location'][$locationTypeName]['location_type'] = $id; } if (in_array($fieldName, array( - 'phone', 'im', 'email', 'openid', 'phone_ext'))) { + 'phone', + 'im', + 'email', + 'openid', + 'phone_ext' + ))) { if ($type) { $returnProperties['location'][$locationTypeName][$fieldName . '-' . $type] = 1; } @@ -1701,12 +1714,12 @@ WHERE id={$id}; "; * @static */ public static function getPrimaryLocationType($contactId, $skipDefaultPriamry = FALSE, $block = NULL) { - if($block){ + if ($block) { $entityBlock = array('contact_id' => $contactId); - $blocks = CRM_Core_BAO_Location::getValues($entityBlock); - foreach($blocks[$block] as $key => $value){ - if (!empty($value['is_primary'])){ - $locationType = CRM_Utils_Array::value('location_type_id',$value); + $blocks = CRM_Core_BAO_Location::getValues($entityBlock); + foreach ($blocks[$block] as $key => $value) { + if (!empty($value['is_primary'])) { + $locationType = CRM_Utils_Array::value('location_type_id', $value); } } } @@ -1789,9 +1802,9 @@ ORDER BY civicrm_email.is_primary DESC"; else { $name = $dao->display_name; } - $email = $dao->email; + $email = $dao->email; $doNotEmail = $dao->do_not_email ? TRUE : FALSE; - $onHold = $dao->on_hold ? TRUE : FALSE; + $onHold = $dao->on_hold ? TRUE : FALSE; $isDeceased = $dao->is_deceased ? TRUE : FALSE; return array($name, $email, $doNotEmail, $onHold, $isDeceased); } @@ -1825,8 +1838,8 @@ ORDER BY civicrm_email.is_primary DESC"; $contactID = NULL, $addToGroupID = NULL, $ufGroupId = NULL, - $ctype = NULL, - $visibility = FALSE + $ctype = NULL, + $visibility = FALSE ) { // add ufGroupID to params array ( CRM-2012 ) if ($ufGroupId) { @@ -1846,8 +1859,8 @@ ORDER BY civicrm_email.is_primary DESC"; // manage is_opt_out if (array_key_exists('is_opt_out', $fields) && array_key_exists('is_opt_out', $params)) { - $wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, FALSE); - $isOptOut = CRM_Utils_Array::value('is_opt_out', $params, FALSE); + $wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, FALSE); + $isOptOut = CRM_Utils_Array::value('is_opt_out', $params, FALSE); $data['is_opt_out'] = $isOptOut; // on change, create new civicrm_subscription_history entry if (($wasOptOut != $isOptOut) && !empty($contactDetails['contact_id'])) { @@ -1964,13 +1977,13 @@ ORDER BY civicrm_email.is_primary DESC"; if (array_key_exists('contact_sub_type', $params) && !empty($params['contact_sub_type']) ) { - $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array)$params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR; + $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type']) . CRM_Core_DAO::VALUE_SEPARATOR; } elseif (array_key_exists('contact_sub_type_hidden', $params) && !empty($params['contact_sub_type_hidden']) ) { // if profile was used, and had any subtype, we obtain it from there - $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array)$params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR; + $data['contact_sub_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, (array) $params['contact_sub_type_hidden']) . CRM_Core_DAO::VALUE_SEPARATOR; } if ($ctype == 'Organization') { @@ -2021,10 +2034,10 @@ ORDER BY civicrm_email.is_primary DESC"; if ($locTypeId == 'Primary') { if ($contactID) { - if(in_array( $fieldName, $blocks)){ + if (in_array($fieldName, $blocks)) { $locTypeId = self::getPrimaryLocationType($contactID, FALSE, $fieldName); } - else{ + else { $locTypeId = self::getPrimaryLocationType($contactID, FALSE, 'address'); } $primaryLocationType = $locTypeId; @@ -2050,7 +2063,7 @@ ORDER BY civicrm_email.is_primary DESC"; $loc = CRM_Utils_Array::key($index, $locationType); - $blockName = in_array( $fieldName, $blocks) ? $fieldName : 'address'; + $blockName = in_array($fieldName, $blocks) ? $fieldName : 'address'; $data[$blockName][$loc]['location_type_id'] = $locTypeId; @@ -2069,7 +2082,7 @@ ORDER BY civicrm_email.is_primary DESC"; $data[$blockName][$loc]['is_primary'] = 1; } - if ( in_array($fieldName, array('phone'))) { + if (in_array($fieldName, array('phone'))) { if ($typeId) { $data['phone'][$loc]['phone_type_id'] = $typeId; } @@ -2171,7 +2184,8 @@ ORDER BY civicrm_email.is_primary DESC"; // if auth source is not checksum / login && $value is blank, do not proceed - CRM-10128 if (($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 && - ($value == '' || !isset($value))) { + ($value == '' || !isset($value)) + ) { continue; } @@ -2222,25 +2236,28 @@ ORDER BY civicrm_email.is_primary DESC"; } } } - 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']){ + foreach ($value as $cnt => $phoneBlock) { + if ($params[$key][$cnt]['location_type_id'] == $params['phone_ext'][$cnt]['location_type_id']) { $data[$key][$cnt]['phone_ext'] = CRM_Utils_Array::retrieveValueRecursive($params['phone_ext'][$cnt], 'phone_ext'); } } } else if (in_array($key, - array('nick_name', + array( + 'nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', - 'suffix_id')) && + 'suffix_id' + )) && ($value == '' || !isset($value)) && - ($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0) { + ($session->get('authSrc') & (CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN)) == 0 + ) { // 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; @@ -2291,8 +2308,8 @@ ORDER BY civicrm_email.is_primary DESC"; */ public static function &matchContactOnEmail($mail, $ctype = NULL) { $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; - $mail = $strtolower(trim($mail)); - $query = " + $mail = $strtolower(trim($mail)); + $query = " SELECT civicrm_contact.id as contact_id, civicrm_contact.hash as hash, civicrm_contact.contact_type as contact_type, @@ -2301,9 +2318,7 @@ FROM civicrm_contact INNER JOIN civicrm_email ON ( civicrm_contact.id = civicrm_email.contact_id )"; - if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, - 'uniq_email_per_site' - )) { + if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'uniq_email_per_site')) { // try to find a match within a site (multisite). $groups = CRM_Core_BAO_Domain::getChildGroupIds(); if (!empty($groups)) { @@ -2345,8 +2360,8 @@ WHERE civicrm_email.email = %1 AND civicrm_contact.is_deleted=0"; */ public static function &matchContactOnOpenId($openId, $ctype = NULL) { $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; - $openId = $strtolower(trim($openId)); - $query = " + $openId = $strtolower(trim($openId)); + $query = " SELECT civicrm_contact.id as contact_id, civicrm_contact.hash as hash, civicrm_contact.contact_type as contact_type, @@ -2470,9 +2485,11 @@ AND civicrm_openid.is_primary = 1"; $temp = array('preferred_communication_method' => $contact->preferred_communication_method); $names = array( - 'preferred_communication_method' => array('newName' => 'preferred_communication_method_display', + 'preferred_communication_method' => array( + 'newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method', - )); + ) + ); CRM_Core_OptionGroup::lookupValues($temp, $names, FALSE); @@ -2491,7 +2508,7 @@ AND civicrm_openid.is_primary = 1"; if ($contact->birth_date) { $birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d'); if ($birthDate < date('Ymd')) { - $age = CRM_Utils_Date::calculateAge($birthDate); + $age = CRM_Utils_Date::calculateAge($birthDate); $values['age']['y'] = CRM_Utils_Array::value('years', $age); $values['age']['m'] = CRM_Utils_Array::value('months', $age); } @@ -2615,7 +2632,7 @@ AND civicrm_openid.is_primary = 1"; // fields that are required to calculate greeting and // also other fields used in tokens etc, // hence we need to retrieve it again. - if ( $contact->_query !== FALSE ) { + if ($contact->_query !== FALSE) { $contact->find(TRUE); } @@ -2638,14 +2655,14 @@ AND civicrm_openid.is_primary = 1"; 'greeting_type' => 'email_greeting', ); - $emailGreeting = CRM_Core_PseudoConstant::greeting($filter); + $emailGreeting = CRM_Core_PseudoConstant::greeting($filter); $emailGreetingString = $emailGreeting[$contact->email_greeting_id]; $updateQueryString[] = " email_greeting_custom = NULL "; } else { if ($useDefaults) { reset($contactDefaults['email_greeting']); - $emailGreetingID = key($contactDefaults['email_greeting']); + $emailGreetingID = key($contactDefaults['email_greeting']); $emailGreetingString = $contactDefaults['email_greeting'][$emailGreetingID]; $updateQueryString[] = " email_greeting_id = $emailGreetingID "; $updateQueryString[] = " email_greeting_custom = NULL "; @@ -2711,15 +2728,15 @@ AND civicrm_openid.is_primary = 1"; 'greeting_type' => 'addressee', ); - $addressee = CRM_Core_PseudoConstant::greeting($filter); - $addresseeString = $addressee[$contact->addressee_id]; + $addressee = CRM_Core_PseudoConstant::greeting($filter); + $addresseeString = $addressee[$contact->addressee_id]; $updateQueryString[] = " addressee_custom = NULL "; } else { if ($useDefaults) { reset($contactDefaults['addressee']); - $addresseeID = key($contactDefaults['addressee']); - $addresseeString = $contactDefaults['addressee'][$addresseeID]; + $addresseeID = key($contactDefaults['addressee']); + $addresseeString = $contactDefaults['addressee'][$addresseeID]; $updateQueryString[] = " addressee_id = $addresseeID "; $updateQueryString[] = " addressee_custom = NULL "; } @@ -2975,8 +2992,13 @@ AND civicrm_openid.is_primary = 1"; //3. edit and view contact are directly accessible to user. $aclPermissionedTasks = array( - 'view-contact', 'edit-contact', 'new-activity', - 'new-email', 'group-add-contact', 'tag-contact', 'delete-contact', + 'view-contact', + 'edit-contact', + 'new-activity', + 'new-email', + 'group-add-contact', + 'tag-contact', + 'delete-contact', ); $corePermission = CRM_Core_Permission::getPermission(); @@ -3020,7 +3042,8 @@ AND civicrm_openid.is_primary = 1"; $hasAllPermissions = TRUE; } elseif (in_array($values['ref'], array( - 'new-email'))) { + 'new-email' + ))) { // grant permissions for these tasks. $hasAllPermissions = TRUE; } @@ -3034,7 +3057,9 @@ AND civicrm_openid.is_primary = 1"; // build directly accessible action menu. if (in_array($values['ref'], array( - 'view-contact', 'edit-contact'))) { + 'view-contact', + 'edit-contact' + ))) { $contextMenu['primaryActions'][$key] = array( 'title' => $values['title'], 'ref' => $values['ref'], @@ -3245,11 +3270,12 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id ) public static function checkDomainContact($contactId) { if (!$contactId) return FALSE; - $domainId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', $contactId, 'id', 'contact_id'); + $domainId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', $contactId, 'id', 'contact_id'); if ($domainId) { return TRUE; - } else { + } + else { return FALSE; } }