You are here

function translation_overview_overview_page in Translation Overview 6

Translation overview page.

Current assumptions:

  • translated node's status is synchronized via the i18n_sync module.
1 string reference to 'translation_overview_overview_page'
translation_overview_menu in ./translation_overview.module
Implementation of hook_menu().

File

./translation_overview.pages.inc, line 175

Code

function translation_overview_overview_page() {
  drupal_add_css(drupal_get_path('module', 'translation_overview') . '/translation_overview.css');
  $rows_per_page = 30;

  // Bail if there are no translatable nodes
  if (count(translation_overview_node_types()) == 0) {
    drupal_set_message(t('There are no translateable node types on this site.'), 'error');
    return '';
  }

  // Get a list of the enabled languages
  $languages = array();
  foreach (language_list() as $key => $language) {
    if ($language->enabled) {
      $languages[$key] = $language->language;
    }
  }

  // Sort the list so the order matches the menu items.
  asort($languages);
  $header = array(
    array(
      'field' => 'n.title',
      'data' => t('Title'),
      'sort' => 'asc',
    ),
    array(
      'field' => 'n.type',
      'data' => t('Type'),
    ),
    array(
      'field' => 'n.created',
      'data' => t('Created'),
    ),
  );
  foreach ($languages as $key => $language_name) {
    $header[] = array(
      'data' => str_replace('-', '<br />', $language_name),
      'class' => 'translation-overview-lang',
    );
  }
  $query = translation_overview_build_filter_query();
  $sql = "SELECT n.nid, n.title, n.type, n.tnid, n.status, n.created, n.language, n.translate \n    FROM {node} n " . implode(' ', $query['join']) . " WHERE (n.nid = n.tnid OR n.tnid = 0) AND n.language <> '' AND n.language IS NOT NULL\n    AND " . implode(' AND ', $query['where']) . tablesort_sql($header);
  $rows = array();
  $result = pager_query(db_rewrite_sql($sql), $rows_per_page, 0, NULL, $query['args']);
  while ($node = db_fetch_object($result)) {

    // Shorten down the title so the table isn't too wide.
    $title = $node->title;
    if (drupal_strlen($title) > 20) {
      $title = drupal_substr($title, 0, 15) . '...';
    }
    $row = array(
      array(
        'data' => l($title, 'node/' . $node->nid, array(
          'attributes' => array(
            'title' => $node->title,
          ),
        )),
      ),
      array(
        'data' => check_plain($node->type),
      ),
      array(
        'data' => format_date($node->created, 'custom', 'j M Y'),
      ),
    );

    // Load the node's translations and then fill in the table with the status.
    $translations = (array) translation_node_get_translations($node->tnid);
    foreach ($languages as $language) {
      $translation_nid = empty($translations[$language]->nid) ? NULL : $translations[$language]->nid;
      $row[$language] = array(
        'data' => translation_overview_translation_link($node, $translation_nid, $language, FALSE),
        'class' => 'translation-overview-status',
      );
    }
    $rows[] = $row;
  }
  return drupal_get_form('translation_overview_filter_form') . theme('table', $header, $rows) . theme('pager', NULL, $rows_per_page);
}