You are here

function organigrams_item_get_children in Organigrams 7

Finds all children of an organigrams item ID.

Parameters

int $iid: An organigrams item ID.

Return value

array An array of organigrams item objects which are the children of the organigrams item.

1 call to organigrams_item_get_children()
organigrams_item_delete in ./organigrams.module
Delete an organigrams item.
1 string reference to 'organigrams_item_get_children'
organigrams_items_static_reset in ./organigrams.module
Clear all static cache variables for organigrams items.

File

./organigrams.module, line 1825
Defines the organigrams functions and entity types.

Code

function organigrams_item_get_children($iid) {

  // Retrieve static cache.
  $children =& drupal_static(__FUNCTION__, array());

  // Validate iid argument and check if the static cache has an entry.
  if ($iid && !isset($children[$iid])) {

    // Retrieve organigrams item children.
    $query = db_select('organigrams_item_data', 'oid');
    $query
      ->addTag('organigrams_item_access');
    $query
      ->addField('oid', 'iid');
    $query
      ->condition('oid.parent', $iid);
    $query
      ->orderBy('oid.weight');
    $query
      ->orderBy('oid.name');
    $iids = $query
      ->execute()
      ->fetchCol();

    // Load the full object for each organigrams item and save to static cache.
    $children[$iid] = organigrams_item_load_multiple($iids);
  }

  // Return the static cached version.
  return isset($children[$iid]) ? $children[$iid] : array();
}