You are here

function _nodehierarchy_widgets_parent_autocomplete_options in Node Hierarchy 6.3

Same name and namespace in other branches
  1. 6.2 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()
  2. 7.4 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()
  3. 7.2 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()

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

2 calls to _nodehierarchy_widgets_parent_autocomplete_options()
nodehierarchy_widgets_autocomplete_parent in nodehierarchy_widgets/nodehierarchy_widgets.module
Page callback for autocomplete.
_nodehierarchy_widgets_autocomplete_parent_validate in nodehierarchy_widgets/nodehierarchy_widgets.module
Validate a node hierarchy autocomplete in the format 'Tile [nid:xx]' or '[nid:xx]' or 'Title'.

File

nodehierarchy_widgets/nodehierarchy_widgets.module, line 84
Alternative parent selector widgets for Node Hierarchy.

Code

function _nodehierarchy_widgets_parent_autocomplete_options($child_type, $exclude = NULL, $string = NULL) {

  // 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.
  $items = $mlids = $tree = array();
  if ($types) {
    $result = db_query("SELECT n.nid, n.type as type, n.title as title, 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                            AND  LOWER(n.title) LIKE LOWER('%%%s%%')\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", $string);
  }

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