In LiveWhale 2.23+, you can set up a Linked Calendar to sync from a CSV or JSON source using the built-in /live/calendar_feeds/ script and a standard set of column headers (or attribute keys, in JSON).
If you want to import CSV data that doesn’t conform exactly to the out-of-the-box column headers, you can use onMapToIcalFields to filter each event before it gets rendered to ICAL.
Supported inputs:
- $source (string) – the specific CSV or JSON source being processed, as defined in your config file
- $source_fields (array) – the original key/value pairs from the CSV or JSON
- $ical_fields (array) – the processed ICAL fields from the core mappings so far
To override the core $ical_fields with your own, you may want to use the “order” setting to ensure this module runs after the core process. See example below.
<?php
$_LW->REGISTERED_APPS['custom_ical_fields']=[
'title'=>'Custom iCal Fields',
'handlers'=>['onMapToIcalFields'],
'order'=>10,
];
class LiveWhaleApplicationCustomIcalFields {
public function onMapToIcalFields($source, $source_fields, $ical_fields=[]) {
global $_LW;
if ($source=='my-csv') { // when importing from my-csv source
// overwrite certain fields
$ical_fields['description']='Some description.';
// or add new/custom fields, e.g. my_variable
$ical_fields['x-livewhale-custom-my-variable']='Some custom value.';
}
return $ical_fields;
}
}
?>
LiveWhale Support