You are here

function nodeorder_admin_display_form in Node Order 6

Same name and namespace in other branches
  1. 7 includes/nodeorder.admin.inc \nodeorder_admin_display_form()

Generate main blocks administration form.

1 string reference to 'nodeorder_admin_display_form'
nodeorder_admin_display in ./nodeorder.admin.inc
Menu callback for nodeorder/order.

File

./nodeorder.admin.inc, line 18
Admin page callbacks for the nodeorder module.

Code

function nodeorder_admin_display_form(&$form_state, $tid) {

  // Build form tree
  $form = array(
    '#tree' => TRUE,
  );
  $term = taxonomy_get_term($tid);
  drupal_set_title(t('Order nodes for <em>%term_name</em>', array(
    '%term_name' => $term->name,
  )));
  $order = 'n.sticky DESC, tn0.weight_in_tid';
  $result = nodeorder_select_nodes(array(
    $tid,
  ), 'and', 0, FALSE, $order, 0);
  $nodes = array();
  $node_count = 1;
  $options = array();
  while ($node = db_fetch_object($result)) {
    if (!isset($node->nodeorder)) {
      $node->nodeorder = array();

      // Store an element called 'nodeorder' that contains
      // an associative array of tid to weight_in_tid...
      $weights = db_query('SELECT tid, weight_in_tid FROM {term_node} WHERE nid = %d', $node->nid);
      while ($term_node = db_fetch_object($weights)) {
        $node->nodeorder[$term_node->tid] = $term_node->weight_in_tid;
      }
    }
    $nodes[] = $node;
    $options[$node_count] = $node_count;
    $node_count++;
  }

  // Weights range from -delta to +delta, so delta should be at least half
  // of the amount of blocks present. This makes sure all blocks in the same
  // region get an unique weight.
  $weight_delta = round($node_count / 2);
  $list_tr_id = 'node-sort-list-' . $tid;
  foreach ($nodes as $node) {
    $key = $list_tr_id . '_' . $node->nid;
    $form[$key]['tid'] = array(
      '#type' => 'value',
      '#value' => $tid,
    );
    $form[$key]['nid'] = array(
      '#type' => 'value',
      '#value' => $node->nid,
    );
    $form[$key]['info'] = array(
      '#value' => check_plain($node->title),
    );
    $form[$key]['weight'] = array(
      '#type' => 'select',
      '#default_value' => $node->nodeorder[$tid],
      '#options' => $options,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save order'),
    '#disabled' => TRUE,
  );
  return $form;
}