You are here

function globallink_taxonomy_get_translations_for_row_id in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.6 globallink_taxonomy/globallink_taxonomy_receive.inc \globallink_taxonomy_get_translations_for_row_id()

Gets taxonomy translations by row ID.

Parameters

string $row_id: The row ID.

Return value

array Array of taxonomy translations.

1 call to globallink_taxonomy_get_translations_for_row_id()
globallink_taxonomy_preview_translated_content in globallink_taxonomy/globallink_taxonomy_receive.inc
Previews translated taxonomy content in the form of JSON.

File

globallink_taxonomy/globallink_taxonomy_receive.inc, line 745

Code

function globallink_taxonomy_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_taxonomy', 'globallink_taxonomy');
  $row = globallink_get_other_row($row_id, 'taxonomy');
  $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)) {
      $targets = array(
        $targets,
      );
    }
    $vocabs = taxonomy_get_vocabularies();
    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_taxonomy_get_arr_items($globallink->targetXML);
      $bid = $translation['bid'];
      $term = taxonomy_term_load($bid);
      $vocab = array();
      if (isset($vocabs[$term->vid])) {
        $vocab = $vocabs[$term->vid];
      }
      if (!empty($term) && !empty($vocab)) {
        $path = drupal_lookup_path('alias', 'taxonomy/term/' . $bid, $term->language);
        if ($vocab->i18n_mode == I18N_MODE_LOCALIZE) {
          $source_xml = globallink_get_taxonomy_xml_for_I18N_MODE_LOCALIZE($term, $path);
        }
        else {
          if ($vocab->i18n_mode == I18N_MODE_TRANSLATE) {
            $source_xml = globallink_get_taxonomy_xml_for_I18N_MODE_TRANSLATE($term, $path);
          }
        }
        $source_arr = array();
        if ($source_xml) {
          $source_arr = globallink_taxonomy_get_arr_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 {
    $arr['source'] = $source_arr;
    $arr['target'] = $translation;
  }
  return $arr;
}