You are here

function _nodehierarchy_widgets_parent_autocomplete_options in Node Hierarchy 7.2

Same name and namespace in other branches
  1. 6.3 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()
  2. 6.2 nodehierarchy_widgets/nodehierarchy_widgets.module \_nodehierarchy_widgets_parent_autocomplete_options()
  3. 7.4 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) {

    // TODO Please convert this statement to the D7 database API syntax.
    $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 :title\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(
      'title' => '%' . db_like(strtolower($string)) . '%',
    ), 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);
  return $out;
}