You are here

function globallink_webform_get_translated in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 globallink_webform/globallink_webform.inc \globallink_webform_get_translated()

Gets number of translated webforms.

Parameters

string $pd4: The project director details.

array $globallink_arr: Array of GlobalLink objects.

Return value

int The number of translated webforms.

2 calls to globallink_webform_get_translated()
globallink_auto_receive in ./globallink.module
Automatically receives translated contents.
globallink_webform_receive_form_submit in globallink_webform/globallink_webform_receive.inc
Handles webform form submission.

File

globallink_webform/globallink_webform.inc, line 230

Code

function globallink_webform_get_translated($pd4, &$globallink_arr) {
  module_load_include('inc', 'globallink', 'globallink');
  $count = 0;
  foreach ($globallink_arr as $globallink) {
    $target_xml = globallink_download_target_resource($pd4, $globallink->targetTicket);
    if ($globallink->sourceDeleted) {
      continue;
    }
    if (!isset($target_xml)) {
      continue;
    }
    $count++;
    $language = globallink_get_drupal_locale_code($globallink->targetLocale);
    $translated_arr = globallink_webform_get_translated_items($target_xml);
    try {
      $lid = $translated_arr['lid'];
      foreach ($translated_arr as $attribute => $translations) {
        if ($attribute == 'lid') {
          continue;
        }
        $webform = '';
        if ($attribute == '#title' || $attribute == '#description' || strpos($attribute, '#options-') !== false) {
          $webform = globallink_load_source_data($translations['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, $translations['translation'], 'webform', $translations['location'], LOCALE_IMPORT_OVERWRITE);
      }
      if ($globallink->status != 'Error') {
        if ($globallink->status != 'Node Deleted') {
          globallink_send_download_confirmation($globallink->targetTicket, $pd4);
        }
        globallink_webform_update_status($globallink);
      }
      else {
        $count--;
      }
    } catch (SoapFault $se) {
      $count--;
      globallink_webform_update_status($globallink, 'Error');
      form_set_error('', t('Web Services Error: @faultcode - @faultstring', array(
        '@faultcode' => $se->faultcode,
        '@faultstring' => $se->faultstring,
      )));
    } catch (Exception $ex) {
      $count--;
      globallink_webform_update_status($globallink, 'Error');
      form_set_error('', t('Error: @message', array(
        '@message' => $ex
          ->getMessage(),
      )));
    }
  }
  return $count;
}