/** * Import file of cities * * @access public * @return void */ public function import($id = false, $ready = false) { // what we doin? if ($id) { $data = _pre_import_csv($id); //helper // Unset the labels // unset($data['entries'][0]); $total = count($data['entries']); // Build the batch foreach ($data['entries'] as $entry) { // A;dd.. $batch[] = array('id' => $entry[0], 'created' => date('Y-m-d H:i:s'), 'created_by' => $this->current_user->id, 'ordering_count' => 0, 'name' => $entry[1], 'asciiname' => $entry[2], 'alternatenames' => $entry[3], 'latitude' => $entry[4], 'longitude' => $entry[5], 'feature_class' => $entry[6], 'feature_code' => $entry[7], 'country_code' => $entry[8], 'cc2' => $entry[9], 'admin1_code' => $entry[10], 'admin2_code' => $entry[11], 'admin3_code' => $entry[12], 'admin4_code' => $entry[13], 'population' => $entry[14], 'elevation' => $entry[15], 'dem' => $entry[16], 'timezone' => $entry[17], 'modification_date' => isset($entry[4]) ? trim($entry[18]) : null); } // Import them batch_insert_update('geonames_manager_geoname', $batch, array('ordering_count')); // Way to go! $this->session->set_flashdata('success', lang('import:success_importation')); redirect('admin/geonames_manager'); } else { // Chosen? if (isset($_POST['file_id'])) { redirect(current_url() . '/' . $_POST['file_id']); return false; } // Get files $data['files'] = array(); //Query / loop foreach ($this->db->select('id, name')->where('extension', '.txt')->get('files')->result() as $row) { $data['files'][$row->id] = $row->name; } $this->template->build('admin/import/choose_csv', $data); } }
/** * Profile Mapping screen * * @param $id Profile ID */ public function mapping($id) { if ($this->input->post()) { // We delete all existing data for this mapping, and we will overwrite everything $this->db->where('profile_relation_stream', $this->input->post('profileID'))->delete('streams_import_mapping'); //Go generate and save the mapping $source = $this->input->post('source'); $dest = $this->input->post('destination'); for ($i = 0; $i < $this->input->post('counter'); $i++) { if (isset($dest[$i]) && !empty($dest[$i]) && isset($source[$i]) && !empty($source[$i])) { # code... $insert_data[] = array('stream_field' => $dest[$i], 'entry_number' => $source[$i], 'ordering_count' => $i, 'created' => date('Y-m-d H:i:s'), 'created_by' => $this->current_user->id, 'profile_relation_stream' => $this->input->post('profileID')); } //var_dump($insert_data); } // Import them batch_insert_update('streams_import_mapping', $insert_data, array('ordering_count')); $this->session->set_flashdata('success', lang('streams_import:messages:mapping:save:success')); redirect('/admin/streams_import/profiles'); } // get the profile we're editing. $current_profile = $this->streams_import_m->get_profile_object($id); //get the stream's fields we want import into $data->fields = $this->get_stream_fields_list($current_profile->stream_identifier); //$data->field_count = count((array) $data->fields); //number of fields we have for this stream. //Go for the magic ! Convert the example file to a PHP array. $data_array = $this->streams_import->file_to_array(get_fileid_by_profileid($current_profile->id), $current_profile); // if we work with XML and path loop is define, so we can load the node to loop if ($current_profile->source_format == 'XML' && $current_profile->xml_path_loop) { $matches = get_values_between_brackets($current_profile->xml_path_loop); //we fetch the array until we got the xpath as the root foreach ($matches as $key) { $data_array = $data_array["{$key}"]; } } //processing the output if the array $data->csv_dropdown = $this->streams_import->post_process_array($data_array); array_unshift($data->csv_dropdown, '------'); $data->csv_dropdown['preprocess'] = 'will be preprocessed'; // Debug //print_r($data->csv_dropdown);die; $this->template->build('admin/profiles/mapping', $data); }