You are here

function lingotek_get_document_targets in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.2 lingotek.api.inc \lingotek_get_document_targets()
  2. 7.3 lingotek.api.inc \lingotek_get_document_targets()
  3. 7.4 lingotek.api.inc \lingotek_get_document_targets()
  4. 7.5 lingotek.remote.inc \lingotek_get_document_targets()
  5. 7.6 lingotek.remote.inc \lingotek_get_document_targets()

Get the target language objects for a Lingotek document associated with a node.

Parameters

int $document_id: A Lingotek Document ID.

bool $flush_cache: Whether or not to force a refresh from the server, as opposed to using cached data.

Return value

array An array of translation target items.

File

./lingotek.remote.inc, line 653

Code

function lingotek_get_document_targets($document_id, $flush_cache = FALSE) {
  global $_lingotek_client;
  $targets =& drupal_static(__FUNCTION__);

  // Use static cache to ensure that we don't go to the server more than once per page for targets.
  if (isset($targets[$document_id])) {
    return $targets[$document_id];
  }
  $results = array();
  $cache_id = 'lingotek_targets_' . $document_id;
  $cache = cache_get($cache_id);
  if (lingotek_do_cache() && !$flush_cache && !empty($cache->data)) {
    LingotekLog::trace("lingotek_get_document_targets USING CACHE", array(
      'document_id' => $document_id,
      'flushCache' => $flush_cache,
    ));
    $results = $cache->data;
  }
  else {
    $output = LingotekApi::instance()
      ->getDocument($document_id);
    if (!empty($output->translationTargets)) {
      foreach ($output->translationTargets as $target) {
        $results[$target->language] = $target;
      }
    }
    LingotekLog::trace("lingotek_get_document_targets GENERATING NEW CACHE DATA getDocument", array(
      'document_id' => $document_id,
      'flushCache' => $flush_cache,
    ));
    $targets[$document_id] = $results;
    if (!empty($results)) {
      cache_set($cache_id, $results, 'cache', time() + 900);
    }
  }
  return $results;
}