You are here

function lingotek_download_translations_form in Lingotek Translation 7.7

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

Download Translations Form.

1 string reference to 'lingotek_download_translations_form'
lingotek_pm in ./lingotek.page.inc
Page callback for the Lingotek local task on node detail pages.

File

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

Code

function lingotek_download_translations_form($form, $form_state, $node, $document = NULL) {
  module_load_include('inc', 'lingotek', 'lingotek.bulk_grid');
  $form = array();
  $document = is_null($document) ? LingotekDocument::load($node->lingotek['document_id']) : $document;
  $document_progress = $document
    ->getProgress();
  $document_id = $node->lingotek['document_id'] ?: '';
  $sum_progress = 0;
  if ($document_progress->results == 'success') {
    $lang_rows = array();
    $phase_rows = array();
    foreach ($document_progress->translationTargets as $target) {
      $current_phase = $document
        ->currentPhase($target->id);
      $marked_complete = FALSE;
      $phase_complete_percent = is_object($current_phase) ? $current_phase->percentComplete : 0;
      if (empty($phase_complete_percent)) {
        $phase_complete_percent = 0;
      }

      //$language_link = l(lingotek_language_field_lookup('native', $target->language), lingotek_get_workbench_url($document_id, $target->language), array('attributes' => array('target' => '_blank')));
      $language_link = lingotek_get_workbench_url($document_id, $target->language, lingotek_language_field_lookup('native', $target->language));
      $language_name = lingotek_language_field_lookup('name', $target->language);
      $language_link .= ' / ' . $language_name . ' (' . $target->language . ')';
      $lang_row = array(
        'column_1' => array(
          'data' => $language_link,
          'width' => '40%',
        ),
        'column_2' => array(
          'data' => lingotek_grid_create_progress_bar($target->percentComplete),
          'width' => '40%',
        ),
        'column_3' => array(
          'data' => '',
        ),
        //$target->percentComplete == 100 ? '<i class="fa fa-check-sign ltk-complete-check" title="'.t('Workflow complete').'"></i>' : '<i class="fa fa-check-empty ltk-complete-check"></i>', 'width' => '20%'
        '#attributes' => array(
          'class' => array(
            'bold-row',
          ),
        ),
        'language_name' => $language_name,
        // We append zzzz as a dirty trick, so es and es19, e.g. are separated
        // properly. If not, the rows of one are added to the other.
        'locale' => $target->language . 'zzzz',
      );
      LingotekLog::trace("lingotek_pm table row [@locale]", array(
        '@locale' => $target->language,
      ));
      $lang_rows[$target->language] = $lang_row;
      foreach ($target->phases as $phase) {
        $phase_row = array(
          'column_1' => $phase->name,
          'column_2' => lingotek_grid_create_progress_bar($phase->percentComplete),
          'column_3' => $phase->isMarkedComplete ? '<i class="fa fa-check-sign ltk-complete-check" title="' . t('Phase complete') . '"></i>' : '<i class="fa fa-check-empty ltk-complete-check"></i>',
          '#attributes' => array(
            'class' => array(
              'no-checkbox-row',
            ),
          ),
          'language_name' => $language_name,
          'locale' => $target->language . 'zzzz',
        );
        $phase_rows[$target->language . '_' . $phase->name] = $phase_row;
        $marked_complete = $phase->isMarkedComplete;
      }

      // update progress
      $lingotek_locale = $target->language;
      $progress_percentage = empty($target->percentComplete) ? 0 : $target->percentComplete;
      $sum_progress += $progress_percentage;
      $target_status_local = lingotek_keystore('node', $node->nid, 'target_sync_status_' . $lingotek_locale);
      if ($target_status_local === LingotekSync::STATUS_PENDING) {
        $target_status = $marked_complete ? LingotekSync::STATUS_READY : LingotekSync::STATUS_PENDING;
        lingotek_keystore('node', $node->nid, 'target_sync_status_' . $lingotek_locale, $target_status);
      }
    }

    // Sort rows by language name
    $lang_rows_sorted = array();
    foreach ($lang_rows as $key => $row) {
      $lang_rows_sorted[$key] = $row['locale'];
    }
    array_multisort($lang_rows_sorted, SORT_ASC, $lang_rows);

    // Combine lang_rows and phase_rows in alphabetical order
    $rows = array();
    foreach ($lang_rows as $lang_key => $lang_row) {
      unset($lang_row['locale']);
      $rows[$lang_key] = $lang_row;
      foreach ($phase_rows as $phase_key => $phase_row) {
        unset($phase_row['locale']);
        if (strpos($phase_key, $lang_key) !== FALSE) {
          $rows[$phase_key] = $phase_row;
        }
      }
    }
    $form['fieldset'] = array(
      '#type' => 'fieldset',
      '#title' => t('Download Translations'),
      '#description' => t('Download the latest translations from Lingotek in the selected languages.'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $header = array(
      'column_1' => t('Target Language'),
      'column_2' => t('Progress'),
      'column_3' => t('Status'),
    );
    $form['fieldset']['documents'] = array(
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $rows,
      '#empty' => t('No content available.'),
      '#after_build' => array(
        'lingotek_remove_checkboxes',
      ),
    );
    $form['fieldset']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Download'),
    );
    $form['fieldset']['nid'] = array(
      '#type' => 'value',
      '#value' => $node->nid,
    );
  }
  return $form;
}