You are here

function translation_admin_nodes in Internationalization 5.2

Same name and namespace in other branches
  1. 5.3 translation/translation.module \translation_admin_nodes()
  2. 5 translation/translation.module \translation_admin_nodes()

Form builder. Administrative form for node translations

1 string reference to 'translation_admin_nodes'
translation_admin_content in translation/translation.module
Menu callback: administration page for node translations

File

translation/translation.module, line 527

Code

function translation_admin_nodes() {

  // First, translation filter because it may need parameters for join conditions
  $filter = translation_build_filter_query();
  $where = $filter['where'];
  $params = $filter['args'];
  $join = $filter['join'];

  // Now we add in conditions from the node admin filter subform
  $filter = node_build_filter_query();

  // Remove WHERE and merge all conditions. The WHERE part from node filter was a string with 'WHERE..'
  if (!empty($filter['where'])) {
    $where += array_merge($where, array(
      str_replace('WHERE', '', $filter['where']),
    ));
  }
  if (!empty($filter['args'])) {
    $params = array_merge($params, $filter['args']);
  }
  if (!empty($filter['join'])) {
    $join .= ' ' . $filter['join'];
  }
  $sql = "SELECT n.nid, n.type, n.title, n.status, u.name, u.uid, i.language, i2.nid AS translation_nid, i2.status AS translation_status " . "FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {i18n_node} i ON n.nid = i.nid " . "LEFT JOIN {i18n_node} i2 ON i.trid = i2.trid AND 0 <> i2.trid AND i.language <> i2.language {$join}" . (count($where) ? ' WHERE ' . implode(' AND ', $where) : '');

  // Fetch data

  //drupal_set_message("DEBUG:query: $sql");

  //drupal_set_message("DEBUG:params: ".implode(', ', $params));
  i18n_selection_mode('off');
  $result = pager_query(db_rewrite_sql($sql), 50, 0, NULL, $params);
  i18n_selection_mode('reset');
  $languages = i18n_supported_languages();
  $translation_status = _translation_status();

  // Fetch language for translations
  $language = isset($_SESSION['translation_filter']['translation_language']) ? $_SESSION['translation_filter']['translation_language'] : i18n_get_lang();
  $destination = drupal_get_destination();
  while ($node = db_fetch_object($result)) {
    $nodes[$node->nid] = '';
    $form['language'][$node->nid] = array(
      '#value' => $languages[$node->language],
    );
    $form['title'][$node->nid] = array(
      '#value' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', node_mark($node->nid, $node->changed)),
    );
    $form['name'][$node->nid] = array(
      '#value' => node_get_types('name', $node),
    );
    $form['username'][$node->nid] = array(
      '#value' => theme('username', $node),
    );
    $form['status'][$node->nid] = array(
      '#value' => $node->status ? t('published') : t('not published'),
    );
    if ($node->translation_nid) {
      $form['translation_status'][$node->nid] = array(
        '#value' => $translation_status[$node->translation_status],
      );
      $form['operations'][$node->nid] = array(
        '#value' => l(t('edit translation'), 'node/' . $node->translation_nid . '/edit', array(), $destination),
      );
    }
    else {
      $form['translation_status'][$node->nid] = array(
        '#value' => '--',
      );
      if ($language == $node->language) {
        $form['operations'][$node->nid] = array(
          '#value' => '--',
        );
      }
      else {
        $prefix = variable_get('i18n_translation_links', 0) ? i18n_get_lang() : $language;
        $form['operations'][$node->nid] = array(
          '#value' => l(t('create translation'), $prefix . '/node/add/' . $node->type, array(), "translation={$node->nid}&language={$language}") . ' | ' . l(t('select node'), "node/{$node->nid}/translation/select/{$language}", array(), $destination),
        );
      }
    }
  }

  /*
  $form['nodes'] = array('#type' => 'checkboxes', '#options' => $nodes);
  */
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}