You are here

function globallink_interface_get_translations_for_row_id in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 globallink_interface/globallink_interface_receive.inc \globallink_interface_get_translations_for_row_id()

Gets interface translations by row ID.

Parameters

string $row_id: The row ID.

Return value

array Array of interface translations.

1 call to globallink_interface_get_translations_for_row_id()
globallink_interface_preview_translated_content in globallink_interface/globallink_interface_receive.inc
Previews translated interface content in the form of JSON.

File

globallink_interface/globallink_interface_receive.inc, line 739

Code

function globallink_interface_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_interface', 'globallink_interface');
  $row = globallink_get_other_row($row_id, 'interface');
  $globallink = new GlobalLink();
  $globallink->tptRowId = $row_id;
  $globallink->otherObjectId = $row->object_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_interface_get_translated_items($globallink->targetXML);
        $lid = $translation['lid'];
        $interface = globallink_load_source_data($lid);
        if ($interface && is_array($interface) && !is_null($interface)) {
          $source = globallink_load_source_data($lid);
          $source_arr_temp['source'] = $source[0]->source;
          $source_arr_temp['location'] = $source[0]->location;
          $source_xml = globallink_interface_get_xml($lid, $source_arr_temp);
          $source_arr = array();
          if ($source_xml) {
            $source_arr = globallink_interface_get_translated_items($source_xml);
          }
        }
        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_interface_get_translated_items($globallink->targetXML);
              $lid = $translation['lid'];
              $interface = globallink_load_source_data($lid);
              if ($interface && is_array($interface) && !is_null($interface)) {
                $source = globallink_load_source_data($lid);
                $source_arr_temp['source'] = $source[0]->source;
                $source_arr_temp['location'] = $source[0]->location;
                $source_xml = globallink_interface_get_xml($lid, $source_arr_temp);
                $source_arr = array();
                if ($source_xml) {
                  $source_arr = globallink_interface_get_translated_items($source_xml);
                }
              }
              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 {
    $source_arr_send['source'] = $source_arr['source']['translation'];
    $translation_arr_send['source'] = $translation['source']['translation'];
    $arr['source'] = $source_arr_send;
    $arr['target'] = $translation_arr_send;
  }
  return $arr;
}