*
* @return array
* array of importable Fields
+ * @throws \CRM_Core_Exception
*/
- public static function &importableFields($contactType = 'Individual', $status = TRUE) {
- if (!self::$_importableFields) {
- if (!self::$_importableFields) {
- self::$_importableFields = [];
- }
-
+ public static function importableFields($contactType = 'Individual', $status = TRUE) {
+ $fields = Civi::cache('fields')->get('membership_importable_fields' . $contactType . $status);
+ if (!$fields) {
if (!$status) {
$fields = ['' => ['title' => '- ' . ts('do not import') . ' -']];
}
}
}
$tmpContactField['external_identifier'] = $contactFields['external_identifier'];
- $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " " . ts('(match to contact)');
+ $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . ' ' . ts('(match to contact)');
- $tmpFields['membership_contact_id']['title'] = $tmpFields['membership_contact_id']['title'] . " " . ts('(match to contact)');
+ $tmpFields['membership_contact_id']['title'] .= ' ' . ts('(match to contact)');
$fields = array_merge($fields, $tmpContactField);
$fields = array_merge($fields, $tmpFields);
$fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Membership'));
- self::$_importableFields = $fields;
+ Civi::cache('fields')->set('membership_importable_fields' . $contactType . $status, $fields);
}
- return self::$_importableFields;
+ return $fields;
}
/**
*/
public function summary(&$values) {
$erroneousField = NULL;
- $response = $this->setActiveFieldValues($values, $erroneousField);
+ $this->setActiveFieldValues($values, $erroneousField);
$errorRequired = FALSE;
}
$session = CRM_Core_Session::singleton();
- $dateType = $session->get('dateTypes');
+ $dateType = CRM_Core_Session::singleton()->get('dateTypes');
$formatted = [];
$customDataType = !empty($params['contact_type']) ? $params['contact_type'] : 'Membership';
$customFields = CRM_Core_BAO_CustomField::getFields($customDataType);
* @group headless
*/
class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase {
+ use CRMTraits_Custom_CustomDataTrait;
+
/**
* Membership type name used in test function.
*
'fixed_period_start_day' => 101,
'fixed_period_rollover_day' => 1231,
];
- $ids = [];
- $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
+
+ $membershipType = CRM_Member_BAO_MembershipType::add($params);
$this->_membershipTypeID = $membershipType->id;
$this->_mebershipStatusID = $this->membershipStatusCreate('test status');
'civicrm_membership_payment',
'civicrm_contact',
];
- $this->quickCleanup($tablesToTruncate, TRUE);
$this->relationshipTypeDelete($this->_relationshipTypeId);
$this->membershipTypeDelete(['id' => $this->_membershipTypeID]);
$this->membershipStatusDelete($this->_mebershipStatusID);
+ $this->quickCleanup($tablesToTruncate, TRUE);
}
/**
return $membershipImporter;
}
+ /**
+ * Test importing to a custom field.
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ */
+ public function testImportCustomData() {
+ $donaldDuckID = $this->individualCreate(['first_name' => 'Donald', 'last_name' => 'Duck']);
+ $this->createCustomGroupWithFieldsOfAllTypes(['extends' => 'Membership']);
+ $membershipImporter = $this->createImportObject([
+ 'membership_contact_id',
+ 'membership_type_id',
+ 'membership_start_date',
+ $this->getCustomFieldName('text'),
+ $this->getCustomFieldName('select_string'),
+ ]);
+ $importValues = [
+ $donaldDuckID,
+ $this->_membershipTypeID,
+ date('Y-m-d'),
+ 'blah',
+ 'Red',
+ ];
+
+ $importResponse = $membershipImporter->import(CRM_Import_Parser::DUPLICATE_UPDATE, $importValues);
+ $this->assertEquals(CRM_Import_Parser::VALID, $importResponse);
+ $membership = $this->callAPISuccessGetSingle('Membership', []);
+ $this->assertEquals('blah', $membership[$this->getCustomFieldName('text')]);
+ $this->assertEquals('R', $membership[$this->getCustomFieldName('select_string')]);
+ }
+
}