You are here

function globallink_entity_send_for_translations in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.7 globallink_entity/globallink_entity.inc \globallink_entity_send_for_translations()
  2. 7.6 globallink_entity/globallink_entity.inc \globallink_entity_send_for_translations()

Sends entities for translation.

Parameters

array $nids: The array of entity node IDs.

string $pd4: The project director details.

string $submission_name: The name of the submission.

string $due_date: When the translation is due.

string $project_code: The project's registered code.

string $source_locale: The locale of the content being translated.

array $target_locale_arr: Array of desired locales to translate into.

array $submission_details: Associative array of details about the submission.

Return value

object GlobalLink object that represents active translation.

1 call to globallink_entity_send_for_translations()
globallink_entity_dashboard_form_submit in globallink_entity/globallink_entity_send.inc
Handles entity form submission.

File

globallink_entity/globallink_entity.inc, line 26

Code

function globallink_entity_send_for_translations($nids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority) {
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_send_translations');
  module_load_include('inc', 'globallink', 'globallink');
  $node_check = variable_get('globallink_implementation_type', 0);
  $submitter = $submission_details['submitter'];
  $drupal_locale_code = globallink_get_drupal_locale_code($source_locale);
  $globallink_arr = array();
  foreach ($nids as $nid) {
    list($nid, $vid) = explode('-', $nid, 2);
    $rows = globallink_entity_get_sent_rows_by_nid($nid);
    $target_arr = $target_locale_arr;
    foreach ($rows as $row) {
      if (array_search($row->target, $target_arr)) {
        unset($target_arr[$row->target]);
      }
    }
    if (empty($target_arr)) {
      watchdog('GlobalLink', 'Target languages already sent. Skipping nid - %nid', array(
        '%nid' => $nid,
      ), WATCHDOG_WARNING);
      continue;
    }
    $node = node_load($nid, $vid);
    if ($node_check == 1) {
      foreach ($target_arr as $key => $target_locale) {
        if (!globallink_translate_node_for_language($node, globallink_get_drupal_locale_code($target_locale))) {
          unset($target_arr[$key]);
        }
      }
    }
    if (empty($target_arr)) {
      watchdog('GlobalLink', 'No target languages. Skipping nid - %nid', array(
        '%nid' => $nid,
      ), WATCHDOG_CRITICAL);
      continue;
    }
    $drupal_target_arr = array();
    foreach ($target_arr as $target_locale) {
      array_push($drupal_target_arr, globallink_get_drupal_locale_code($target_locale));
    }
    $tnid = NULL;
    $tvid = NULL;
    $name = '.xml';
    $xml = globallink_entity_get_xml($node, $drupal_target_arr, $tnid, $tvid, $name, FALSE, $drupal_locale_code);
    if (!$xml) {
      watchdog('GlobalLink', 'Cannot create XML. Skipping nid - %nid', array(
        '%nid' => $nid,
      ), WATCHDOG_CRITICAL);
      continue;
    }
    watchdog('GlobalLink', 'XML - %xml', array(
      '%xml' => $xml,
    ), WATCHDOG_INFO);
    $globallink = new GlobalLink();
    $globallink->nid = $node->nid;
    $globallink->vid = $node->vid;
    $globallink->title = $node->title;
    $globallink->type = $node->type;
    $globallink->metadata = 'entity';
    $globallink->sourceLocale = $source_locale;
    $globallink->targetLocale = $target_arr;
    $globallink->sourceXML = $xml;
    $globallink->sourceFileName = $name;
    $globallink->submissionName = $submission_name;
    $globallink->submissionPriority = $submission_priority;
    $globallink->dueDate = $due_date;
    $globallink->submissionInstructions = $submission_details['instructions'] . "\nSubmitter: " . $submitter;
    $globallink_arr[] = $globallink;
  }
  if (!empty($globallink_arr)) {
    globallink_send_documents_for_translation_to_pd($globallink_arr, $pd4, $project_code, $submitter);
  }
  return $globallink_arr;
}