You are here

function lingotek_grid_get_rows in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.bulk_grid.inc \lingotek_grid_get_rows()
  2. 7.4 lingotek.bulk_grid.inc \lingotek_grid_get_rows()
  3. 7.5 lingotek.bulk_grid.inc \lingotek_grid_get_rows()

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

Return value

array $table_data Returns array of rows Populates The Grid

1 call to lingotek_grid_get_rows()
lingotek_bulk_grid_form in ./lingotek.bulk_grid.inc

File

./lingotek.bulk_grid.inc, line 1209

Code

function lingotek_grid_get_rows($entity_type, $form, &$form_state, $count_only = FALSE) {
  $info = entity_get_info($entity_type);
  $entity_id_key = $info['entity keys']['id'];
  $eid = 'n.' . $entity_id_key;
  $entity_properties = array_flip($info['schema_fields_sql']['base table']);
  $label_col = isset($info['entity keys']['label']) && $info['entity keys']['label'] ? $info['entity keys']['label'] : NULL;
  $bundle_col = isset($info['entity keys']['bundle']) && $info['entity keys']['bundle'] && isset($entity_properties[$info['entity keys']['bundle']]) ? $info['entity keys']['bundle'] : NULL;

  // All managed entity types should have a language column.
  // Field collection entities have one, but it is called 'langcode'.
  // Message type entities have one, and it is called 'language'; but currently it does not appear in their entity keys.
  // So, the $language_col looks for the correct language field, and then guesses it is 'language' if it doesn't find one.
  $language_col = !empty($info['entity keys']['language']) ? $info['entity keys']['language'] : 'language';
  $entity_properties['type'] = $entity_type;
  $entity_properties['label_col'] = $label_col;
  $entity_properties['info'] = $info;
  $entity_properties['language_col'] = $language_col;
  $limit = isset($_SESSION['limit_select']) ? $_SESSION['limit_select'] : 10;
  $columns = isset($form_state['values']['columns']) ? $form_state['values']['columns'] : array();
  $header = array(
    // Define the tentative source header
    'nid' => array(
      'data' => t('ID'),
      'field' => 'n.' . $entity_id_key,
    ),
    'content_type' => array(
      'data' => t('Content Type'),
      'field' => 'type',
    ),
    'title' => array(
      'data' => t('Title'),
      'field' => 'n.' . $label_col,
    ),
    'description' => array(
      'data' => t('Description'),
    ),
    'language' => array(
      'data' => t('Source Uploaded'),
    ),
    //, 'field' => 'upload_status'),
    'translations' => array(
      'data' => t('Translations'),
      'field' => 't_current_c',
    ),
    'configuration' => array(
      'data' => t('Profile'),
    ),
    'workflow' => array(
      'data' => t('Workflow'),
      'field' => 'workflow',
    ),
    'document_id' => array(
      'data' => t('Doc ID'),
      'field' => 'document_id',
    ),
    'changed' => array(
      'data' => t('Last Modified'),
      'field' => 'changed',
    ),
    'last_uploaded' => array(
      'data' => t('Last Uploaded'),
      'field' => 'last_uploaded',
    ),
    'actions' => array(
      'data' => t('Actions'),
    ),
    'translation_status' => array(
      'data' => t('Translation Status'),
    ),
    'last_downloaded' => array(
      'data' => t('Last Downloaded'),
      'field' => 'last_downloaded',
    ),
    'translate_link' => array(
      'data' => t('Translate'),
    ),
  );
  if (!isset($entity_properties['changed'])) {
    unset($header['changed']);
  }
  if (!$label_col) {
    unset($header['title']);
  }

  // Taxonomy terms require special handling of bundles because they do not
  // have a bundle column in their table.
  if (!$bundle_col && $entity_type != 'taxonomy_term') {
    unset($header['content_type']);
  }
  if (isset($entity_properties['changed'])) {
    $header['changed']['sort'] = 'desc';
  }
  $form_state['values']['grid_header'] = lingotek_bulk_grid_refine_source_header($header, $columns);
  $query = lingotek_bulk_grid_query($form_state, $count_only, $entity_id_key, $label_col, $entity_type, $limit, $bundle_col, $info, $entity_properties, $eid);

  // Initialize Query and extend paginator and tablesort if necessary
  lingotek_bulk_grid_filter_query($query, $entity_type, $eid, $label_col, $info);

  // If count only, return the count
  if ($count_only) {
    $result = $query
      ->execute();
    return $result
      ->rowCount();
  }

  // Execute the query
  $table_data_raw = $query
    ->distinct()
    ->execute()
    ->fetchAllAssoc($entity_id_key);
  lingotek_entity_load($table_data_raw, $entity_type);

  // Parse returned objects and make them arrays keyed by the Node ID for clean use in The Grid.
  $table_data = lingotek_bulk_grid_parse_table_data($table_data_raw, $entity_properties, $entity_id_key);
  return $table_data;
}