Skip to content

Instantly share code, notes, and snippets.

@cwittyman
Last active August 29, 2015 14:00
Show Gist options
  • Save cwittyman/11022987 to your computer and use it in GitHub Desktop.
Save cwittyman/11022987 to your computer and use it in GitHub Desktop.
ee-marker-import
<?php
ee()->load->library('api');
ee()->api->instantiate('channel_entries');
ee()->api->instantiate('channel_fields');
$channel_id = 100;
$site_id = 9;
$fileName = "/path/to/hotels.csv";
$csvData = file_get_contents($fileName);
$lines = explode(PHP_EOL, $csvData);
foreach ($lines as $line) {
$line = str_getcsv($line);
$address = $line[0] . "<br/>" . $line[1] . " " . $line[2] . ", " . $line[3] . "<br/>". $line[5];
if($line[7] !=""){
$address .= "<br/>Contact - " . $line[7];
}
$data = array(
'title' => $line[4],
'entry_date' => time(),
'edit_date' => time(),
'field_id_455' => '{filedir_24}hotels_marker.png',
'field_ft_455' => 'none',
'field_id_459' => '{filedir_24}maps_courtyard_marriott.jpg',
'field_ft_459' => 'none',
'field_id_452' => $line[8],
'field_ft_452' => 'xhtml',
'field_id_453' => $line[9],
'field_ft_453' => 'none',
'field_id_457' => $line[4],
'field_ft_457' => 'none',
'field_id_460' => $line[10],
'field_ft_460' => 'none',
'field_id_458' => $address,
'field_ft_458' => 'none',
);
ee()->api_channel_fields->setup_entry_settings($channel_id, $data);
$newId = ee()->api_channel_entries->submit_new_entry($channel_id, $data);
if ( $newId === FALSE)
{
show_error('An Error Occurred Creating the Entry');
}
$results = $this->EE->db->query("SELECT MAX( entry_id ) FROM exp_channel_data");
foreach($results->result_array() as $row)
{
//echo $row['MAX( entry_id )']."\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment