You are here

function globallink_send_documents_for_translation_to_pd in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 gl_ws/gl_ws_send_translations.inc \globallink_send_documents_for_translation_to_pd()
  2. 7.6 gl_ws/gl_ws_send_translations.inc \globallink_send_documents_for_translation_to_pd()
1 call to globallink_send_documents_for_translation_to_pd()
globallink_background_send in ./globallink_background_jobs.inc

File

gl_ws/gl_ws_send_translations.inc, line 16

Code

function globallink_send_documents_for_translation_to_pd(&$globallink_arr, $pd_obj, $submission) {
  if (globallink_debug_enabled()) {
    watchdog(GLOBALLINK_MODULE, 'Connecting to PD - %pd', array(
      '%pd' => print_r($submission, TRUE),
    ), WATCHDOG_DEBUG);
  }
  $connectorConfig = new PDConfig();
  $connectorConfig->url = $pd_obj->url;
  $connectorConfig->username = $pd_obj->username;
  $connectorConfig->password = $pd_obj->password;
  $connectorConfig->userAgent = $pd_obj->userAgent;
  $glExchange = new GLExchange($connectorConfig);
  $glExchange
    ->initSubmission($submission);
  $client_identifier = rand() . $submission->project->shortcode . REQUEST_TIME;
  foreach ($globallink_arr as $gl) {
    foreach ($gl as $globallink) {
      $document = new PDDocument();
      $document->name = $globallink->sourceFileName;
      $document->encoding = 'UTF-8';
      $document->fileformat = $pd_obj->classifier;
      $document->clientIdentifier = $client_identifier;
      $document->sourceLanguage = str_replace('_', '-', $globallink->sourceLocale);
      $document->targetLanguages = str_replace('_', '-', $globallink->targetLocale);
      $document->data = $globallink->sourceXML;
      $md_arr = array();
      $md_arr['type'] = $globallink->metadata;
      if ($globallink->metadata != GLOBALLINK_ENTITY_TYPE_NODE && $globallink->metadata != GLOBALLINK_ENTITY_TYPE_ENTITY) {
        $md_arr['type_id'] = $globallink->otherObjectId;
      }
      else {
        $md_arr['type_id'] = $globallink->nid;
      }
      $document->metadata = $md_arr;
      if (globallink_debug_enabled()) {
        watchdog(GLOBALLINK_MODULE, 'Doc - %pd', array(
          '%pd' => print_r($document, TRUE),
        ), WATCHDOG_DEBUG);
      }
      $ticket = $glExchange
        ->uploadTranslatable($document);

      //$globallink->submissionTicket = $ticket->submissionTicket;
      $globallink->documentTicket = $ticket;
    }
  }
  $submission_ticket = $glExchange
    ->startSubmission();
  foreach ($globallink_arr as $gl) {
    foreach ($gl as $globallink) {
      $globallink->submissionTicket = $submission_ticket;
    }
  }
}