You are here

function globallink_webform_get_translated in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.5 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 292

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;
    }
    $globallink->lids = array();
    $language = globallink_get_drupal_locale_code($globallink->targetLocale);
    $translated_arr = globallink_webform_get_translated_items($target_xml);
    try {
      $parent = $translated_arr['pid'];
      foreach ($translated_arr as $w_key => $lid_arr) {
        if ($w_key == 'pid') {
          continue;
        }
        $lid = $w_key;
        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,
            ));
            $count++;
            _locale_import_one_string_db($report, $language, $webform[0]->context, $webform[0]->source, $lid_arr['translation'], 'webform', $lid_arr['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;
}