You are here

function globallink_entity_get_translations_for_row_id in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 globallink_entity/globallink_entity_receive.inc \globallink_entity_get_translations_for_row_id()

Gets entity translations by row ID.

Parameters

string $row_id: The row ID.

Return value

array Array of entity translations.

1 call to globallink_entity_get_translations_for_row_id()
globallink_entity_preview_translated_content in globallink_entity/globallink_entity_receive.inc
Previews translated entity content in the form of JSON.

File

globallink_entity/globallink_entity_receive.inc, line 719

Code

function globallink_entity_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_entity', 'globallink_entity');
  $row = globallink_entity_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 (empty($target)) {
        continue;
      }
      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_entity_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_entity_get_xml($node, $globallink->targetLocale, NULL, NULL, $name, TRUE, $drupal_locale_code);
        $source_arr = array();
        if ($source_xml != 'Source Deleted') {
          $source_arr = globallink_entity_get_translated_array($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 {
    $arr['source'] = $source_arr;
    $arr['target'] = $translation;
  }
  return $arr;
}