Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created July 19, 2012 19:29
Show Gist options
  • Select an option

  • Save objectivehtml/3146209 to your computer and use it in GitHub Desktop.

Select an option

Save objectivehtml/3146209 to your computer and use it in GitHub Desktop.
public function import_item_action()
{
$item = $this->EE->data_import_model->get_item($this->EE->input->get_post('schema_id'));
$settings = $this->EE->data_import_model->get_setting($this->EE->input->get_post('schema_id'));
$data = (array) json_decode($item->data);
foreach(explode('|', $item->categories) as $category)
{
$data['category'][] = $category;
}
$data['entry_date'] = $this->EE->localize->now;
$markers = array();
//var_dump($this->EE->google_maps->geocode('50 Washington Ave Richmond CA 948013995'));exit();
foreach($this->EE->google_maps->geocode($item->geocode) as $response)
{
if($response->status == 'OK')
{
foreach($response->results as $result)
{
$markers[] = (object) $result;
}
}
}
$data['field_id_'.$settings->gmap_field] = $this->EE->google_maps->build_response(array('markers' => $markers));;
$data['field_ft_'.$settings->gmap_field] = 'none';
$this->EE->load->library('api');
$this->EE->api->instantiate('channel_entries');
$this->EE->api->instantiate('channel_fields');
$this->EE->api_channel_fields->setup_entry_settings($settings->channel, $data);
$this->EE->api_channel_entries->submit_new_entry($settings->channel, $data);
if(count($this->EE->api_channel_entries->errors) == 0)
{
$this->EE->data_import_model->delete_pool($item->id);
$return = $this->EE->data_import_model->import_success($this->EE->input->get_post('schema_id'));
}
else
{
$return = $this->EE->data_import_model->import_failed($this->EE->input->get_post('schema_id'));
}
$return = (array) $return;
$return['geocode'] = $item->geocode;
return $this->json((object) $return);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment