function taxonomy_csv_line_import_geotaxonomy in Taxonomy CSV import/export 6.2
Same name and namespace in other branches
- 6.5 formats/geotaxonomy.format.inc \taxonomy_csv_line_import_geotaxonomy()
- 6.3 formats/geotaxonomy.format.inc \taxonomy_csv_line_import_geotaxonomy()
- 6.4 formats/geotaxonomy.format.inc \taxonomy_csv_line_import_geotaxonomy()
Import a line of items.
Parameters
$previous_items: Specificity: tid and name arrays are indexed with unique ids, and with name when unique id is not defined.
File
- formats/
geotaxonomy.format.inc, line 130 - Plug-in that manages geotaxonomy vocabularies import/export.
Code
function taxonomy_csv_line_import_geotaxonomy($line, $options, $previous_items = array()) {
// Define default values.
$result = array(
'name' => array(),
'tid' => array(),
'msg' => array(),
);
switch ($result) {
// Simulate a goto with break.
default:
// Keep index (names and tids) with unique id.
$result['name'] = $previous_items['name'];
$result['tid'] = $previous_items['tid'];
// First, import parent if needed using a recursive call and check result.
if (!empty($line[3])) {
$parent_unique_id = $line[3];
// Import a new term if it is not already imported.
if (!isset($previous_items['tid'][$parent_unique_id])) {
$term = (object) array(
'name' => $line[3],
'vid' => $options['vocabulary_id'],
);
$current_result = taxonomy_csv_term_import($term, $options['existing_items']);
$result['name'][$parent_unique_id] = $current_result['name'];
$result['tid'][$parent_unique_id] = $current_result['tid'];
$result['msg'] = $current_result['msg'];
if (_taxonomy_csv_worst_message($result['msg']) < TAXONOMY_CSV_PROCESS_NOTICE) {
break;
}
}
$parent_name = $result['name'][$parent_unique_id];
$parent_tid = $result['tid'][$parent_unique_id];
}
// Second, import (save or update) main term.
$unique_id = $line[0];
// Complete line with NULL if needed.
$line = array_pad($line, 8, NULL);
$term = (object) array(
'name' => $line[0],
'vid' => $options['vocabulary_id'],
'parents' => array(
isset($parent_tid) ? $parent_tid : 0,
),
'synonyms' => array(
$line[1],
$line[2],
),
// Geotaxonomy specific fields.
'lat' => $line[1],
'lon' => $line[2],
'bound_top' => $line[4],
'bound_right' => $line[5],
'bound_bottom' => $line[6],
'bound_left' => $line[7],
);
// Add unique ids only if they are set.
if (isset($result['tid'][$unique_id])) {
$term->tid = $result['tid'][$unique_id];
}
if (isset($line[3])) {
$term->parent_name = $line[3];
}
// Import term then store result. No check because only one term.
$current_result = taxonomy_csv_term_import($term, $options['existing_items'], FALSE, '', $options['import_format']);
$result['name'][$unique_id] = $current_result['name'];
$result['tid'][$unique_id] = $current_result['tid'];
$result['msg'] = array_merge($result['msg'], $current_result['msg']);
}
return $result;
}