03/10/2019 at 12:42 pm
#486580
Participant
Hi Steven,
this is our snippet for the im- and export from our custom fields.
the first one for the export and the second for the import.
The field herden_name is a text field.
The fields genussfleisch,biologisch and herdbuch_zuechter is a checkbox. The last one rinder_farbe is a checkboxgroup. Are the snippets ok?
Regards
Roland
add_filter( 'cn_csv_export_fields', 'cn_register_text_field_header' );
add_filter( ‘cn_csv_export_fields_config’, ‘cn_register_text_field_config’ );
function cn_register_text_field_header( $fields ) {
$fields['herden_name'] = 'Herdenname';
$fields['genussfleisch'] = 'Genussfleischpartner';
$fields['biologisch'] = 'Biobetrieb';
$fields['herdbuch_zuechter'] = 'Herdbuchzucht';
$fields['rinder_farbe'] = 'Farbschlag';
return $fields;
}
function cn_register_text_field_config( $fields ) {
$fields[] = array(
'field' => 'herden_name',
'type' => 5,
'fields' => '',
'table' => CN_ENTRY_TABLE_META,
'types' => NULL,
);
$fields[] = array(
'field' => 'genussfleisch',
'type' => 5,
'fields' => '',
'table' => CN_ENTRY_TABLE_META,
'types' => NULL,
);
$fields[] = array(
'field' => 'biologisch',
'type' => 5,
'fields' => '',
'table' => CN_ENTRY_TABLE_META,
'types' => NULL,
);
$fields[] = array(
'field' => 'herdbuch_zuechter',
'type' => 5,
'fields' => '',
'table' => CN_ENTRY_TABLE_META,
'types' => NULL,
);
$fields[] = array(
'field' => 'rinder_farbe',
'type' => 5,
'fields' => '',
'table' => CN_ENTRY_TABLE_META,
'types' => NULL,
);
return $fields;
}
add_filter( ‘cncsv_map_import_fields’, ‘cncsv_header_name’ );
add_action( ‘cncsv_import_fields’, ‘cncsv_process_import’, 10, 3 );
function cncsv_header_name( $fields ) {
$fields['herden_name'] = 'Herdenname';
$fields['genussfleisch'] = 'Genussfleischpartner';
$fields['biologisch'] = 'Biobetrieb';
$fields['herdbuch_zuechter'] = 'Herdbuchzucht';
$fields['rinder_farbe'] = 'Farbschlag';
return $fields;
}
function cncsv_process_import( $id, $row, $entry ) {
$data = $entry->arrayPull( $row, 'herden_name', '' );
$data = cnFormatting::maybeJSONdecode( stripslashes( $data ) );
$data = $entry->arrayPull( $row, 'genussfleisch', '' );
$data = cnFormatting::maybeJSONdecode( stripslashes( $data ) );
$data = $entry->arrayPull( $row, 'biologisch', '' );
$data = cnFormatting::maybeJSONdecode( stripslashes( $data ) );
$data = $entry->arrayPull( $row, 'herdbuch_zuechter', '' );
$data = cnFormatting::maybeJSONdecode( stripslashes( $data ) );
$data = $entry->arrayPull( $row, 'rinder_farbe', '' );
$data = cnFormatting::maybeJSONdecode( stripslashes( $data ) );
cnEntry_Action::meta(
'update',
$id,
array(
array(
'key' => 'herden_name',
'value' => $data
),
)
);
cnEntry_Action::meta(
'update',
$id,
array(
array(
'key' => 'genussfleisch',
'value' => $data
),
)
);
cnEntry_Action::meta(
'update',
$id,
array(
array(
'key' => 'biologisch',
'value' => $data
),
)
);
cnEntry_Action::meta(
'update',
$id,
array(
array(
'key' => 'herdbuch_zuechter',
'value' => $data
),
)
);
cnEntry_Action::meta(
'update',
$id,
array(
array(
'key' => 'rinder_farbe',
'value' => $data
),
)
);
}
