You are here

function organigrams_item_get_suitable_parents_options in Organigrams 7

Generate a list of suitable parents for the given organigrams item.

This function is suitable for selection form elements.

Parameters

int $iid: An organigrams item ID.

int $oid: An organigrams ID.

Return value

array An associative array of parents, keyed by the organigrams item ID and the name as value.

1 call to organigrams_item_get_suitable_parents_options()
organigrams_form_organigrams_item in ./organigrams_item.admin.inc
Create or edit form for an organigrams item.

File

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

Code

function organigrams_item_get_suitable_parents_options($iid, $oid) {

  // Initialize the parent relation options.
  $parent_relation_options = array();

  // Retrieve the children.
  $children = organigrams_get_tree($oid, $iid);

  // Construct excluded iids.
  $excluded_iids = array();
  foreach ($children as $child) {
    $excluded_iids[] = $child->iid;
  }
  $excluded_iids[] = $iid;

  // Iterate through the organigrams tree.
  foreach (organigrams_get_tree($oid) as $tree_item) {

    // Do not allow the excluded iids as parent.
    if (!in_array($tree_item->iid, $excluded_iids)) {

      // Add organigrams item name to the parent options.
      $parent_relation_options[$tree_item->iid] = str_repeat('-', $tree_item->depth) . filter_xss_admin($tree_item->name);
    }
  }

  // Return the suitable parent options.
  return $parent_relation_options;
}