Index: relativity.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/relativity/relativity.module,v retrieving revision 1.46.2.6 diff -u -p -r1.46.2.6 relativity.module --- relativity.module 20 Apr 2009 21:07:09 -0000 1.46.2.6 +++ relativity.module 8 Jul 2009 10:17:09 -0000 @@ -35,6 +35,23 @@ function relativity_node_list($use_blank } /** + * Lists the children of a given parent node. + * + * @param int $parent_nid The node id of the node for which you want the children + * @return array of child node objects + */ +function relativity_list_children($parent_nid) { + $child_nodes = array(); + + $result = db_query('SELECT nid FROM {relativity} WHERE parent_nid = %d', $parent_nid); + while ($child = db_fetch_object($result)) { + $child_nodes[] = node_load($child->nid); + } + + return $child_nodes; +} + +/** * Lists nodes that could be attached to a given parent type. * * TODO: @@ -1564,12 +1581,9 @@ function theme_relativity_show_children( $output = ''; // load all nodes associated with this one as the parent nid and show links to all of them. - $result = db_query('SELECT nid FROM {relativity} WHERE parent_nid = %d', $parent->nid); - while ($child = db_fetch_object($result)) { - $child_nodes[] = node_load($child->nid); - } - if (!is_array($child_nodes)) return ''; - + $child_nodes = relativity_list_children($parent->nid); + if (!is_array($child_nodes) || count($child_nodes) == 0) return ''; + $childrentypes = relativity_childrentypes($parent); // sorted list of types foreach ($childrentypes as $childtype) { @@ -1643,12 +1657,11 @@ function theme_relativity_show_link_oper $parent_nid = $parent->nid; $output = relativity_get_operation_links($parent); - // show child removal links - $result = db_query('SELECT nid FROM {relativity} WHERE parent_nid = %d', $parent_nid); $output = ($output ? $output .'
' : ''); - while ($child = db_fetch_object($result)) { - $child_node = node_load($child->nid); - // make sure that no dependencies exist that would require this node to be attached + + // show child removal links + $child_nodes = relativity_list_children($parent_nid); + foreach($child_nodes as $child_node) { if (relativity_may_unchild($parent, $child_node)) { $removables[] = $child_node; }