You are here

function lingotek_grid_download_ready in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.4 lingotek.bulk_grid.inc \lingotek_grid_download_ready()
  2. 7.5 lingotek.bulk_grid.inc \lingotek_grid_download_ready()
  3. 7.6 lingotek.bulk_grid.inc \lingotek_grid_download_ready()
1 string reference to 'lingotek_grid_download_ready'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.bulk_grid.inc, line 1288

Code

function lingotek_grid_download_ready($entity_type, $comma_separated_ids = NULL) {
  if ($entity_type === 'config') {
    config_download_ready(NULL, $comma_separated_ids, $entity_type);
    return;
  }
  $targets = LingotekSync::getTargetsByStatuses($entity_type, array(
    LingotekSync::STATUS_READY,
    LingotekSync::STATUS_READY_INTERIM,
  ));
  if (!empty($targets)) {
    if ($comma_separated_ids !== NULL || isset($_SESSION['grid_filters'][$entity_type]) && !empty($_SESSION['grid_filters'][$entity_type])) {
      if (isset($_SESSION['grid_filters'][$entity_type])) {
        $filtered_ids = isset($_SESSION['grid_filters'][$entity_type]['filtered_ids']) ? isset($_SESSION['grid_filters'][$entity_type]['filtered_ids']) : NULL;
        empty_array_check($filtered_ids, $entity_type, "There are no translations ready for download for this filter.");
      }
      $entity_ids = $comma_separated_ids !== NULL ? explode(",", $comma_separated_ids) : $_SESSION['grid_filters'][$entity_type]['filtered_ids'];
    }
    else {
      $entity_ids = array();
      foreach ($targets as $target) {
        $entity_ids[] = $target['id'];
      }
    }
    $entities = entity_load($entity_type, $entity_ids);
    $operations = array();
    foreach ($targets as $target) {
      if (isset($entities[$target['id']]) && $entities[$target['id']]->lingotek['profile'] != LingotekSync::PROFILE_DISABLED) {

        // exclude nodes with PROFILE_DISABLED
        $operations[] = array(
          'lingotek_entity_download',
          array(
            $entities[$target['id']],
            $entity_type,
            $target['locale'],
          ),
        );
      }
    }
    $redirect = 'admin/settings/lingotek/manage/' . $entity_type;
    $batch = array(
      'title' => t('Downloading Translations'),
      'finished' => 'lingotek_sync_download_target_finished',
    );
    $batch['operations'] = $operations;
    batch_set($batch);
    batch_process($redirect);
  }
  else {
    drupal_set_message(t('There are no translations with status <i>Ready for Download</i>.'));
    drupal_goto('admin/settings/lingotek/manage/' . $entity_type);
  }
}