You are here

function globallink_get_translations_for_row_id in GlobalLink Connect for Drupal 7.6

Same name and namespace in other branches
  1. 7.5 globallink_receive_translations.inc \globallink_get_translations_for_row_id()

Gets GlobalLink translations by row ID.

Parameters

string $row_id: The row ID.

Return value

array Array of GlobalLink translations.

1 call to globallink_get_translations_for_row_id()
globallink_preview_translated_content in ./globallink_receive_translations.inc
Previews translated GlobalLink content in the form of JSON.

File

./globallink_receive_translations.inc, line 722

Code

function globallink_get_translations_for_row_id($row_id) {
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_node');
  module_load_include('inc', 'globallink', 'globallink_settings');
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
  $row = globallink_get_row($row_id);
  $globallink = new GlobalLink();
  $globallink->tptRowId = $row_id;
  $globallink->nid = $row->nid;
  $globallink->vid = $row->vid;
  $globallink->type = $row->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)) {
      $targets = array(
        $targets,
      );
    }
    foreach ($targets as $target) {
      if (str_replace('-', '_', $target->targetLanguage->locale) != $globallink->targetLocale) {
        $source_xml = 'Source Deleted';
        $globallink->sourceDeleted = TRUE;
        continue;
      }
      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_get_translated_array($globallink->targetXML);
          $nid = $translation['nid'];
          $vid = $translation['vid'];
          $node = node_load($nid, $vid);
          if ($node && is_object($node) && !is_null($node)) {
            $drupal_locale_code = globallink_get_drupal_locale_code($globallink->sourceLocale);
            if ($node->tnid != 0 && $node->language != $drupal_locale_code) {
              $translations = translation_node_get_translations($node->tnid);
              if (isset($translations) && isset($translations[$drupal_locale_code])) {
                $src_tnode = $translations[$drupal_locale_code];
                $node = node_load($src_tnode->nid);
              }
            }
            $name = '';
            $source_xml = globallink_get_xml($node, $globallink->targetLocale, NULL, NULL, $name, TRUE);
            $source_arr = array();
            if ($source_xml != 'Source Deleted') {
              $source_arr = globallink_get_translated_array($source_xml);
            }
          }
          else {
            $source_xml = 'Source Deleted';
            $globallink->sourceDeleted = TRUE;
          }
        }
      }
      $name = '';
      $source_xml = globallink_get_xml($node, $globallink->targetLocale, NULL, NULL, $name, TRUE);
      $source_arr = array();
      if ($source_xml != 'Source Deleted') {
        $source_arr = globallink_get_translated_array($source_xml);
      }
    }
  } 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;
  }
  return $arr;
}