/**
* @return array|NULL
* NULL if execution should proceed; array if the response is already known
*/
public function loadCMSBootstrap()
{
$requestParams = CRM_Utils_Request::exportValues();
$q = CRM_Utils_array::value('q', $requestParams);
$args = explode('/', $q);
// Proceed with bootstrap for "?entity=X&action=Y"
// Proceed with bootstrap for "?q=civicrm/X/Y" but not "?q=civicrm/ping"
if (!empty($q)) {
if (count($args) == 2 && $args[1] == 'ping') {
return NULL;
// this is pretty wonky but maybe there's some reason I can't see
}
if (count($args) != 3) {
return self::error('ERROR: Malformed REST path');
}
if ($args[0] != 'civicrm') {
return self::error('ERROR: Malformed REST path');
}
// Therefore we have reasonably well-formed "?q=civicrm/X/Y"
}
if (!CRM_Utils_System::authenticateKey(FALSE)) {
// FIXME: At time of writing, this doesn't actually do anything because
// authenticateKey abends, but that's a bad behavior which sends a
// malformed response.
return self::error('Failed to authenticate key');
}
$uid = NULL;
if (!$uid) {
$store = NULL;
$api_key = CRM_Utils_Request::retrieve('api_key', 'String', $store, FALSE, NULL, 'REQUEST');
if (empty($api_key)) {
return self::error("FATAL: mandatory param 'api_key' (user key) missing");
}
$contact_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $api_key, 'id', 'api_key');
if ($contact_id) {
$uid = CRM_Core_BAO_UFMatch::getUFId($contact_id);
}
}
if ($uid) {
CRM_Utils_System::loadBootStrap(array('uid' => $uid), TRUE, FALSE);
return NULL;
} else {
return self::error('ERROR: No CMS user associated with given api-key');
}
}
开发者ID:kidaa30,项目名称:yes,代码行数:49,代码来源:REST.php
示例5: assignAddressField
/**
* Add fields to $profileAddressFields as appropriate.
* profileAddressFields is assigned to the template to tell it
* what fields are in the profile address
* that potentially should be copied to the Billing fields
* we want to give precedence to
* 1) Billing &
* 2) then Primary designated as 'Primary
* 3) location_type is primary
* 4) if none of these apply then it just uses the first one
*
* as this will be used to
* transfer profile address data to billing fields
* http://issues.civicrm.org/jira/browse/CRM-5869
*
* @param string $key
* Field key - e.g. street_address-Primary, first_name.
* @param array $profileAddressFields
* Array of profile fields that relate to address fields.
* @param array $profileFilter
* Filter to apply to profile fields - expected usage is to only fill based on.
* the bottom profile per CRM-13726
*
* @return bool
* Can the address block be hidden safe in the knowledge all fields are elsewhere collected (see CRM-15118)
*/
public static function assignAddressField($key, &$profileAddressFields, $profileFilter)
{
$billing_id = CRM_Core_BAO_LocationType::getBilling();
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
$profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name, is_required', 'options' => array('limit' => 0))));
//check for valid fields ( fields that are present in billing block )
$validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country');
$requiredBillingFields = array_diff($validBillingFields, array('middle_name', 'supplemental_address_1'));
$validProfileFields = array();
$requiredProfileFields = array();
foreach ($profileFields['values'] as $field) {
if (in_array($field['field_name'], $validBillingFields)) {
$validProfileFields[] = $field['field_name'];
}
if ($field['is_required']) {
$requiredProfileFields[] = $field['field_name'];
}
}
if (!in_array($prefixName, $validProfileFields)) {
return FALSE;
}
if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) {
$profileAddressFields[$prefixName] = $index;
}
$potentiallyMissingRequiredFields = array_diff($requiredBillingFields, $requiredProfileFields);
CRM_Core_Resources::singleton()->addSetting(array('billing' => array('billingProfileIsHideable' => empty($potentiallyMissingRequiredFields))));
}
开发者ID:kidaa30,项目名称:yes,代码行数:53,代码来源:UFField.php
示例6: postProcess
//.........这里部分代码省略.........
$this->endPostProcess($newActParams, $activity);
}
// copy files attached to old activity if any, to new one,
// as long as users have not selected the 'delete attachment' option.
if (empty($newActParams['is_delete_attachment'])) {
CRM_Core_BAO_File::copyEntityFile('civicrm_activity', $this->_activityId, 'civicrm_activity', $activity->id);
}
// copy back params to original var
$params = $newActParams;
}
foreach ($vvalue as $vkey => $vval) {
if ($vval['actId']) {
// add tags if exists
$tagParams = array();
if (!empty($params['tag'])) {
foreach ($params['tag'] as $tag) {
$tagParams[$tag] = 1;
}
}
//save static tags
CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $vval['actId']);
//save free tags
if (isset($params['taglist']) && !empty($params['taglist'])) {
CRM_Core_Form_Tag::postProcess($params['taglist'], $vval['actId'], 'civicrm_activity', $this);
}
}
// update existing case record if needed
$caseParams = $params;
$caseParams['id'] = $vval['case_id'];
if (!empty($caseParams['case_status_id'])) {
$caseParams['status_id'] = $caseParams['case_status_id'];
}
// unset params intended for activities only
unset($caseParams['subject'], $caseParams['details'], $caseParams['status_id'], $caseParams['custom']);
$case = CRM_Case_BAO_Case::create($caseParams);
// create case activity record
$caseParams = array('activity_id' => $vval['actId'], 'case_id' => $vval['case_id']);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
}
// Insert civicrm_log record for the activity (e.g. store the
// created / edited by contact id and date for the activity)
// Note - civicrm_log is already created by CRM_Activity_BAO_Activity::create()
// send copy to selected contacts.
$mailStatus = '';
$mailToContacts = array();
//CRM-5695
//check for notification settings for assignee contacts
$selectedContacts = array('contact_check');
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) {
$selectedContacts[] = 'assignee_contact_id';
}
foreach ($vvalue as $vkey => $vval) {
foreach ($selectedContacts as $dnt => $val) {
if (array_key_exists($val, $params) && !CRM_Utils_array::crmIsEmptyArray($params[$val])) {
if ($val == 'contact_check') {
$mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
} else {
$this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($vval['actId']), TRUE, FALSE);
$mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s).");
}
//build an associative array with unique email addresses.
foreach ($params[$val] as $key => $value) {
if ($val == 'contact_check') {
$id = $key;
} else {
$id = $value;
}
if (isset($id) && array_key_exists($id, $this->_relatedContacts) && isset($this->_relatedContacts[$id]['email'])) {
//if email already exists in array then append with ', ' another role only otherwise add it to array.
if ($contactDetails = CRM_Utils_Array::value($this->_relatedContacts[$id]['email'], $mailToContacts)) {
$caseRole = CRM_Utils_Array::value('role', $this->_relatedContacts[$id]);
$mailToContacts[$this->_relatedContacts[$id]['email']]['role'] = $contactDetails['role'] . ', ' . $caseRole;
} else {
$mailToContacts[$this->_relatedContacts[$id]['email']] = $this->_relatedContacts[$id];
}
}
}
}
}
$extraParams = array('case_id' => $vval['case_id'], 'client_id' => $this->_currentlyViewedContactId);
$result = CRM_Activity_BAO_Activity::sendToAssignee($activity, $mailToContacts, $extraParams);
if (empty($result)) {
$mailStatus = '';
}
// create follow up activity if needed
$followupStatus = '';
if (!empty($params['followup_activity_type_id'])) {
$followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($vval['actId'], $params);
if ($followupActivity) {
$caseParams = array('activity_id' => $followupActivity->id, 'case_id' => $vval['case_id']);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
$followupStatus = ts("A followup activity has been scheduled.") . '<br /><br />';
}
}
$title = ts("%1 Saved", array(1 => $this->_activityTypeName));
CRM_Core_Session::setStatus($followupStatus . $mailStatus, $title, 'success');
}
}
//.........这里部分代码省略.........
}
}
}
// **** Do file custom fields related migrations
// FIXME: move this someplace else (one of the BAOs) after discussing
// where to, and whether CRM_Core_BAO_File::deleteFileReferences() shouldn't actually,
// like, delete a file...
if (!isset($customFiles)) {
$customFiles = array();
}
foreach ($customFiles as $customId) {
list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($customId);
// get the contact_id -> file_id mapping
$fileIds = array();
$sql = "SELECT entity_id, {$columnName} AS file_id FROM {$tableName} WHERE entity_id IN ({$mainId}, {$otherId})";
$dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
while ($dao->fetch()) {
$fileIds[$dao->entity_id] = $dao->file_id;
}
$dao->free();
// delete the main contact's file
if (!empty($fileIds[$mainId])) {
CRM_Core_BAO_File::deleteFileReferences($fileIds[$mainId], $mainId, $customId);
}
// move the other contact's file to main contact
//NYSS need to INSERT or UPDATE depending on whether main contact has an existing record
if (CRM_Core_DAO::singleValueQuery("SELECT id FROM {$tableName} WHERE entity_id = {$mainId}")) {
$sql = "UPDATE {$tableName} SET {$columnName} = {$fileIds[$otherId]} WHERE entity_id = {$mainId}";
} else {
$sql = "INSERT INTO {$tableName} ( entity_id, {$columnName} ) VALUES ( {$mainId}, {$fileIds[$otherId]} )";
}
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
if (CRM_Core_DAO::singleValueQuery("\n SELECT id\n FROM civicrm_entity_file\n WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}")) {
$sql = "\n UPDATE civicrm_entity_file\n SET entity_id = {$mainId}\n WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}";
} else {
$sql = "\n INSERT INTO civicrm_entity_file ( entity_table, entity_id, file_id )\n VALUES ( '{$tableName}', {$mainId}, {$fileIds[$otherId]} )";
}
CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
}
// move view only custom fields CRM-5362
$viewOnlyCustomFields = array();
foreach ($submitted as $key => $value) {
$fid = (int) substr($key, 7);
if (array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])) {
$viewOnlyCustomFields[$key] = $value;
}
}
// special case to set values for view only, CRM-5362
if (!empty($viewOnlyCustomFields)) {
$viewOnlyCustomFields['entityID'] = $mainId;
CRM_Core_BAO_CustomValueTable::setValues($viewOnlyCustomFields);
}
// **** Delete other contact & update prev-next caching
$otherParams = array('contact_id' => $otherId, 'id' => $otherId, 'version' => 3);
if (CRM_Core_Permission::check('merge duplicate contacts') && CRM_Core_Permission::check('delete contacts')) {
// if ext id is submitted then set it null for contact to be deleted
if (!empty($submitted['external_identifier'])) {
$query = "UPDATE civicrm_contact SET external_identifier = null WHERE id = {$otherId}";
CRM_Core_DAO::executeQuery($query);
}
civicrm_api('contact', 'delete', $otherParams);
CRM_Core_BAO_PrevNextCache::deleteItem($otherId);
}
// FIXME: else part
/* else { */
/* CRM_Core_Session::setStatus( ts('Do not have sufficient permission to delete duplicate contact.') ); */
/* } */
// CRM-15681 merge sub_types
if ($other_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['other_details'])) {
if ($main_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['main_details'])) {
$submitted['contact_sub_type'] = array_unique(array_merge($main_sub_types, $other_sub_types));
} else {
$submitted['contact_sub_type'] = $other_sub_types;
}
}
// **** Update contact related info for the main contact
if (!empty($submitted)) {
$submitted['contact_id'] = $mainId;
//update current employer field
if ($currentEmloyerId = CRM_Utils_Array::value('current_employer_id', $submitted)) {
if (!CRM_Utils_System::isNull($currentEmloyerId)) {
$submitted['current_employer'] = $submitted['current_employer_id'];
} else {
$submitted['current_employer'] = '';
}
unset($submitted['current_employer_id']);
}
//CRM-14312 include prefix/suffix from mainId if not overridden for proper construction of display/sort name
if (!isset($submitted['prefix_id']) && !empty($migrationInfo['main_details']['prefix_id'])) {
$submitted['prefix_id'] = $migrationInfo['main_details']['prefix_id'];
}
if (!isset($submitted['suffix_id']) && !empty($migrationInfo['main_details']['suffix_id'])) {
$submitted['suffix_id'] = $migrationInfo['main_details']['suffix_id'];
}
CRM_Contact_BAO_Contact::createProfileContact($submitted, CRM_Core_DAO::$_nullArray, $mainId);
unset($submitted);
}
CRM_Utils_Hook::post('merge', 'Contact', $mainId, CRM_Core_DAO::$_nullObject);
return TRUE;
}
/**
* Process activity creation.
*
* @param array $params
* Associated array of submitted values.
*
* @return self|null|object
*/
protected function processActivity(&$params)
{
$activityAssigned = array();
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
// format assignee params
if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
//skip those assignee contacts which are already assigned
//while sending a copy.CRM-4509.
$activityAssigned = array_flip($params['assignee_contact_id']);
if ($this->_activityId) {
$assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID);
$activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
}
}
// call begin post process. Idea is to let injecting file do
// any processing before the activity is added/updated.
$this->beginPostProcess($params);
$activity = CRM_Activity_BAO_Activity::create($params);
// add tags if exists
$tagParams = array();
if (!empty($params['tag'])) {
foreach ($params['tag'] as $tag) {
$tagParams[$tag] = 1;
}
}
//save static tags
CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id);
//save free tags
if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) {
CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this);
}
// call end post process. Idea is to let injecting file do any
// processing needed, after the activity has been added/updated.
$this->endPostProcess($params, $activity);
// CRM-9590
if (!empty($params['is_multi_activity'])) {
$this->_activityIds[] = $activity->id;
} else {
$this->_activityId = $activity->id;
}
// create follow up activity if needed
$followupStatus = '';
$followupActivity = NULL;
if (!empty($params['followup_activity_type_id'])) {
$followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
$followupStatus = ts('A followup activity has been scheduled.');
}
// send copy to assignee contacts.CRM-4509
$mailStatus = '';
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) {
$activityIDs = array($activity->id);
if ($followupActivity) {
$activityIDs = array_merge($activityIDs, array($followupActivity->id));
}
$assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE);
if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
$mailToContacts = array();
//build an associative array with unique email addresses.
foreach ($activityAssigned as $id => $dnc) {
if (isset($id) && array_key_exists($id, $assigneeContacts)) {
$mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id];
}
}
if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
//include attachments while sending a copy of activity.
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
$ics = new CRM_Activity_BAO_ICalendar($activity);
$ics->addAttachment($attachments, $mailToContacts);
// CRM-8400 add param with _currentlyViewedContactId for URL link in mail
CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL);
$ics->cleanup();
$mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
}
}
// Also send email to follow-up activity assignees if set
if ($followupActivity) {
$mailToFollowupContacts = array();
foreach ($assigneeContacts as $values) {
if ($values['activity_id'] == $followupActivity->id) {
$mailToFollowupContacts[$values['email']] = $values;
}
}
if (!CRM_Utils_array::crmIsEmptyArray($mailToFollowupContacts)) {
$ics = new CRM_Activity_BAO_ICalendar($followupActivity);
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $followupActivity->id);
$ics->addAttachment($attachments, $mailToFollowupContacts);
CRM_Case_BAO_Case::sendActivityCopy(NULL, $followupActivity->id, $mailToFollowupContacts, $attachments, NULL);
$ics->cleanup();
$mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s).");
}
}
//.........这里部分代码省略.........
//.........这里部分代码省略.........
$params['activity_type_id'] = $this->_activityTypeId;
}
if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) {
$customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId);
$customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE));
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity');
}
// store the date with proper format
$params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']);
// assigning formated value to related variable
if (CRM_Utils_Array::value('target_contact_id', $params)) {
$params['target_contact_id'] = explode(',', $params['target_contact_id']);
} else {
$params['target_contact_id'] = array();
}
if (CRM_Utils_Array::value('assignee_contact_id', $params)) {
$params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']);
} else {
$params['assignee_contact_id'] = array();
}
// get ids for associated contacts
if (!$params['source_contact_id']) {
$params['source_contact_id'] = $this->_currentUserId;
} else {
$params['source_contact_id'] = $this->_submitValues['source_contact_qid'];
}
if (isset($this->_activityId)) {
$params['id'] = $this->_activityId;
}
// add attachments as needed
CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId);
// format target params
if (!$this->_single) {
$params['target_contact_id'] = $this->_contactIds;
}
$activityAssigned = array();
// format assignee params
if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
//skip those assignee contacts which are already assigned
//while sending a copy.CRM-4509.
$activityAssigned = array_flip($params['assignee_contact_id']);
if ($this->_activityId) {
$assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId);
$activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
}
}
// call begin post process. Idea is to let injecting file do
// any processing before the activity is added/updated.
$this->beginPostProcess($params);
$activity = CRM_Activity_BAO_Activity::create($params);
// add tags if exists
$tagParams = array();
if (!empty($params['tag'])) {
foreach ($params['tag'] as $tag) {
$tagParams[$tag] = 1;
}
}
//save static tags
CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id);
//save free tags
if (isset($params['activity_taglist']) && !empty($params['activity_taglist'])) {
CRM_Core_Form_Tag::postProcess($params['activity_taglist'], $activity->id, 'civicrm_activity', $this);
}
// call end post process. Idea is to let injecting file do any
// processing needed, after the activity has been added/updated.
$this->endPostProcess($params, $activity);
// CRM-9590
$this->_activityId = $activity->id;
// create follow up activity if needed
$followupStatus = '';
if (CRM_Utils_Array::value('followup_activity_type_id', $params)) {
$followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
$followupStatus = ts('A followup activity has been scheduled.');
}
// send copy to assignee contacts.CRM-4509
$mailStatus = '';
if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'activity_assignee_notification')) {
$mailToContacts = array();
$assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
//build an associative array with unique email addresses.
foreach ($activityAssigned as $id => $dnc) {
if (isset($id) && array_key_exists($id, $assigneeContacts)) {
$mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id];
}
}
if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
//include attachments while sendig a copy of activity.
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
// CRM-8400 add param with _currentlyViewedContactId for URL link in mail
$result = CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL);
$mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
}
}
// set status message
if (CRM_Utils_Array::value('subject', $params)) {
$params['subject'] = "'" . $params['subject'] . "'";
}
CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus)));
return array('activity' => $activity);
}
/**
* Add fields to $profileAddressFields as appropriate.
* profileAddressFields is assigned to the template to tell it
* what fields are in the profile address
* that potentially should be copied to the Billing fields
* we want to give precedence to
* 1) Billing &
* 2) then Primary designated as 'Primary
* 3) location_type is primary
* 4) if none of these apply then it just uses the first one
*
* as this will be used to
* transfer profile address data to billing fields
* http://issues.civicrm.org/jira/browse/CRM-5869
* @param string $key Field key - e.g. street_address-Primary, first_name
* @params array $profileAddressFields array of profile fields that relate to address fields
*/
static function assignAddressField($key, &$profileAddressFields)
{
$billing_id = CRM_Core_BAO_LocationType::getBilling();
list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
//check for valid fields ( fields that are present in billing block )
$validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country');
if (!in_array($prefixName, $validBillingFields)) {
return;
}
if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) {
$profileAddressFields[$prefixName] = $index;
}
}
//.........这里部分代码省略.........
}
//validate for min and max.
if ($otherAmountVal) {
$min = CRM_Utils_Array::value('min_amount', $self->_values);
$max = CRM_Utils_Array::value('max_amount', $self->_values);
if ($min && $otherAmountVal < $min) {
$errors['amount_other'] = ts('Contribution amount must be at least %1', array(1 => $min));
}
if ($max && $otherAmountVal > $max) {
$errors['amount_other'] = ts('Contribution amount cannot be more than %1.', array(1 => $max));
}
}
}
}
// validate PCP fields - if not anonymous, we need a nick name value
if ($self->_pcpId && CRM_Utils_Array::value('pcp_display_in_roll', $fields) && CRM_Utils_Array::value('pcp_is_anonymous', $fields) == 0 && CRM_Utils_Array::value('pcp_roll_nickname', $fields) == '') {
$errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.');
}
// return if this is express mode
$config = CRM_Core_Config::singleton();
if ($self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
if (CRM_Utils_Array::value($self->_expressButtonName . '_x', $fields) || CRM_Utils_Array::value($self->_expressButtonName . '_y', $fields) || CRM_Utils_Array::value($self->_expressButtonName, $fields)) {
return $errors;
}
}
//validate the pledge fields.
if (CRM_Utils_Array::value('pledge_block_id', $self->_values)) {
//validation for pledge payment.
if (CRM_Utils_Array::value('pledge_id', $self->_values)) {
if (empty($fields['pledge_amount'])) {
$errors['pledge_amount'] = ts('At least one payment option needs to be checked.');
}
} else {
if (CRM_Utils_Array::value('is_pledge', $fields)) {
if (CRM_Utils_Rule::positiveInteger(CRM_Utils_Array::value('pledge_installments', $fields)) == false) {
$errors['pledge_installments'] = ts('Please enter a valid pledge installment.');
} else {
if (CRM_Utils_Array::value('pledge_installments', $fields) == null) {
$errors['pledge_installments'] = ts('Pledge Installments is required field.');
} else {
if (CRM_Utils_array::value('pledge_installments', $fields) == 1) {
$errors['pledge_installments'] = ts('Pledges consist of multiple scheduled payments. Select one-time contribution if you want to make your gift in a single payment.');
} else {
if (CRM_Utils_array::value('pledge_installments', $fields) == 0) {
$errors['pledge_installments'] = ts('Pledge Installments field must be > 1.');
}
}
}
}
//validation for Pledge Frequency Interval.
if (CRM_Utils_Rule::positiveInteger(CRM_Utils_Array::value('pledge_frequency_interval', $fields)) == false) {
$errors['pledge_frequency_interval'] = ts('Please enter a valid Pledge Frequency Interval.');
} else {
if (CRM_Utils_Array::value('pledge_frequency_interval', $fields) == null) {
$errors['pledge_frequency_interval'] = ts('Pledge Frequency Interval. is required field.');
} else {
if (CRM_Utils_array::value('pledge_frequency_interval', $fields) == 0) {
$errors['pledge_frequency_interval'] = ts('Pledge frequency interval field must be > 0');
}
}
}
}
}
}
// also return if paylater mode
if (CRM_Utils_Array::value('is_pay_later', $fields)) {
return empty($errors) ? true : $errors;
}
// if the user has chosen a free membership or the amount is less than zero
// i.e. we skip calling the payment processor and hence dont need credit card
// info
if ((double) $amount <= 0.0) {
return $errors;
}
foreach ($self->_fields as $name => $fld) {
if ($fld['is_required'] && CRM_Utils_System::isNull(CRM_Utils_Array::value($name, $fields))) {
$errors[$name] = ts('%1 is a required field.', array(1 => $fld['title']));
}
}
// make sure that credit card number and cvv are valid
require_once 'CRM/Utils/Rule.php';
if (CRM_Utils_Array::value('credit_card_type', $fields)) {
if (CRM_Utils_Array::value('credit_card_number', $fields) && !CRM_Utils_Rule::creditCardNumber($fields['credit_card_number'], $fields['credit_card_type'])) {
$errors['credit_card_number'] = ts('Please enter a valid Credit Card Number');
}
if (CRM_Utils_Array::value('cvv2', $fields) && !CRM_Utils_Rule::cvv($fields['cvv2'], $fields['credit_card_type'])) {
$errors['cvv2'] = ts('Please enter a valid Credit Card Verification Number');
}
}
$elements = array('email_greeting' => 'email_greeting_custom', 'postal_greeting' => 'postal_greeting_custom', 'addressee' => 'addressee_custom');
foreach ($elements as $greeting => $customizedGreeting) {
if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
$customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
if ($customizedValue == $greetingType && !CRM_Utils_Array::value($customizedGreeting, $fields)) {
$errors[$customizedGreeting] = ts('Custom %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', " ", $greeting))));
}
}
}
return empty($errors) ? true : $errors;
}
请发表评论