/[drupal]/contributions/modules/nodeorder/nodeorder.admin.inc
ViewVC logotype

Contents of /contributions/modules/nodeorder/nodeorder.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Wed Apr 22 18:45:19 2009 UTC (7 months, 1 week ago) by pvanderspek
Branch: MAIN
Changes since 1.1: +134 -0 lines
File MIME type: text/x-php
merged changes from 6.x branch into HEAD
1 <?php
2 // $Id: nodeorder.admin.inc,v 1.1.2.8 2009/01/17 16:36:04 pvanderspek Exp $
3
4 /**
5 * @file
6 * Admin page callbacks for the nodeorder module.
7 */
8
9 /**
10 * Menu callback for nodeorder/order.
11 */
12 function nodeorder_admin_display($tid) {
13 return drupal_get_form('nodeorder_admin_display_form', $tid);
14 }
15
16 /**
17 * Generate main blocks administration form.
18 */
19 function nodeorder_admin_display_form(&$form_state, $tid) {
20 // Build form tree
21 $form = array(
22 '#tree' => TRUE
23 );
24
25 $term = taxonomy_get_term($tid);
26 drupal_set_title(t('Order nodes for <em>%term_name</em>', array( '%term_name' => $term->name)));
27
28 $order = 'n.sticky DESC, tn0.weight_in_tid';
29 $result = nodeorder_select_nodes(array($tid), 'and', 0, FALSE, $order, 0);
30 $nodes = array();
31 $node_count = 1;
32 $options = array();
33 while ($node = db_fetch_object($result)) {
34 if (!isset($node->nodeorder)) {
35 $node->nodeorder = array();
36
37 // Store an element called 'nodeorder' that contains
38 // an associative array of tid to weight_in_tid...
39 $weights = db_query('SELECT tid, weight_in_tid FROM {term_node} WHERE nid = %d', $node->nid);
40 while ($term_node = db_fetch_object($weights)) {
41 $node->nodeorder[$term_node->tid] = $term_node->weight_in_tid;
42 }
43 }
44
45 $nodes[] = $node;
46 $options[$node_count] = $node_count;
47 $node_count++;
48 }
49
50 // Weights range from -delta to +delta, so delta should be at least half
51 // of the amount of blocks present. This makes sure all blocks in the same
52 // region get an unique weight.
53 $weight_delta = round($node_count / 2);
54
55 $list_tr_id = 'node-sort-list-'. $tid;
56 foreach ($nodes as $node) {
57 $key = $list_tr_id .'_'. $node->nid;
58
59 $form[$key]['tid'] = array(
60 '#type' => 'value',
61 '#value' => $tid,
62 );
63 $form[$key]['nid'] = array(
64 '#type' => 'value',
65 '#value' => $node->nid,
66 );
67 $form[$key]['info'] = array(
68 '#value' => check_plain($node->title),
69 );
70 $form[$key]['weight'] = array(
71 '#type' => 'select',
72 '#default_value' => $node->nodeorder[$tid],
73 '#options' => $options
74 );
75 }
76
77 $form['submit'] = array(
78 '#type' => 'submit',
79 '#value' => t('Save order'),
80 '#disabled' => TRUE
81 );
82
83 return $form;
84 }
85
86 /**
87 * Process main blocks administration form submission.
88 */
89 function nodeorder_admin_display_form_submit($form, &$form_state) {
90 $sql = "UPDATE {term_node} SET weight_in_tid = %d WHERE tid = %d AND nid = %d";
91 $tid = -1;
92
93 foreach ($form_state['values'] as $node) {
94 // Only take form elements that are blocks.
95 if (is_array($node) && array_key_exists('tid', $node)) {
96 db_query($sql, $node['weight'], $node['tid'], $node['nid']);
97
98 $tid = $node['tid'];
99 }
100 }
101
102 drupal_set_message(t('The node orders have been updated.'));
103 cache_clear_all();
104
105 $form_state['redirect'] = 'nodeorder/term/'. $tid;
106 return;
107 }
108
109 /**
110 * Process variables for nodeorder-admin-display.tpl.php.
111 *
112 * The $variables array contains the following arguments:
113 * - $form
114 *
115 * @see nodeorder-admin-display.tpl.php
116 * @see theme_nodeorder_admin_display()
117 */
118 function template_preprocess_nodeorder_admin_display_form(&$variables) {
119 foreach (element_children($variables['form']) as $i) {
120 $node = &$variables['form'][$i];
121
122 // Only take form elements that are nodes.
123 if (is_array($node) && array_key_exists('info', $node)) {
124 $variables['form'][$i]['weight']['#attributes']['class'] = 'nodeorder-weight';
125 $variables['node_listing'][$i]->row_class = isset($block['#attributes']['class']) ? $block['#attributes']['class'] : '';
126 $variables['node_listing'][$i]->node_title = drupal_render($node['info']);
127 $variables['node_listing'][$i]->weight = drupal_render($node['weight']);
128 $variables['node_listing'][$i]->tid = drupal_render($node['tid']);
129 $variables['node_listing'][$i]->nid = drupal_render($node['nid']);
130 }
131 }
132
133 $variables['form_submit'] = drupal_render($variables['form']);
134 }

  ViewVC Help
Powered by ViewVC 1.1.2