You are here

function lingotek_get_document_targets in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.7 lingotek.remote.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.

3 calls to lingotek_get_document_targets()
lingotek_get_workbench_url in ./lingotek.api.inc
Get the url to open the Lingotek Workbench.
lingotek_node_sync in ./lingotek.util.inc
Synchronize the node's content with current translations as stored on the Lingotek platform.
lingotek_pm in ./lingotek.page.inc
Page callback for the Lingotek local task on node detail pages.

File

./lingotek.api.inc, line 281

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)) {
    lingotek_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 ($output) {
      foreach ($output->translationTargets as $target) {
        $results[$target->language] = $target;
      }
    }
    lingotek_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;
}