本文整理汇总了PHP中_civicrm_api3_custom_format_params函数的典型用法代码示例。如果您正苦于以下问题:PHP _civicrm_api3_custom_format_params函数的具体用法?PHP _civicrm_api3_custom_format_params怎么用?PHP _civicrm_api3_custom_format_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_civicrm_api3_custom_format_params函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_grant_create
/**
* create/update grant
*
* This API is used to create new grant or update any of the existing
* In case of updating existing grant, id of that particular grant must
* be in $params array.
*
* @param array $params Associative array of property
* name/value pairs to insert in new 'grant'
*
* @return array grant array
* {@getfields grant_create}
* @access public
*/
function civicrm_api3_grant_create($params)
{
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Grant');
$params = array_merge($values, $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'grant');
}
示例2: civicrm_api3_contribution_create
/**
* Add or update a Contribution.
*
* @param array $params
* Input parameters.
*
* @throws API_Exception
* @return array
* Api result array
*/
function civicrm_api3_contribution_create(&$params)
{
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Contribution');
$params = array_merge($params, $values);
if (!empty($params['id']) && !empty($params['contribution_status_id'])) {
$error = array();
//throw error for invalid status change such as setting completed back to pending
//@todo this sort of validation belongs in the BAO not the API - if it is not an OK
// action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api
CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error);
if (array_key_exists('contribution_status_id', $error)) {
throw new API_Exception($error['contribution_status_id']);
}
}
if (!empty($params['id']) && !empty($params['financial_type_id'])) {
$error = array();
CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error);
if (array_key_exists('financial_type_id', $error)) {
throw new API_Exception($error['financial_type_id']);
}
}
_civicrm_api3_contribution_create_legacy_support_45($params);
// Make sure tax calculation is handled via api.
$params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution');
}
示例3: civicrm_api3_pledge_create
/**
* Creates or updates an Activity. See the example for usage
*
* @param array $params Associative array of property name/value
* pairs for the activity.
* {@getfields pledge_create}
*
* @return array Array containing 'is_error' to denote success or failure and details of the created pledge
*
* @example PledgeCreate.php Standard create example
*
*/
function civicrm_api3_pledge_create($params)
{
_civicrm_api3_pledge_format_params($params, TRUE);
$values = $params;
//format the custom fields
_civicrm_api3_custom_format_params($params, $values, 'Pledge');
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $values);
}
示例4: civicrm_api3_membership_create
/**
* Create a Contact Membership.
*
* This API is used for creating a Membership for a contact.
* Required parameters : membership_type_id and status_id.
*
* @param array $params
* Array of name/value property values of civicrm_membership.
*
* @return array
* API result array.
*/
function civicrm_api3_membership_create($params)
{
// check params for membership id during update
if (!empty($params['id']) && !isset($params['skipStatusCal'])) {
// Don't calculate status on existing membership - expect API use to pass them in
// or leave unchanged.
$params['skipStatusCal'] = 1;
} else {
// also check for status id if override is set (during add/update)
if (!empty($params['is_override']) && empty($params['status_id'])) {
return civicrm_api3_create_error('Status ID required');
}
}
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Membership');
$params = array_merge($params, $values);
// Fixme: This code belongs in the BAO
if (empty($params['id']) || !empty($params['num_terms'])) {
if (empty($params['id'])) {
$calcDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($params['membership_type_id'], CRM_Utils_Array::value('join_date', $params), CRM_Utils_Array::value('start_date', $params), CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('num_terms', $params, 1));
} else {
$calcDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($params['id'], NULL, CRM_Utils_Array::value('membership_type_id', $params), $params['num_terms']);
}
foreach (array('join_date', 'start_date', 'end_date') as $date) {
if (empty($params[$date]) && isset($calcDates[$date])) {
$params[$date] = $calcDates[$date];
}
}
}
// Fixme: This code belongs in the BAO
$action = CRM_Core_Action::ADD;
// we need user id during add mode
$ids = array();
if (!empty($params['contact_id'])) {
$ids['userId'] = $params['contact_id'];
}
//for edit membership id should be present
if (!empty($params['id'])) {
$ids['membership'] = $params['id'];
$action = CRM_Core_Action::UPDATE;
}
//need to pass action to handle related memberships.
$params['action'] = $action;
if (empty($params['line_item']) && !empty($params['membership_type_id'])) {
CRM_Price_BAO_LineItem::getLineItemArray($params, NULL, 'membership', $params['membership_type_id']);
}
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
if (array_key_exists('is_error', $membershipBAO)) {
// In case of no valid status for given dates, $membershipBAO
// is going to contain 'is_error' => "Error Message"
return civicrm_api3_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
}
$membership = array();
_civicrm_api3_object_to_array($membershipBAO, $membership[$membershipBAO->id]);
return civicrm_api3_create_success($membership, $params, 'Membership', 'create', $membershipBAO);
}
示例5: civicrm_api3_event_create
/**
* Create a Event
*
* This API is used for creating a Event
*
* @param array $params input parameters
* Allowed @params array keys are:
* {@getfields event_create}
*
* @return array API result Array.
* @access public
*/
function civicrm_api3_event_create($params)
{
_civicrm_api3_event_create_legacy_support_42($params);
//format custom fields so they can be added
$value = array();
_civicrm_api3_custom_format_params($params, $values, 'Event');
$params = array_merge($values, $params);
require_once 'CRM/Event/BAO/Event.php';
$eventBAO = CRM_Event_BAO_Event::create($params);
$event = array();
_civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id]);
return civicrm_api3_create_success($event, $params);
}
示例6: civicrm_api3_participant_create
/**
* Create an Event Participant.
*
* @param array $params
* An associative array of name/value property values of civicrm_participant.
*
* @return array
* API result array
*/
function civicrm_api3_participant_create($params)
{
// Check that event id is not an template - should be done @ BAO layer.
if (!empty($params['event_id'])) {
$isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template');
if (!empty($isTemplate)) {
return civicrm_api3_create_error(ts('Event templates are not meant to be registered.'));
}
}
$values = $participant = array();
_civicrm_api3_custom_format_params($params, $values, 'Participant');
$params = array_merge($values, $params);
$participantBAO = CRM_Event_BAO_Participant::create($params);
if (empty($params['price_set_id']) && empty($params['id']) && !empty($params['fee_level'])) {
_civicrm_api3_participant_createlineitem($params, $participantBAO);
}
_civicrm_api3_object_to_array($participantBAO, $participant[$participantBAO->id]);
return civicrm_api3_create_success($participant, $params, 'Participant', 'create', $participantBAO);
}
示例7: civicrm_api3_contact_create
/**
* Create or update a Contact.
*
* @param array $params
* Input parameters.
*
* @throws API_Exception
*
* @return array
* API Result Array
*/
function civicrm_api3_contact_create($params)
{
$contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params));
if ($contactID && !empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::EDIT)) {
throw new \Civi\API\Exception\UnauthorizedException('Permission denied to modify contact record');
}
$dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE);
$values = _civicrm_api3_contact_check_params($params, $dupeCheck);
if ($values) {
return $values;
}
if (!$contactID) {
// If we get here, we're ready to create a new contact
if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) {
$defLocType = CRM_Core_BAO_LocationType::getDefault();
$params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1));
}
}
if (!empty($params['home_url'])) {
$websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
$params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $params['home_url']));
}
_civicrm_api3_greeting_format_params($params);
$values = array();
if (empty($params['contact_type']) && $contactID) {
$params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($contactID);
}
if (!isset($params['contact_sub_type']) && $contactID) {
$params['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($contactID);
}
_civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $contactID);
$params = array_merge($params, $values);
//@todo we should just call basic_create here - but need to make contact:create accept 'id' on the bao
$contact = _civicrm_api3_contact_update($params, $contactID);
if (is_a($contact, 'CRM_Core_Error')) {
throw new API_Exception($contact->_errors[0]['message']);
} else {
$values = array();
_civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id]);
}
return civicrm_api3_create_success($values, $params, 'Contact', 'create');
}
示例8: civicrm_api3_contribution_create
/**
* Add or update a Contribution.
*
* @param array $params
* Input parameters.
*
* @throws API_Exception
* @return array
* Api result array
*/
function civicrm_api3_contribution_create(&$params)
{
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Contribution');
$params = array_merge($params, $values);
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
if (empty($params['id'])) {
$op = CRM_Core_Action::ADD;
} else {
if (empty($params['financial_type_id'])) {
$params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['id'], 'financial_type_id');
}
$op = CRM_Core_Action::UPDATE;
}
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op);
if (!in_array($params['financial_type_id'], array_keys($types))) {
return civicrm_api3_create_error('You do not have permission to create this contribution');
}
}
if (!empty($params['id']) && !empty($params['contribution_status_id'])) {
$error = array();
//throw error for invalid status change such as setting completed back to pending
//@todo this sort of validation belongs in the BAO not the API - if it is not an OK
// action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api
CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error);
if (array_key_exists('contribution_status_id', $error)) {
throw new API_Exception($error['contribution_status_id']);
}
}
if (!empty($params['id']) && !empty($params['financial_type_id'])) {
$error = array();
CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error);
if (array_key_exists('financial_type_id', $error)) {
throw new API_Exception($error['financial_type_id']);
}
}
_civicrm_api3_contribution_create_legacy_support_45($params);
// Make sure tax calculation is handled via api.
// @todo this belongs in the BAO NOT the api.
$params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution');
}
示例9: civicrm_api3_grant_create
/**
* create/update grant
*
* This API is used to create new grant or update any of the existing
* In case of updating existing grant, id of that particular grant must
* be in $params array.
*
* @param array $params Associative array of property
* name/value pairs to insert in new 'grant'
*
* @return array grant array
* {@getfields grant_create}
* @access public
*/
function civicrm_api3_grant_create($params)
{
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Grant');
$params = array_merge($values, $params);
// BAO is non standard to we need to construct $ids array. Ideally we would fix BAO to accept $params without
// id for standardisation
$ids = array();
if (CRM_Utils_Array::value('id', $params)) {
$ids['grant'] = $params['id'];
}
$bao = CRM_GRANT_BAO_GRANT::create($params, $ids);
if (is_null($bao)) {
return civicrm_api3_create_error('Grant not created ');
} else {
$values = array();
_civicrm_api3_object_to_array($bao, $values[$bao->id]);
return civicrm_api3_create_success($values, $params, $bao, 'create');
}
}
示例10: civicrm_api3_contribution_create
/**
* Add or update a contribution
*
* @param array $params (reference ) input parameters
*
* @return array Api result array
* @static void
* @access public
* @example ContributionCreate.php
* {@getfields Contribution_create}
*/
function civicrm_api3_contribution_create(&$params)
{
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Contribution');
$params = array_merge($params, $values);
//legacy soft credit handling - recommended approach is chaining
if (!empty($params['soft_credit_to'])) {
$params['soft_credit'] = array(array('contact_id' => $params['soft_credit_to'], 'amount' => $params['total_amount']));
}
if (CRM_Utils_Array::value('id', $params) && CRM_Utils_Array::value('contribution_status_id', $params)) {
$error = array();
//throw error for invalid status change such as setting completed back to pending
//@todo this sort of validation belongs in the BAO not the API - if it is not an OK
// action it needs to be blocked there. If it is Ok through a form it needs to be OK through the api
CRM_Contribute_BAO_Contribution::checkStatusValidation(NULL, $params, $error);
if (array_key_exists('contribution_status_id', $error)) {
throw new API_Exception($error['contribution_status_id']);
}
}
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Contribution');
}
示例11: civicrm_api3_event_create
/**
* Create a Event
*
* This API is used for creating a Event
*
* @param array $params input parameters
* Allowed @params array keys are:
* {@getfields event_create}
*
* @return array API result Array.
* @access public
*/
function civicrm_api3_event_create($params)
{
civicrm_api3_verify_one_mandatory($params, NULL, array('event_type_id', 'template_id'));
// Clone event from template
if (!empty($params['template_id']) && empty($params['id'])) {
$copy = CRM_Event_BAO_Event::copy($params['template_id']);
$params['id'] = $copy->id;
unset($params['template_id']);
if (empty($params['is_template'])) {
$params['is_template'] = 0;
}
}
_civicrm_api3_event_create_legacy_support_42($params);
//format custom fields so they can be added
$values = array();
_civicrm_api3_custom_format_params($params, $values, 'Event');
$params = array_merge($values, $params);
$eventBAO = CRM_Event_BAO_Event::create($params);
$event = array();
_civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id]);
return civicrm_api3_create_success($event, $params);
}
示例12: civicrm_api3_participant_create
/**
* Create an Event Participant
*
* This API is used for creating a participants in an event.
* Required parameters : event_id AND contact_id for new creation
* : participant as name/value with participantid for edit
*
* @param array $params an associative array of name/value property values of civicrm_participant
*
* @return array apiresult
* {@getfields participant_create}
* @access public
*/
function civicrm_api3_participant_create($params)
{
//check that event id is not an template
// note that check duplicate check was removed as it wasn't actually being called.
//check contact exists removed as belongs @ wrapper layer
if (CRM_Utils_Array::value('event_id', $params)) {
$isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template');
if (!empty($isTemplate)) {
return civicrm_api3_create_error(ts('Event templates are not meant to be registered'));
}
}
$value = array();
_civicrm_api3_custom_format_params($params, $values, 'Participant');
$params = array_merge($values, $params);
require_once 'CRM/Event/BAO/Participant.php';
$participantBAO = CRM_Event_BAO_Participant::create($params);
if (empty($params['price_set_id']) && empty($params['id']) && CRM_Utils_Array::value('fee_level', $params)) {
_civicrm_api3_participant_createlineitem($params, $participantBAO);
}
_civicrm_api3_object_to_array($participantBAO, $participant[$participantBAO->id]);
return civicrm_api3_create_success($participant, $params, 'participant', 'create', $participantBAO);
}
示例13: membership_format_params
//.........这里部分代码省略.........
{
require_once 'api/v3/utils.php';
$fields = CRM_Member_DAO_Membership::fields();
_civicrm_api3_store_values($fields, $params, $values);
$customFields = CRM_Core_BAO_CustomField::getFields('Membership');
foreach ($params as $key => $value) {
// ignore empty values or empty arrays etc
if (CRM_Utils_System::isNull($value)) {
continue;
}
//Handling Custom Data
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
$values[$key] = $value;
$type = $customFields[$customFieldID]['html_type'];
if ($type == 'CheckBox' || $type == 'Multi-Select' || $type == 'AdvMulti-Select') {
$mulValues = explode(',', $value);
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true);
$values[$key] = array();
foreach ($mulValues as $v1) {
foreach ($customOption as $customValueID => $customLabel) {
$customValue = $customLabel['value'];
if (strtolower($customLabel['label']) == strtolower(trim($v1)) || strtolower($customValue) == strtolower(trim($v1))) {
if ($type == 'CheckBox') {
$values[$key][$customValue] = 1;
} else {
$values[$key][] = $customValue;
}
}
}
}
}
}
switch ($key) {
case 'membership_contact_id':
if (!CRM_Utils_Rule::integer($value)) {
throw new Exception("contact_id not valid: {$value}");
}
$dao = new CRM_Core_DAO();
$qParams = array();
$svq = $dao->singleValueQuery("SELECT id FROM civicrm_contact WHERE id = {$value}", $qParams);
if (!$svq) {
throw new Exception("Invalid Contact ID: There is no contact record with contact_id = {$value}.");
}
$values['contact_id'] = $values['membership_contact_id'];
unset($values['membership_contact_id']);
break;
case 'membership_type_id':
if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipType())) {
throw new Exception('Invalid Membership Type Id');
}
$values[$key] = $value;
break;
case 'membership_type':
$membershipTypeId = CRM_Utils_Array::key(ucfirst($value), CRM_Member_PseudoConstant::membershipType());
if ($membershipTypeId) {
if (CRM_Utils_Array::value('membership_type_id', $values) && $membershipTypeId != $values['membership_type_id']) {
throw new Exception('Mismatched membership Type and Membership Type Id');
}
} else {
throw new Exception('Invalid Membership Type');
}
$values['membership_type_id'] = $membershipTypeId;
break;
case 'status_id':
if (!CRM_Utils_Array::value($value, CRM_Member_PseudoConstant::membershipStatus())) {
throw new Exception('Invalid Membership Status Id');
}
$values[$key] = $value;
break;
case 'membership_status':
$membershipStatusId = CRM_Utils_Array::key(ucfirst($value), CRM_Member_PseudoConstant::membershipStatus());
if ($membershipStatusId) {
if (CRM_Utils_Array::value('status_id', $values) && $membershipStatusId != $values['status_id']) {
throw new Exception('Mismatched membership Status and Membership Status Id');
}
} else {
throw new Exception('Invalid Membership Status');
}
$values['status_id'] = $membershipStatusId;
break;
default:
break;
}
}
_civicrm_api3_custom_format_params($params, $values, 'Membership');
if ($create) {
// CRM_Member_BAO_Membership::create() handles membership_start_date,
// membership_end_date and membership_source. So, if $values contains
// membership_start_date, membership_end_date or membership_source,
// convert it to start_date, end_date or source
$changes = array('membership_start_date' => 'start_date', 'membership_end_date' => 'end_date', 'membership_source' => 'source');
foreach ($changes as $orgVal => $changeVal) {
if (isset($values[$orgVal])) {
$values[$changeVal] = $values[$orgVal];
unset($values[$orgVal]);
}
}
}
return NULL;
}
示例14: civicrm_api3_membership_create
/**
* Create a Contact Membership
*
* This API is used for creating a Membership for a contact.
* Required parameters : membership_type_id and status_id.
*
* @param array $params an associative array of name/value property values of civicrm_membership
*
* @return array of newly created membership property values.
* {@getfields membership_create}
* @access public
*/
function civicrm_api3_membership_create($params)
{
// @todo shouldn't be required - should be handling by api.aliases & api.required in _spec
civicrm_api3_verify_one_mandatory($params, NULL, array('membership_type_id', 'membership_type'));
// check params for membership id during update
if (CRM_Utils_Array::value('id', $params) && !isset($params['skipStatusCal'])) {
//don't calculate dates on exisiting membership - expect API use to pass them in
// or leave unchanged
$params['skipStatusCal'] = 1;
} else {
// also check for status id if override is set (during add/update)
if (isset($params['is_override']) && !CRM_Utils_Array::value('status_id', $params)) {
return civicrm_api3_create_error('Status ID required');
}
}
$values = array();
$error = _civicrm_api3_membership_format_params($params, $values);
if (civicrm_error($error)) {
return $error;
}
_civicrm_api3_custom_format_params($params, $values, 'Membership');
$params = array_merge($params, $values);
$action = CRM_Core_Action::ADD;
// we need user id during add mode
$ids = array();
if (CRM_Utils_Array::value('contact_id', $params)) {
$ids['userId'] = $params['contact_id'];
}
//for edit membership id should be present
if (CRM_Utils_Array::value('id', $params)) {
$ids['membership'] = $params['id'];
$action = CRM_Core_Action::UPDATE;
}
//need to pass action to handle related memberships.
$params['action'] = $action;
$membershipBAO = CRM_Member_BAO_Membership::create($params, $ids, TRUE);
if (array_key_exists('is_error', $membershipBAO)) {
// In case of no valid status for given dates, $membershipBAO
// is going to contain 'is_error' => "Error Message"
return civicrm_api3_create_error(ts('The membership can not be saved, no valid membership status for given dates'));
}
$membership = array();
_civicrm_api3_object_to_array($membershipBAO, $membership[$membershipBAO->id]);
return civicrm_api3_create_success($membership, $params, 'membership', 'create', $membershipBAO);
}
示例15: _civicrm_api3_format_params_for_create
/**
* Format parameters for create action.
*
* @param array $params
* @param $entity
*/
function _civicrm_api3_format_params_for_create(&$params, $entity)
{
$nonGenericEntities = array('Contact', 'Individual', 'Household', 'Organization');
$customFieldEntities = array_diff_key(CRM_Core_BAO_CustomQuery::$extendsMap, array_fill_keys($nonGenericEntities, 1));
if (!array_key_exists($entity, $customFieldEntities)) {
return;
}
$values = array();
_civicrm_api3_custom_format_params($params, $values, $entity);
$params = array_merge($params, $values);
}