You are here

function lingotek_pm in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.7 lingotek.page.inc \lingotek_pm()
  2. 7.3 lingotek.page.inc \lingotek_pm()
  3. 7.4 lingotek.page.inc \lingotek_pm()
  4. 7.5 lingotek.page.inc \lingotek_pm()
  5. 7.6 lingotek.page.inc \lingotek_pm()

Page callback for the Lingotek local task on node detail pages.

Construct the table summarizing information a Product Manager would want to know about the progress of the translations.

Return value

array A Drupal render array of the page contents.

1 string reference to 'lingotek_pm'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.page.inc, line 175
Lingotek Tab for Nodes

Code

function lingotek_pm($node) {

  // Display all of the appropriate node management sections (e.g., Upload, Download, Publish)
  // If we have a language prefix, then drupal_get_path will append that to the front of the string it returns.  So lets strip it back off, so it doesn't break the paths.
  $icon_green_check = base_path() . drupal_get_path('module', 'lingotek') . '/images/ico_tick_17x.png';
  $output = array();
  drupal_add_js(drupal_get_path('module', 'lingotek') . '/js/lingotek.pm.js');
  if (class_exists('LingotekDocument')) {
    $checkbox = '<input type="checkbox" onchange="lingotek.pm.toggle_checkboxes(this);" />';
    $headers = array(
      $checkbox,
      t('Language'),
      t('Document Progress'),
      t('Phase'),
      t('Phase Progress'),
      t('Phase Complete'),
    );
    $document = LingotekDocument::load(lingotek_lingonode($node->nid, 'document_id'));
    $targets = lingotek_get_document_targets($document->document_id, TRUE);
    $rows = array();
    foreach ($targets as $lingotek_locale => $target) {
      $current_phase = $document
        ->currentPhase($target->id);
      $phase_complete = $current_phase->isMarkedComplete ? TRUE : FALSE;
      $phase_complete_percent = $current_phase->percentComplete;
      if (empty($phase_complete_percent)) {
        $phase_complete_percent = 0;
      }
      $language_link = l(lingotek_language_field_lookup('native', $lingotek_locale), '', array(
        'attributes' => array(
          'onclick' => 'window.open(\'' . lingotek_get_workbench_url($node, $lingotek_locale) . '\'); return false;',
        ),
      ));
      $language_link .= ' ' . t('(@language_name)', array(
        '@language_name' => lingotek_language_field_lookup('name', $lingotek_locale),
      ));
      $row = array(
        '<input type="checkbox" tag="lingotek_pm_row" language="' . $lingotek_locale . '" />',
        $language_link,
        $target->percentComplete . '%',
        $current_phase->name,
        $phase_complete_percent . '%',
        $phase_complete ? '<img src="' . $icon_green_check . '" />' : '',
      );
      lingotek_trace("lingotek_pm table row", array(
        'language' => $lingotek_locale,
      ));
      $rows[] = $row;
    }
    $table = theme('table', array(
      'header' => $headers,
      'rows' => $rows,
    ));
    $actions = '<input type="button" id="lingotek-update-button" value="' . t('Download') . '" class="form-submit"/>';
    $vars = '<input type="hidden" id="lingotek_nid" value="' . $node->nid . '" />';
    $token_element = array(
      '#type' => 'hidden',
      '#attributes' => array(
        'id' => 'submit-token',
      ),
      '#value' => drupal_get_token(),
    );
    $vars .= drupal_render($token_element);
    $download_translations = array();
    $download_translations['fieldset'] = array(
      '#type' => 'fieldset',
      '#title' => t('Download Translations'),
      '#description' => t('Download the latest translations from Lingotek in the selected languages.'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $download_translations['fieldset']['contents'] = array(
      '#markup' => $table . $actions . $vars,
    );
    if (lingotek_supported_type($node->type) && lingotek_supported_language($node->language)) {
      $content_push_form = drupal_get_form('lingotek_push_form', $node);
      $output['content_push'] = array(
        '#markup' => lingotek_lingonode($node->nid, 'create_lingotek_document') ? '' : drupal_render($content_push_form),
      );
      if (!empty($rows)) {
        $output['content_pull'] = array(
          '#markup' => drupal_render($download_translations),
        );
      }
    }
    else {
      $output['content_pull'] = array(
        '#markup' => '<p class="help">' . t('This node is not compatible with Lingotek translation. Either it is not a Lingotek tranlsation-enabled content type or the node does not have a defined language.') . '</p>',
      );
    }

    // Add the mark as complete table if there are complete-eligible phrases.
    if ($document
      ->hasPhasesToComplete()) {
      $drupal_phase_complete_from = drupal_get_form('lingotek_mark_phases_complete', $node);
      $output['mark_complete'] = array(
        '#markup' => drupal_render($drupal_phase_complete_from),
      );
    }
    $lingotek_advanced_parsing_form = drupal_get_form('lingotek_advanced_parsing_upgrade_form');
    $output['upgrade_form'] = array(
      '#markup' => drupal_render($lingotek_advanced_parsing_form),
    );

    // Publish form
    $output['publish_form'] = drupal_get_form('lingotek_publish_form', $node);
  }
  return $output;
}