$fieldMap[ts(ts('Payment Method'))] = 'payment_instrument_id';
$fieldMap[ts('- do not import -')] = 'do_not_import';
+ // Membership fields
foreach ($mappings as $mapping) {
if (!empty($fieldMap[$mapping['name']])) {
MappingField::update(FALSE)
->execute();
}
}
+
+ // Membership fields...
+ // Yes - I know they could be combined - but it's also less confusing this way.
+ $mappings = MappingField::get(FALSE)
+ ->setSelect(['id', 'name'])
+ ->addWhere('mapping_id.mapping_type_id:name', '=', 'Import Membership')
+ ->execute();
+ $fields = CRM_Member_BAO_Membership::importableFields('All', FALSE);;
+ $fieldMap = [];
+ foreach ($fields as $fieldName => $field) {
+ $fieldMap[$field['title']] = $fieldName;
+ if (!empty($field['html']['label'])) {
+ $fieldMap[$field['html']['label']] = $fieldName;
+ }
+ }
+ $fieldMap[ts('- do not import -')] = 'do_not_import';
+
+ foreach ($mappings as $mapping) {
+ if (!empty($fieldMap[$mapping['name']])) {
+ MappingField::update(FALSE)
+ ->addWhere('id', '=', $mapping['id'])
+ ->addValue('name', $fieldMap[$mapping['name']])
+ ->execute();
+ }
+ }
+
+ // Participant fields...
+ // Yes - I know they could be combined - but it's also less confusing this way.
+ $mappings = MappingField::get(FALSE)
+ ->setSelect(['id', 'name'])
+ ->addWhere('mapping_id.mapping_type_id:name', '=', 'Import Participant')
+ ->execute();
+
+ $fields = CRM_Event_BAO_Participant::importableFields('All', FALSE);
+ $fields['event_id']['title'] = 'Event ID';
+ $eventfields = CRM_Event_BAO_Event::fields();
+ $fields['event_title'] = $eventfields['event_title'];
+
+ $fieldMap = [];
+ foreach ($fields as $fieldName => $field) {
+ $fieldMap[$field['title']] = $fieldName;
+ if (!empty($field['html']['label'])) {
+ $fieldMap[$field['html']['label']] = $fieldName;
+ }
+ }
+ $fieldMap[ts('- do not import -')] = 'do_not_import';
+ $fieldMap[ts('Participant Status')] = 'participant_status_id';
+ $fieldMap[ts('Participant Role')] = 'participant_role_id';
+ $fieldMap[ts('Event Title')] = 'event_id';
+
+ foreach ($mappings as $mapping) {
+ if (!empty($fieldMap[$mapping['name']])) {
+ MappingField::update(FALSE)
+ ->addWhere('id', '=', $mapping['id'])
+ ->addValue('name', $fieldMap[$mapping['name']])
+ ->execute();
+ }
+ }
+
+ // Activity fields...
+ // Yes - I know they could be combined - but it's also less confusing this way.
+ $mappings = MappingField::get(FALSE)
+ ->setSelect(['id', 'name'])
+ ->addWhere('mapping_id.mapping_type_id:name', '=', 'Import Activity')
+ ->execute();
+
+ $activityContact = CRM_Activity_BAO_ActivityContact::import();
+ $activityTarget['target_contact_id'] = $activityContact['contact_id'];
+ $fields = array_merge(CRM_Activity_BAO_Activity::importableFields(),
+ $activityTarget
+ );
+
+ $fields = array_merge($fields, [
+ 'source_contact_id' => [
+ 'title' => ts('Source Contact'),
+ 'headerPattern' => '/Source.Contact?/i',
+ ],
+ ]);
+
+ $fieldMap = [];
+ foreach ($fields as $fieldName => $field) {
+ $fieldMap[$field['title']] = $fieldName;
+ if (!empty($field['html']['label'])) {
+ $fieldMap[$field['html']['label']] = $fieldName;
+ }
+ }
+ $fieldMap[ts('- do not import -')] = 'do_not_import';
+ $fieldMap[ts('Activity Type Label')] = 'activity_type_id';
+
+ foreach ($mappings as $mapping) {
+ if (!empty($fieldMap[$mapping['name']])) {
+ MappingField::update(FALSE)
+ ->addWhere('id', '=', $mapping['id'])
+ ->addValue('name', $fieldMap[$mapping['name']])
+ ->execute();
+ }
+ }
+
return TRUE;
}