* {getfields MembershipType_get}
*/
function civicrm_api3_membership_type_create($params) {
- $values = $params;
- civicrm_api3_verify_mandatory($values, 'CRM_Member_DAO_MembershipType');
+ $ids['membershipType'] = CRM_Utils_Array::value('id', $params);
+ $ids['memberOfContact'] = CRM_Utils_Array::value('member_of_contact_id', $params);
+ $ids['contributionType'] = CRM_Utils_Array::value('financial_type_id', $params);
- $ids['membershipType'] = CRM_Utils_Array::value('id', $values);
- $ids['memberOfContact'] = CRM_Utils_Array::value('member_of_contact_id', $values);
- $ids['contributionType'] = CRM_Utils_Array::value('financial_type_id', $values);
-
- $membershipTypeBAO = CRM_Member_BAO_MembershipType::add($values, $ids);
+ $membershipTypeBAO = CRM_Member_BAO_MembershipType::add($params, $ids);
$membershipType = array();
_civicrm_api3_object_to_array($membershipTypeBAO, $membershipType[$membershipTypeBAO->id]);
CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
+ civicrm_api3('membership', 'getfields', array('cache_clear' => 1, 'fieldname' => 'membership_type_id'));
+ civicrm_api3('profile', 'getfields', array('action' => 'submit', 'cache_clear' => 1));
return civicrm_api3_create_success($membershipType, $params, 'membership_type', 'create', $membershipTypeBAO);
}
// we don't resolve state, country & county for performance reasons
$resolveOptions = CRM_Utils_Array::value('get_options',$apirequest['params']) == 'all' ? True : False;
$profileID = _civicrm_api3_profile_getProfileID($apirequest['params']['profile_id']);
- $params = _civicrm_api3_buildprofile_submitfields($profileID, $resolveOptions);
+ $params = _civicrm_api3_buildprofile_submitfields($profileID, $resolveOptions, CRM_Utils_Array::value('cache_clear', $params));
+ }
+ elseif (isset($apirequest['params']['cache_clear'])) {
+ _civicrm_api3_buildprofile_submitfields(FALSE, FALSE, True);
}
$params['profile_id']['api.required'] = TRUE;
}
*
* @param integer $profileID
* @param integer $optionsBehaviour 0 = don't resolve, 1 = resolve non-aggressively, 2 = resolve aggressively - ie include country & state
+ * @param $params
+ *
+ * @return
*/
-function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour = 1) {
+function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour = 1, $is_flush) {
static $profileFields = array();
+ if($is_flush) {
+ $profileFields = array();
+ if(empty($profileID)) {
+ return;
+ }
+ }
if(isset($profileFields[$profileID])) {
return $profileFields[$profileID];
}
*
*/
function _civicrm_api3_map_profile_fields_to_entity(&$field) {
- $entity = $field['field_type'];
+ $entity = _civicrm_api_get_entity_name_from_camel($field['field_type']);
$contactTypes = civicrm_api3('contact', 'getoptions', array('field' => 'contact_type'));
- $locationFields = array('email' => 'Email');
+ $locationFields = array('email' => 'email');
if(in_array($entity, $contactTypes['values'])) {
- $entity = 'Contact';
+ $entity = 'contact';
}
$fieldName = $field['field_name'];
if(!empty($field['location_type_id'])) {
if($fieldName == 'email') {
- $entity = 'Email';
+ $entity = 'email';
}
else{
- $entity = 'Address';
+ $entity = 'address';
}
$fieldName .= '-' . $field['location_type_id'];
}
elseif(array_key_exists($fieldName, $locationFields)) {
$fieldName .= '-Primary';
- $entity = 'Email';
+ $entity = 'email';
}
if(!empty($field['phone_type_id'])) {
$fieldName .= '-' . $field['location_type_id'];
- $entity = 'Phone';
+ $entity = 'phone';
}
// @todo - sort this out!
// in a perfect world the uf_field table would hold the correct entity for each item
// & only the relationships between entities would need to be coded
$hardCodedEntityMappings = array(
- 'street_address' => 'Address',
- 'street_number' => 'Address',
- 'supplemental_address_1' => 'Address',
- 'supplemental_address_2' => 'Address',
- 'supplemental_address_3' => 'Address',
- 'postal_code' => 'Address',
- 'city' => 'Address',
- 'email' => 'Email',
- 'state_province' => 'Address',
- 'country' => 'Address',
- 'county' => 'Address',
+ 'street_address' => 'address',
+ 'street_number' => 'address',
+ 'supplemental_address_1' => 'address',
+ 'supplemental_address_2' => 'address',
+ 'supplemental_address_3' => 'address',
+ 'postal_code' => 'address',
+ 'city' => 'address',
+ 'email' => 'email',
+ 'state_province' => 'address',
+ 'country' => 'address',
+ 'county' => 'address',
//note that in discussions about how to restructure the api we discussed making these membership
// fields into 'membership_payment' fields - which would entail declaring them in getfields
// & renaming them in existing profiles
- 'financial_type' => 'Contribution',
- 'total_amount' => 'Contribution',
- 'receive_date' => 'Contribution',
- 'payment_instrument' => 'Contribution',
- 'check_number' => 'Contribution',
- 'contribution_status_id' => 'Contribution',
- 'soft_credit' => 'Contribution',
- 'group' => 'GroupContact',
- 'tag' => 'EntityTag',
+ 'financial_type' => 'contribution',
+ 'total_amount' => 'contribution',
+ 'receive_date' => 'contribution',
+ 'payment_instrument' => 'contribution',
+ 'check_number' => 'contribution',
+ 'contribution_status_id' => 'contribution',
+ 'soft_credit' => 'contribution',
+ 'group' => 'group_contact',
+ 'tag' => 'entity_tag',
);
if(array_key_exists($fieldName, $hardCodedEntityMappings)) {
$entity = $hardCodedEntityMappings[$fieldName];
}
}
//special case on membership & contribution - can't see how to handle in a generic way
- if(in_array($entity, array('Membership', 'Contribution'))) {
+ if(in_array($entity, array('membership', 'contribution'))) {
$values['send_receipt'] = array('title' => 'Send Receipt', 'type' => (int) 16);
}
return $values;
class api_v3_ProfileTest extends CiviUnitTestCase {
protected $_apiversion;
protected $_profileID = 0;
+ protected $_membershipTypeID;
+ protected $_contactID;
function get_info() {
return array(
'name' => 'Profile Test',
$config->countryLimit[1] = 1013;
$config->stateLimit[1] = 1013;
$this->createLoggedInUser();
+ $this->_membershipTypeID = $this->membershipTypeCreate();
}
function tearDown() {
'civicrm_contact',
'civicrm_phone',
'civicrm_address',
+ 'civicrm_membership',
+ 'civicrm_contribution',
), TRUE);
+ $this->callAPISuccess('membership_type', 'delete', array('id' => $this->_membershipTypeID));
// ok can't be bothered wring an api to do this & truncating is crazy
CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_uf_group WHERE id IN ($this->_profileID, 26)");
}
), $params
);
- $contactID = $this->individualCreate($contactParams);
+ $this->_contactID = $this->individualCreate($contactParams);
$this->_createIndividualProfile();
// expected result of above created profile with contact Id $contactId
- $profileData[$contactID] = array(
+ $profileData[$this->_contactID] = array(
'first_name' => 'abc1',
'last_name' => 'xyz1',
'email-primary' => 'abc1.xyz1@yahoo.com',