You are here

function globallink_webform_get_translations_for_row_id in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.5 globallink_webform/globallink_webform_receive.inc \globallink_webform_get_translations_for_row_id()

Gets webform translations by row ID.

Parameters

string $row_id: The row ID.

Return value

array Array of webform translations.

1 call to globallink_webform_get_translations_for_row_id()
globallink_webform_preview_translated_content in globallink_webform/globallink_webform_receive.inc
Previews translated webform content in the form of JSON.

File

globallink_webform/globallink_webform_receive.inc, line 726

Code

function globallink_webform_get_translations_for_row_id($row_id) {
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_settings');
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
  module_load_include('inc', 'globallink_webform', 'globallink_webform');
  $row = globallink_get_other_row($row_id, 'webform');
  $globallink = new GlobalLink();
  $globallink->tptRowId = $row_id;
  $globallink->otherObjectId = $row->parent_id;
  $globallink->type = $row->object_type;
  $globallink->title = $row->title;
  $globallink->sourceLocale = $row->source;
  $globallink->targetLocale = $row->target;
  $globallink->documentTicket = $row->document_ticket;
  $globallink->submissionTicket = $row->submission_ticket;
  $globallink->submission = $row->submission;
  $globallink->status = $row->status;
  $source_arr = array();
  $translation = array();
  $error = FALSE;
  try {
    $pd4 = globallink_get_project_director_details();
    $targets = globallink_get_completed_targets_by_doc($pd4, $globallink->documentTicket);
    if (is_array($targets)) {
      foreach ($targets as $target) {
        if (str_replace('-', '_', $target->targetLanguage->locale) != $globallink->targetLocale) {
          continue;
        }
        if (is_null($target->ticket) || $target->ticket == '') {
          continue;
        }
        $globallink->targetTicket = $target->ticket;
        $globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
        if (is_null($globallink->targetXML) || $globallink->targetXML == '') {
          continue;
        }
        $translation = globallink_webform_get_translated_items($globallink->targetXML);
        $pid = '';
        foreach ($translation as $w_key => $lid_arr) {
          if ($w_key == 'pid') {
            $pid = $lid_arr;
            continue;
          }
          $lid = $w_key;
        }
        $webform = globallink_load_source_data($lid);
        if ($webform && is_array($webform) && !is_null($webform)) {
          $source = globallink_load_source_data($lid);
          $source_arr_temp['source'] = $source[0]->source;
          $source_arr_temp['location'] = $source[0]->location;
          $lids = array();
          $lids[$pid] = $lid;
          $source_xmls = globallink_webform_get_xml($lids);
          $source_xml = $source_xmls[$globallink->otherObjectId];
          $source_arr = array();
          if ($source_xml) {
            $source_arr = globallink_webform_get_translated_items($source_xml);
            $source_arr = $source_arr[$lid];
          }
        }
        else {
          $source_xml = 'Source Deleted';
          $globallink->sourceDeleted = TRUE;
        }
      }
    }
    else {
      if (!is_null($targets)) {
        $target = $targets;
        if (str_replace('-', '_', $target->targetLanguage->locale) == $globallink->targetLocale) {
          if (!is_null($target->ticket) && $target->ticket != '') {
            $globallink->targetTicket = $target->ticket;
            $globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
            if (!is_null($globallink->targetXML) && $globallink->targetXML != '') {
              $translation = globallink_webform_get_translated_items($globallink->targetXML);
              $pid = '';
              foreach ($translation as $w_key => $lid_arr) {
                if ($w_key == 'pid') {
                  $pid = $lid_arr;
                  continue;
                }
                $lid = $w_key;
              }
              $webform = globallink_load_source_data($lid);
              if ($webform && is_array($webform) && !is_null($webform)) {
                $source = globallink_load_source_data($lid);
                $source_arr_temp['source'] = $source[0]->source;
                $source_arr_temp['location'] = $source[0]->location;
                $lids = array();
                $lids[$pid] = $lid;
                $source_xmls = globallink_webform_get_xml($lids);
                $source_xml = $source_xmls[$globallink->otherObjectId];
                $source_arr = array();
                if ($source_xml) {
                  $source_arr = globallink_webform_get_translated_items($source_xml);
                  $source_arr = $source_arr[$lid];
                }
              }
              else {
                $source_xml = 'Source Deleted';
                $globallink->sourceDeleted = TRUE;
              }
            }
          }
        }
      }
    }
  } catch (SoapFault $se) {
    $error = $se->faultstring;
  } catch (Exception $ex) {
    $error = $ex
      ->getMessage();
  }
  $arr = array();
  $arr['target_ticket'] = $globallink->targetTicket;
  if ($globallink->sourceDeleted) {
    $arr = array(
      'Source Deleted',
    );
  }
  elseif ($error) {
    $arr = array(
      'error' => $error,
    );
  }
  else {
    $arr['source'] = $source_arr;
    $arr['target'] = $translation[$lid];
  }
  return $arr;
}