You are here

function lingotek_bulk_grid_parse_config_data in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.6 lingotek.config.inc \lingotek_bulk_grid_parse_config_data()
2 calls to lingotek_bulk_grid_parse_config_data()
lingotek_config_get_rows in ./lingotek.config.inc
lingotek_row_status_query in ./lingotek.config.inc

File

./lingotek.config.inc, line 342
Config grid form elements

Code

function lingotek_bulk_grid_parse_config_data($table_data_raw, $entity_type, $status_query = FALSE) {
  $lingotek_languages = Lingotek::getLanguages();
  $lids = array_keys($table_data_raw);
  $existing_translations = !empty($lids) ? lingotek_config_add_existing_translations($lids, $lingotek_languages) : array();
  $global_profile = lingotek_get_global_profile();
  $row_status = array();
  $table_data = array();
  if ($status_query === FALSE) {
    $non_lingotek_config_translations = lingotek_get_locked_config_translations($lids);
    $api = LingotekApi::instance();
    $workflows = $api
      ->listWorkflows();
    $languages = language_list();
  }
  $i18n_language = variable_get('i18n_string_source_language', language_default()->language);
  foreach ($table_data_raw as $row) {
    $lid = $row->{'lid'};
    $document_id = $row->document_id ?: '';
    $config_set_id = isset($row->{'config_set_id'}) ? $row->{'config_set_id'} : 'N/A';
    $row->lingotek = $global_profile;
    $row->lingotek['profile'] = 1;
    $row->language = $i18n_language;
    $locale_statuses = lingotek_build_locales_statuses($row, FALSE);
    $item_is_current = LingotekConfigSet::isLidCurrent($lid);
    $item_has_translations = array_key_exists($lid, $existing_translations);
    $source_was_edited = $row->source_edited && $item_is_current !== FALSE ? explode(',', $row->source_edited) : array();
    $item_belongs_to_set = !empty($locale_statuses);
    if ($source_was_edited) {
      $row->upload_status = LingotekSync::STATUS_EDITED;
      foreach ($source_was_edited as $key => $lang) {
        $locale = Lingotek::convertDrupal2Lingotek($lang);
        $locale_statuses[$locale] = 'edited';
      }
    }
    $not_uploaded_to_lingotek = !$item_has_translations && $item_is_current;
    ksort($locale_statuses);
    if ($item_belongs_to_set) {
      if ($not_uploaded_to_lingotek) {
        unset($locale_statuses);
        $locale_statuses = array();
        $row->upload_status = NULL;
      }
    }
    elseif ($item_has_translations) {

      // No translations in locales + translations in locales_target = Untracked.
      foreach ($existing_translations[$lid] as $existing_locale) {
        $locale_statuses[$existing_locale] = 'untracked';
      }
    }
    if ($status_query === TRUE) {
      $row_status[$lid] = $locale_statuses;
      if (isset($row->status)) {
        $row_status[$lid]['source_status'] = $row->upload_status;
      }
      continue;
    }
    $escaped_source = htmlentities($row->{'source'});
    $source_text = lingotek_truncate_grid_text($escaped_source, 55);
    $translation_icons = lingotek_lang_icons($entity_type, $lid, $document_id, NULL, $locale_statuses, FALSE, $row->language, FALSE, FALSE, $non_lingotek_config_translations);

    // show translation statuses
    $target_icons_str = implode('', array_values($translation_icons));
    $source_uploaded = lingotek_render_source($entity_type, $row, $languages, 'language');
    $set_id = LingotekConfigSet::getSetId($lid, FALSE);
    $marked_html = lingotek_render_marked_html($row, 'config', $lid);
    $set_name = $set_id !== FALSE ? LingotekConfigSet::getTitleBySetId($set_id) : t('N/A');
    $config_profile = LingotekProfile::loadById(LingotekSync::PROFILE_CONFIG);
    $stored_workflow_id = $config_profile
      ->getWorkflow();
    if (isset($row->{'workflow_id'}) && array_key_exists($row->{'workflow_id'}, $workflows)) {
      $workflow = $workflows[$row->{'workflow_id'}];
    }
    elseif (array_key_exists($stored_workflow_id, $workflows)) {
      $workflow = $workflows[$stored_workflow_id];
    }
    else {
      $workflow = '';
    }
    $data = array(
      'marked' => $marked_html,
      'config_set_id' => $config_set_id,
      'lid' => $lid ?: t('??'),
      'source' => '<a class="tooltips">' . $source_text . '<span>' . $escaped_source . '</span></a>',
      'source_uploaded' => $source_uploaded,
      'location' => $row->{'location'},
      'context' => $row->{'context'},
      'textgroup' => $row->{'textgroup'} == 'default' ? 'built-in interface' : $row->{'textgroup'},
      'translations' => $target_icons_str,
      'doc_id' => $row->document_id ? $row->document_id : t('N/A'),
      'set_name' => '<span class="set_name">' . $set_name . '</span>',
      'workflow' => $workflow,
    );
    $table_data[$lid] = $data;
  }
  if ($status_query === TRUE) {
    return $row_status;
  }
  return $table_data;
}