You are here

function _pm_permission_get_all_child_nids in Drupal PM (Project Management) 7.3

Same name and namespace in other branches
  1. 8 includes/pm.permission.inc \_pm_permission_get_all_child_nids()

Recursively hunt for child nodes of pmorganization.

1 call to _pm_permission_get_all_child_nids()
pm_permission_get_all_child_nids in includes/pm.permission.inc
Helper function to get all child nids under current node.

File

includes/pm.permission.inc, line 742
Main module file for the pm_permission module.

Code

function _pm_permission_get_all_child_nids($nids, &$result = NULL) {
  static $depth = 0;
  $depth++;
  if ($depth >= 10) {
    return;
  }
  if ($result === NULL) {
    $result = array();
    $new_ids = $nids;
  }
  else {
    $new_ids = array_diff($nids, $result);
    $result = array_merge($result, $new_ids);
    if (empty($new_ids)) {
      return;
    }
  }
  $ids = array();
  foreach ($new_ids as $nid) {
    $enabled = pm_permission_get_enabled_types();
    if ($enabled) {
      foreach ($enabled as $type) {
        $parent_field = variable_get("pm_permission_field_parent_reference_for_{$type}", NULL);
        if ($parent_field) {
          $query = new EntityFieldQuery();
          $query
            ->entityCondition('entity_type', 'node')
            ->entityCondition('bundle', array(
            $type,
          ), 'IN')
            ->fieldCondition($parent_field, 'target_id', $nid)
            ->addMetaData('account', user_load(1));
          $r = $query
            ->execute();
          if (isset($r['node'])) {
            $keys = array_keys($r['node']);
            $ids = array_merge($ids, $keys);
          }
        }
      }
    }
  }
  _pm_permission_get_all_child_nids($ids, $result);
}