获取子代节点

@param      $id
@param bool $all 是否获取全部子级
true: 是
false: 取得自己下一层的子代

@return Collection
506768
public function getChildren($id, bool $all = false): Collection
    {
        if (! $all) {
            return $this->repo->pushCriteria(new GetChildren($id))->all();
        } else {
            return $this->repo->pushCriteria(new GetChildAll($id))->all();
        }
    }
269329
public static function allRevisions($id, $params = null, $opts = null)
    {
        return self::_allNestedResources($id, static::PATH_REVISIONS, $params, $opts);
    }
1039180
public function _id($_id = false)
    {

        $this->_id = $_id;

        $this->filter[] = ["term" => ["_id" => $_id]];

        return $this;
    }
382492
public function get_item($id)
	{
		// Element empty!
		if (count($this->_items) === 0)
			return FALSE;

		if (array_key_exists($id, $this->_items))
		{ // By ID
			return $this->_items[$id];
		} else
		{ // By route
			$path = $this->get_tree_index(Route::get($id));

			if($path != false)
			{
				$levels = count($path);

				$item = $this->_items[$path[0]];

				if($levels > 1)
				{
					for($i=1; $i<$levels; $i++)
					{
						$item = $item->siblings[$path[$i]];
					}
				}
				return $item;
			}
		}
		return FALSE;
	}
1245908
protected static function cache_get_by_id($id) {
        if (isset(self::$cache_contextsbyid[$id])) {
            return self::$cache_contextsbyid[$id];
        }
        return false;
    }
1107430
protected static function build_tree($all, $parentid) {
        $tree = array();
        foreach ($all as $one) {
            if ($one->get('parentid') == $parentid) {
                $node = new stdClass();
                $node->competency = $one;
                $node->children = self::build_tree($all, $one->get('id'));
                $tree[] = $node;
            }
        }
        return $tree;
    }
1369020
public function getChildById($id)
    {
        foreach ($this->children as $child) {
            if ($child->id === $id) {
                return $child;
            }

            $subChild = $child->getChildById($id);
            if ($subChild !== null) {
                return $subChild;
            }
        }

        return null;
    }
749913
public function all($id = null)
    {
        if (!is_int($id)) {
            return $this->get('/repositories');
        }

        return $this->get('/repositories?since='.rawurldecode($id));
    }
1032317
public function is($id, $role, $all = true)
    {
        if (! $user = $this->findUserById($id)) {
            return false;
        }

        return $user->is($role, $all);
    }
793456
public function without($id): self
    {
        if (!is_array($id)) {
            $id = (array) $id;
        }

        $items = $this->filter(function ($element) use ($id) {
            return !in_array($element->id(), $id, true);
        })->all();

        $this->items = array_values($items);

        return $this;
    }
1063719
public function findById($id)
    {
        $result = array();
        $relations = $this->getRelations();

        $items = $relations[RelationBuilder::TREE_PARAM_ITEMS];

        if (isset($items[$id])) {
            return $items[$id];
        } else {
            return false;
        }
    }
501281
public function stageChildren($showAll = false) {
		// if we don't have an ID directly, we should load and return ALL the external content sources
		if (!$this->ID) {
			return DataObject::get('ExternalContentSource');
		}

		$children = new ArrayList();
		return $children;
	}
1026671
public function getMultilevelChildren($id, array $options = [])
	{
		$options['for']    = $id;
		$options['direct'] = false;

		$options['for']    = $id;
		$options['direct'] = false;

		$query    = $this->_table->find();
		$iterator = $this->findChildren($query, $options);

		$primaryKey = $this->_table->getSchema()->primaryKey();
		$primaryKey = count($primaryKey) == 1 ? $primaryKey[0] : $primaryKey;

		$parent_id_fieldname = $this->getConfig('model_parent_id_fieldname');

		$nodes_by_pk = [];
		$root_nodes  = [];

		foreach($iterator as $node)
		{
			$nodes_by_pk[$node->{$primaryKey}] = $node;

			if($node->{$parent_id_fieldname} == $id)
			{
				$root_nodes[] = $node;
			}

			if(isset($nodes_by_pk[$node->{$parent_id_fieldname}]))
			{
				if(!isset($nodes_by_pk[$node->{$parent_id_fieldname}]->children))
				{
					$nodes_by_pk[$node->{$parent_id_fieldname}]->children = [];
				}

				$nodes_by_pk[$node->{$parent_id_fieldname}]->children[] = $node;
			}
		}
		unset($node);

		return new \Cake\Collection\Collection($root_nodes);
	}
1107000
public function getById($id)
    {
        if ($this->id == $id) return $this;

        return $this->children->getById($id);
    }
999930
public function menu($id)
    {
        $this->loadModel('Menu.Menus');
        $menu = $this->Menus->get($id);
        $links = $this->Menus->MenuLinks->find()
            ->where(['menu_id' => $menu->id])
            ->order(['lft' => 'ASC'])
            ->all()
            ->map(function ($link) {
                $link->set('expanded', true);

                return $link;
            })
            ->nest('id', 'parent_id');

        if (!empty($this->request->data['tree_order'])) {
            $items = json_decode($this->request->data['tree_order']);

            if (!empty($items)) {
                unset($items[0]);
                $entities = [];

                foreach ($items as $key => $item) {
                    $link = $this->Menus->MenuLinks->get($item->item_id);
                    $link = $this->Menus->MenuLinks->patchEntity($link, [
                        'parent_id' => intval($item->parent_id),
                        'lft' => intval(($item->left - 1)),
                        'rght' => intval(($item->right - 1)),
                    ], ['validate' => false]);
                    $entities[] = $link;
                }

                $this->Menus->MenuLinks->connection()->transactional(function () use ($entities) {
                    foreach ($entities as $entity) {
                        $result = $this->Menus->MenuLinks->save($entity);
                        if (!$result) {
                            return false;
                        }
                    }

                    return true;
                });

                // don't trust "left" and "right" values coming from user's POST
                $this->Menus->MenuLinks->addBehavior('Tree', ['scope' => ['menu_id' => $menu->id]]);
                $this->Menus->MenuLinks->recover();
                $this->Flash->success(__d('menu', 'Menu has been reordered'));
            } else {
                $this->Flash->danger(__d('menu', 'Invalid information, check you have JavaScript enabled'));
            }

            $this->redirect($this->referer());
        }

        $disabledIds = $links
            ->match(['status' => false])
            ->extract('id')
            ->toArray();

        $this->title(__d('menu', 'Menu’s Links'));
        $this->set(compact('menu', 'links', 'disabledIds'));
        $this->Breadcrumb
            ->push('/admin/menu/manage')
            ->push(__d('menu', 'Editing menu'), ['plugin' => 'Menu', 'controller' => 'manage', 'action' => 'edit', $menu->id])
            ->push(__d('menu', 'Links'), '#');
    }
844203
public function findParentNodesByChildId($id)
	{
        // To be returned
        $result = array();

        $rl = $this->getRelations();
        $data = $rl[RelationBuilder::TREE_PARAM_ITEMS];

        // If can't find, then return empty array
        if (!isset($data[$id])) {
            return array();
        }

        $current = $data[$id];
        $parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];

        while (isset($data[$parentId])) {
            $current = $data[$parentId];
            $parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];

            array_push($result, $current);
        }

        return $result;
    }
938036
public function has($id, $permission, $all = true)
    {
        if (! $user = $this->findUserById($id)) {
            return false;
        }

        return $user->has($permission, $all);
}