You are here

function nodehierarchy_get_node_parents in Node Hierarchy 7.4

Same name and namespace in other branches
  1. 6.3 nodehierarchy.module \nodehierarchy_get_node_parents()
  2. 6.2 nodehierarchy.module \nodehierarchy_get_node_parents()
  3. 7.2 nodehierarchy.module \nodehierarchy_get_node_parents()

Get all the parents for the given node.

4 calls to nodehierarchy_get_node_parents()
nodehierarchy_get_node_parent_nids in ./nodehierarchy.api.inc
Get the parent nodes for the given node.
nodehierarchy_get_node_parent_primary in ./nodehierarchy.api.inc
Get the primary parent nid for the given node.
nodehierarchy_node_load in ./nodehierarchy.module
Implements hook_node_load().
nodehierarchy_prepare_node in ./nodehierarchy.admin.inc
Set a default parent when the node is being prepared for the edit screen.

File

./nodehierarchy.api.inc, line 146
API functions for Node Hierarchy

Code

function nodehierarchy_get_node_parents($node, $limit = NULL) {
  $cnid = $node;

  // If a node object was passed, then the parents may already have been loaded.
  if (is_object($node)) {
    if (isset($node->nodehierarchy_parents)) {
      return $node->nodehierarchy_parents;
    }
    $cnid = $node->nid;
  }
  $out = array();
  $query = db_select('nodehierarchy', 'nh')
    ->fields('nh')
    ->where('cnid = :cnid', array(
    ':cnid' => $cnid,
  ))
    ->orderBy('pweight', 'ASC');
  if ($limit) {
    $query
      ->range(0, $limit);
  }
  $result = $query
    ->execute()
    ->fetchAll();
  foreach ($result as $item) {
    $out[] = $item;
  }
  return $out;
}