You are here

function lingotek_form_bulk_sync_submit in Lingotek Translation 7.5

Same name and namespace in other branches
  1. 7.3 lingotek.sync.inc \lingotek_form_bulk_sync_submit()
  2. 7.4 lingotek.sync.inc \lingotek_form_bulk_sync_submit()

Submit handler for the lingotek_form_bulk_sync form. Calls the function that creates a batch job to do bulk sync.

Parameters

array $form: The FAPI form array.

array $form_state: The FAPI form state array.

1 string reference to 'lingotek_form_bulk_sync_submit'
lingotek_form_bulk_sync in ./lingotek.sync.inc

File

./lingotek.sync.inc, line 409
Sync and management

Code

function lingotek_form_bulk_sync_submit($form, $form_state) {
  $extra_operations = array();
  $upload_config = array();
  $download_targets_incomplete = array();
  $vals = $form_state['values'];
  if ($vals['op'] == 'Force Download All') {
    $document_ids = LingotekConfigChunk::getAllDocumentIds();
    $available_targets = Lingotek::getLanguages();
    unset($available_targets['en_US']);

    // all locales_source is assumed by i18n modules to be English
    $download_targets = array();
    foreach ($document_ids as $doc_id) {
      foreach (array_keys($available_targets) as $lang) {
        $target = new stdClass();
        $target->document_id = $doc_id;
        $target->locale = $lang;
        $download_targets[] = $target;
      }
    }
    lingotek_sync_batch_create($upload_config, $download_targets, $download_targets_incomplete, NULL, $extra_operations);
    return;
  }

  // upload config
  $upload_config = array();
  if (isset($vals['upload_config']) && $vals['upload_config'] && isset($vals['upload_config_json'])) {
    $upload_config = json_decode($vals['upload_config_json']);
  }

  //download - complete
  $download_locales_complete = array();
  if (isset($vals['download_locales_complete'])) {
    foreach ($vals['download_locales_complete'] as $locale => $enabled) {
      if ($enabled) {
        $download_locales_complete[] = $locale;
      }
    }
  }
  $document_ids = array();
  $download_targets = array();
  if (!empty($download_locales_complete) && isset($vals['download_targets_workflow_complete_json'])) {
    $all_download_targets = json_decode($vals['download_targets_workflow_complete_json']);
    foreach ($all_download_targets as $download_target) {
      if (in_array($download_target->locale, $download_locales_complete)) {
        $document_ids[] = $download_target->document_id;
        $download_targets[] = $download_target;
      }
    }
  }

  //download - incomplete
  $download_locales_incomplete = array();
  if (isset($vals['download_locales_incomplete'])) {
    foreach ($vals['download_locales_incomplete'] as $locale => $enabled) {
      if ($enabled) {
        $download_locales_incomplete[] = $locale;
      }
    }
  }
  $download_targets_incomplete = array();
  if (!empty($download_locales_incomplete) && isset($vals['download_targets_workflow_incomplete_json'])) {
    $all_download_targets = json_decode($vals['download_targets_workflow_incomplete_json']);
    foreach ($all_download_targets as $download_target) {
      if (in_array($download_target->locale, $download_locales_incomplete)) {
        $document_ids[] = $download_target->document_id;
        $download_targets_incomplete[] = $download_target;
      }
    }
  }
  $document_ids = array_unique($document_ids);
  lingotek_sync_batch_create($upload_config, $download_targets, $download_targets_incomplete, NULL, $extra_operations);
}