You are here

function globallink_get_ready_translations_for_documents in GlobalLink Connect for Drupal 7.7

3 calls to globallink_get_ready_translations_for_documents()
globallink_background_import in ./globallink_background_jobs.inc
Imports the documents
globallink_background_pull in ./globallink_background_jobs.inc
Pull submissions or documents
globallink_content_preview_content in ./globallink_workbench_all_active_submissions.inc
Helper function

File

gl_ws/gl_ws_receive_translations.inc, line 83

Code

function globallink_get_ready_translations_for_documents($pd_obj, $document_tickets) {
  if (globallink_debug_enabled()) {
    watchdog(GLOBALLINK_MODULE, 'Connecting to PD - %pd', array(
      '%pd' => print_r($pd_obj, 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);
  $targets = $glExchange
    ->getCompletedTargetsByDocument($document_tickets, $pd_obj->maxTargetCount);
  $globallink_arr = array();
  if (isset($targets) && count($targets) > 0) {
    if (globallink_debug_enabled()) {
      watchdog(GLOBALLINK_MODULE, 'Targets Returned from GlobalLink Project Director - %targets', array(
        '%targets' => print_r($targets, TRUE),
      ), WATCHDOG_DEBUG);
    }
    $count = 1;
    if (is_array($targets)) {
      foreach ($targets as $target) {
        if (!is_null($target->ticket) && $target->ticket != '') {
          $m_arr = $target->metadata;
          $source_type = '';
          $type_id = '';
          if (is_array($m_arr)) {
            foreach ($m_arr as $m_key => $md) {
              if ($m_key == 'type') {
                $source_type = $md;
              }
              else {
                $type_id = $md;
              }
            }
          }
          $globallink = new GlobalLink();
          $globallink->submissionTicket = $target->submissionTicket;
          $globallink->submissionName = $target->submissionName;
          $globallink->documentTicket = $target->documentTicket;
          $globallink->sourceFileName = $target->documentName;
          $globallink->targetTicket = $target->ticket;
          $globallink->sourceLocale = str_replace('-', '_', $target->sourceLocale);
          $globallink->targetLocale = str_replace('-', '_', $target->targetLocale);
          $globallink->type = $source_type;
          if ($source_type != GLOBALLINK_ENTITY_TYPE_NODE && $source_type != GLOBALLINK_ENTITY_TYPE_ENTITY) {
            $globallink->otherObjectId = $type_id;
          }
          else {
            $globallink->nid = $type_id;
          }
          $globallink_arr[$count] = $globallink;
          $count++;
        }
      }
    }
  }
  return $globallink_arr;
}