You are here

function _nodehierarchy_parent_options in Node Hierarchy 7.2

Same name and namespace in other branches
  1. 6.3 nodehierarchy.module \_nodehierarchy_parent_options()
  2. 6.2 nodehierarchy.module \_nodehierarchy_parent_options()
  3. 7.4 nodehierarchy.admin.inc \_nodehierarchy_parent_options()

Return a list of menu items that are valid possible parents for the given node.

1 call to _nodehierarchy_parent_options()
_nodehierarchy_get_parent_selector in ./nodehierarchy.module
Get the parent selector pulldown.

File

./nodehierarchy.module, line 1599
A module to make nodes hierarchical.

Code

function _nodehierarchy_parent_options($child_type, $exclude = NULL) {
  static $options = array();

  // If these options have already been generated, then return that saved version.
  if (isset($options[$child_type][$exclude])) {
    return $options[$child_type][$exclude];
  }

  // Get all the possible parents.
  $types = nodehierarchy_get_allowed_parent_types();
  foreach ($types as $i => $type) {
    $types[$i] = "'{$type}'";
  }

  // Get the items with menu links.
  $result = $items = $mlids = array();
  if ($types) {
    $result = db_query("SELECT n.nid, n.type as type, n.title as title, n.uid as uid, ml.*, IF(depth IS NULL, 1, depth) as depth, IF(ml.mlid IS NULL, CONCAT('nid:', n.nid), ml.mlid) as mlid, ml.mlid as linkid\n                           FROM {node} n\n                      LEFT JOIN {nodehierarchy_menu_links} nh_parent\n                             ON nh_parent.nid = n.nid\n                      LEFT JOIN {menu_links} ml\n                             ON ml.mlid = nh_parent.mlid\n                          WHERE (ml.module = 'nodehierarchy' OR ml.module IS NULL)\n                            AND n.type IN (" . implode(', ', $types) . ")\n                          ORDER BY IF(p1 IS NULL, n.created, 0) ASC, p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", array(), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
  }

  // Flatten tree to a list of options.
  $parent_types = nodehierarchy_get_allowed_parent_types($child_type);
  $out = nodehierarchy_tree_data($result, $exclude, $parent_types);

  // Static caching to prevent these options being built more than once.
  $options[$child_type][$exclude] = $out;
  return $out;
}