API:getParentIds

From MODx Wiki
Jump to: navigation, search

Returns an array of all parent record IDs for the id passed.


Usage

  1. array getParentIds($id, $height=10, $parents=array());

Examples

  1. $parents = $modx->getParentIds(10);

will return an array of all the parents of document 10, starting at the lowest level and working upwards, using aliases as the array keys, e.g.

  1. Array
  2. (
  3. [services/accident-claims] => 3
  4. [services] => 2
  5. )

$height argument defines the maximum number of levels to go up.

Source Code

File: manager/includes/document.parser.class.inc.php
Line: 1212
function getParentIds($id, $height= 10, $parents= array ()) {
        $parentId= 0;
        foreach ($this->documentMap as $mapEntry) {
            $parentId= array_search($id, $mapEntry);
            if ($parentId) {
                $parentKey= array_search($parentId, $this->documentListing);
                if (!$parentKey) {
                    $parentKey= "$parentId";
                }
                $parents[$parentKey]= $parentId;
                break;
            }
        }
        $height--;
        if ($parentId && $height) {
            $parents= $parents + $this->getParentIds($parentId, $height, $parents);
        }
        return $parents;
    }
Personal tools