You are here

function lingotek_get_workbench_url_by_phases in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.3 lingotek.api.inc \lingotek_get_workbench_url_by_phases()
  2. 7.4 lingotek.api.inc \lingotek_get_workbench_url_by_phases()
  3. 7.6 lingotek.remote.inc \lingotek_get_workbench_url_by_phases()

Get the url to open the Lingotek Workbench.

This fetches a link.

Parameters

object $node: A Drupal node.

$lingotek_locale: A target language.

mixed $label: The label to use as text for the link. Possible values are TRUE, FALSE, or a string to use as a the custom label for the link.

bool $force: Force the link to use the label of the first returned workflow phase for the target Document.

Return value

string Either a link pointing the the url, or the url itself if $label is FALSE

1 call to lingotek_get_workbench_url_by_phases()
lingotek_get_workbench_url in ./lingotek.remote.inc
Get the url to open the Lingotek Workbench.

File

./lingotek.remote.inc, line 613

Code

function lingotek_get_workbench_url_by_phases($document_id, $phases, $label = FALSE, $force = FALSE) {
  $phase_id = -1;
  $which_phase = 0;
  foreach ($phases as $phase) {
    if (!$phase->isMarkedComplete || $force) {
      $phase_id = $phase->id;
      break;
    }
    $which_phase++;
  }

  // All phases are complete, use last phase as current.
  if (!empty($phases) && $phase_id == -1) {
    $last_phase = end($phases);
    $phase_id = $last_phase->id;
  }
  $l = '';
  if ($phase_id != -1) {
    if ($document_id && ($workbench_url = LingotekApi::instance()
      ->getWorkbenchLink($document_id, $phase_id))) {
      if ($label === FALSE) {
        $l = $workbench_url;
      }
      else {
        $path = $workbench_url;
        if ($label === TRUE) {
          $label = lingotek_get_phase_name($phase_id);
        }
        list($nid, $entity_type) = LingotekSync::getEntityIdFromDocId($document_id);
        $l = l($label, '', array(
          'attributes' => array(
            'onclick' => 'window.open(\'' . $path . '\'); return false;',
            'onmouseover' => 'jQuery("#node-' . $nid . '").addClass("lingotek-highlight");',
            'onmouseout' => 'jQuery("#node-' . $nid . '").removeClass("lingotek-highlight");',
          ),
        ));
      }
    }
  }
  return $l;
}