You are here

function lingotek_bulk_grid_parse_table_data in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.6 lingotek.bulk_grid.inc \lingotek_bulk_grid_parse_table_data()
1 call to lingotek_bulk_grid_parse_table_data()
lingotek_grid_get_rows in ./lingotek.bulk_grid.inc
Dynamic query processing function for the grid Since the header defines which columns are shown, this query gets all possible values and refines the header using the columns selected in the UI The filters are also processed here

File

./lingotek.bulk_grid.inc, line 2313

Code

function lingotek_bulk_grid_parse_table_data($table_data_raw, $entity_properties, $entity_id_key) {
  global $language;
  $languages = language_list();
  $profiles = lingotek_get_profiles();
  $api = LingotekApi::instance();
  $workflows = $api
    ->listWorkflows();
  $table_data = array();
  $node_based_translations = array();
  foreach ($table_data_raw as $row) {
    if ($row->language !== $language->language) {
      $node_based_translations[] = $row->{$entity_id_key};
    }
    $entity_id = $row->{$entity_id_key};
    $entity_type = $entity_properties['type'];
    $row->title = lingotek_truncate_grid_text($row->title, 55);
    $locales_statuses = lingotek_build_locales_statuses($row);
    ksort($locales_statuses);
    $document_id = $row->document_id ?: '';
    $disabled = $row->lingotek['profile'] == LingotekSync::PROFILE_DISABLED;
    $disabled_class = $disabled ? ' ltk-disabled-icon' : '';
    $allow_source_overwriting = !empty($row->lingotek['allow_source_overwriting']);
    $allow_target_localization = !empty($row->lingotek['allow_target_localization']);
    $translation_icons = lingotek_lang_icons($entity_properties['type'], $entity_id, $document_id, $row->lingotek['profile'], $locales_statuses, $disabled, $row->language, $allow_source_overwriting, $allow_target_localization, array());

    // show translation statuses
    if (!empty($translation_icons['source'])) {
      $row->overridden_source_target_icon = $translation_icons['source'];
      unset($translation_icons['source']);
    }
    $target_icons_str = implode('', array_values($translation_icons));
    $configuration = lingotek_render_configuration($row, $profiles, $disabled_class);
    $source = lingotek_render_source($entity_properties['type'], $row, $languages, $entity_properties['language_col'], $entity_properties);
    $marked_html = lingotek_render_marked_html($row, $entity_type, $entity_id);
    $actions = lingotek_render_actions($entity_properties, $entity_id, $disabled_class);
    $title = $entity_properties['label_col'] ? lingotek_render_title($row, $entity_properties) : '';
    $workflow_id = !empty($row->lingotek['workflow_id']) ? $row->lingotek['workflow_id'] : '';
    $workflow_name = array_key_exists($workflow_id, $workflows) ? $workflows[$workflow_id] : '';

    // Build the data to be output for this row
    $data = array(
      'marked' => $marked_html,
      'nid' => $row->{$entity_id_key} ?: t('??'),
      'title' => $title,
      'label' => isset($row->label) ? $row->label : '',
      'language' => $source,
      'translations' => $target_icons_str,
      'configuration' => $configuration,
      'document_id' => $row->document_id ?: t('N/A'),
      'content_type' => isset($entity_properties['info']['bundles'][$row->type]['label']) ? $entity_properties['info']['bundles'][$row->type]['label'] : $row->type,
      'last_uploaded' => $row->last_uploaded ? t('@time ago', array(
        '@time' => lingotek_human_readable_timestamp($row->last_uploaded),
      )) : t('Never'),
      'workflow_id' => $workflow_id,
      'workflow_name' => $workflow_name,
      'actions' => '<span class="lingotek-node-actions">' . $actions . '</span>',
      'description' => isset($row->description) ? $row->description : '',
    );
    if ($entity_type === 'paragraphs_item') {
      list($parent_id, $parent_title) = lingotek_get_paragraph_parent_info($entity_type, $entity_id);
      $data['parent_node_id'] = $parent_id;
      $data['paragraph_snippet'] = lingotek_get_paragraph_snippet($entity_type, $entity_id);
    }
    if (isset($entity_properties['changed'])) {
      $data['changed'] = $row->changed ? t('@time ago', array(
        '@time' => lingotek_human_readable_timestamp($row->changed),
      )) : t('Never');
    }
    $table_data[$entity_id] = $data;
  }
  $entity_type = $entity_properties['type'];
  if (!empty($node_based_translations)) {
    if ($entity_type === 'node') {
      $query = db_select('node', 'n');
      $query
        ->addField('n', 'title');
      $query
        ->addField('n', 'tnid');
      $query
        ->addField('n', 'nid');
      $query
        ->condition('n.tnid', $node_based_translations, 'IN');
      $query
        ->condition('n.language', $language->language);
      $results = $query
        ->execute();
      foreach ($results as $result) {
        if (isset($table_data[$result->tnid])) {
          $table_data[$result->tnid]['title'] = l(t($result->title), $entity_properties['type'] . "/{$result->nid}");
        }
      }
    }
  }
  return $table_data;
}