function globallink_webform_import in GlobalLink Connect for Drupal 7.7
1 call to globallink_webform_import()
- globallink_background_import in ./
globallink_background_jobs.inc - Imports the documents
File
- globallink_webform/
globallink_webform.inc, line 179
Code
function globallink_webform_import(&$globallink, $submission_rid, $document_rids = NULL) {
module_load_include('inc', 'globallink', 'globallink');
$target_xml = $globallink->targetXML;
if (!isset($target_xml)) {
$globallink->status = GLOBALLINK_STATUS_TRANSLATION_ERROR;
return;
}
$globallink->lids = array();
$language = globallink_get_drupal_locale_code($globallink->targetLocale);
$translated_arr = globallink_webform_get_translated_items($target_xml);
$parent = $translated_arr['pid'];
$parent_arr = globallink_webform_get_doc_rows_by_parent($submission_rid, $parent);
$doc_arr = array();
if ($document_rids != NULL) {
$doc_arr = globallink_webform_get_doc_rows_by_rids($document_rids, $parent);
}
foreach ($translated_arr as $w_key => $lid_arr) {
try {
if ($w_key == 'pid') {
continue;
}
$lid = $w_key;
$import = FALSE;
if ($document_rids != NULL) {
if (count($doc_arr) > 0) {
foreach ($doc_arr as $doc) {
if ($doc->object_id == $lid) {
$import = TRUE;
break;
}
}
}
}
// Only import the lids selected in this submission
if ($document_rids != NULL && !$import) {
continue;
}
array_push($globallink->lids, $lid);
foreach ($lid_arr as $attribute => $translations) {
if ($attribute == 'lid') {
continue;
}
$webform = '';
if ($translations == '#title' || $translations == '#description' || strpos($translations, '#options-') !== false) {
$webform = globallink_load_source_data($lid);
if ($webform == '') {
throw new Exception('Source string not found for webform id ' . $lid . ' and field name ' . $attribute);
}
$report =& drupal_static(__FUNCTION__, array(
'additions' => 0,
'updates' => 0,
'deletes' => 0,
'skips' => 0,
));
_locale_import_one_string_db($report, $language, $webform[0]->context, $webform[0]->source, $lid_arr['translation'], GLOBALLINK_ENTITY_TYPE_WEBFORM, $lid_arr['location'], LOCALE_IMPORT_OVERWRITE);
}
}
} catch (Exception $e) {
$globallink->status = GLOBALLINK_STATUS_TRANSLATION_ERROR;
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
$globallink->status = GLOBALLINK_STATUS_TRANSLATION_IMPORTED;
}
if ($document_rids != NULL) {
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
if (count($parent_arr) == count($globallink->lids)) {
return TRUE;
}
}
return FALSE;
}
elseif ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
return TRUE;
}
return FALSE;
}