Recursively finds all children of node with given id

@param $id
@param $data
@param $hidden
3130
private static function treeGoDown($id, $data, &$hidden)
    {
        foreach ($data as $row) {
            if ($row['parent_id'] == $id) {
                if (false === in_array($row['id'], $hidden)) {
                    $hidden[] = $row['id'];
                }
                self::treeGoDown($row['id'], $data, $hidden);
            }
        }
    }
128590
public function getParentCategory(HasNodeInterface $page, $hidden = false)
    {
        $breadcrumbs = $this->getBreadcrumbs($page, $hidden);

        // chop of current page, as it cant be it’s own parent:
        $breadcrumbs = array_slice($breadcrumbs, 0, -1);

        return end($breadcrumbs) ?: null;
    }
1008287
public function findNode(string $id, $searchChildren = false)
    {
        return $this->findByIdAmongChildren($id, $this->nodes(), $searchChildren);
    }
339089
public function run($id = null, $contextId = null)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        if (false === Yii::$app->user->can('dotplant-structure-view')) {
            throw new ForbiddenHttpException(Yii::t(
                'yii', 'You are not allowed to perform this action.'
            ));
        }
        /** @var BaseStructure | string $class */
        if (null === $current_selected_id = Yii::$app->request->get($this->querySelectedAttribute)) {
            $current_selected_id = Yii::$app->request->get($this->queryParentAttribute);
        }
        $checked = Yii::$app->request->get('checked', '');
        $cacheKey = "AdjacencyFullTreeData:{$this->cacheKey}:{$this->querySortOrder}:{$id}:{$contextId}"
            . Yii::$app->multilingual->language_id . $this->showHiddenInTree . $checked;
        if (false === empty($checked)) {
            $checked = explode(',', $checked);
        } else {
            $checked = [];
        }
        if (false === $result = Yii::$app->cache->get($cacheKey)) {
            $contexts = call_user_func([Yii::$app->multilingual->modelsMap['Context'], 'getListData']);
            /** @var ActiveQuery $query */
            $parentId = ('#' == $id) ? null : $id;
            $query = BaseStructure::find()
                ->where(['parent_id' => $parentId])
                ->orderBy([
                    $this->contextIdAttribute => SORT_ASC,
                    $this->querySortOrder => SORT_ASC
                ]);
            if (count($this->whereCondition) > 0) {
                $query = $query->where($this->whereCondition);
            }
            if ($contextId != 'all') {
                $query->andWhere([$this->contextIdAttribute => $contextId]);
            }

            $entityId = (null !== $this->className) ? Entity::getEntityIdForClass($this->className) : null;
            if (null === $rows = $query->asArray()->all()) {
                return [];
            }
            $result = [];
            $hidden = [];
            $roots = BaseStructure::find()->select(['id'])->where(['is_deleted' => 1])->column();
            $hidden += $roots;
            foreach ($roots as $id) {
                self::treeGoDown($id, $rows, $hidden);
            }
            foreach ($rows as $row) {
                if ((int)$row['expand_in_tree'] === 1) {
                    $c = (new Query())
                        ->from(BaseStructure::tableName())
                        ->where(['parent_id' => $row['id']])
                        ->select('id')
                        ->count();
                    $children = $c > 0;
                } else {
                    $children = false;
                }
                $item = [];
                if (true === in_array($row[$this->modelIdAttribute], $hidden)) {
                    if (true === $this->showHiddenInTree) {
                        self::setState($item, ['disabled' => true]);
                    } else {
                        continue;
                    }
                }
                $text = ($row[$this->modelParentAttribute] > 0)
                    ? $row['defaultTranslation'][$this->modelLabelAttribute]
                    : ($row['defaultTranslation'][$this->modelLabelAttribute]
//                        . " ({$contexts[$row[$this->contextIdAttribute]]})"
                    );
                $item += [
                    'id' => $row[$this->modelIdAttribute],
                    'parent' => ($row[$this->modelParentAttribute] > 0) ? $row[$this->modelParentAttribute] : '#',
                    'text' => $text,
                    'children' => $children,
                    'a_attr' => [
                        'data-id' => $row[$this->modelIdAttribute],
                        'data-parent_id' => $row[$this->modelParentAttribute],
                        'data-context_id' => $row[$this->contextIdAttribute],
                        'data-entity_id' => $row['entity_id'],
                    ],
                ];
                if (null !== $entityId && $entityId != $row['entity_id']) {
                    self::setState($item, ['checkbox_disabled' => true]);
                }
                if (true === in_array($row[$this->modelIdAttribute], $checked)) {
                    self::setState($item, ['opened' => true, 'checked' => true, 'selected' => true]);
                }
                if (null !== $this->varyByTypeAttribute) {
                    $item['type'] = $row[$this->varyByTypeAttribute];
                }
                $result[$row[$this->modelIdAttribute]] = $item;
            }

            Yii::$app->cache->set(
                $cacheKey,
                $result,
                86400,
                new TagDependency([
                    'tags' => [
                        NamingHelper::getCommonTag(BaseStructure::class),
                    ],
                ])
            );
        }

        if (array_key_exists($current_selected_id, $result)) {
            $result[$current_selected_id] = array_merge(
                $result[$current_selected_id],
                ['state' => ['opened' => true, 'selected' => true]]
            );
        }

        return array_values($result);
    }
454800
public function getChildren(Node $node, $includeHiddenFromNav = true)
    {
        $this->init();
        $children = array();

        if (array_key_exists($node->getId(), $this->childNodes)) {
            $nodes = $this->childNodes[$node->getId()];
            /* @var Node $childNode */
            foreach ($nodes as $childNode) {
                $nodeTranslation = $childNode->getNodeTranslation(
                    $this->locale,
                    $this->includeOffline
                );
                if (!is_null($nodeTranslation)) {
                    $children[] = new NodeMenuItem(
                        $childNode,
                        $nodeTranslation,
                        false,
                        $this
                    );
                }
            }

            $children = array_filter(
                $children,
                function (NodeMenuItem $entry) use ($includeHiddenFromNav) {
                    if ($entry->getNode()->isHiddenFromNav(
                        ) && !$includeHiddenFromNav
                    ) {
                        return false;
                    }

                    return true;
                }
            );
        }

        return $children;
    }
413553
public function unset_hidden(string $id_imess, string $id_user){
    $cfg =& $this->class_cfg;
    if ( !empty($id_imess) && !empty($id_user) ){
      return !!$this->db->update_ignore($cfg['tables']['users'], [
        $cfg['arch']['users']['id_imessage'] => $id_imess,
        $cfg['arch']['users']['id_user'] => $id_user,
        $cfg['arch']['users']['hidden'] => 0,
        $cfg['arch']['users']['moment'] => date('Y-m-d H:i:s'),
      ], [
        $cfg['arch']['users']['id_imessage'] => $id_imess,
        $cfg['arch']['users']['id_user'] => $id_user
      ]);
    }
    return false;
  }
128053
public function addChildren($id, $data) {
		// find
		$model = $this->get($id);

		if ($model === null) {
			return new NotFound(['message' => 'Skill not found.']);
		}

		// pass add to internal logic
		try {
			$this->doAddChildren($model, $data);
		} catch (ErrorsException $e) {
			return new NotValid(['errors' => $e->getErrors()]);
		}

		// save and dispatch events
		$this->dispatch(SkillEvent::PRE_CHILDREN_ADD, $model, $data);
		$this->dispatch(SkillEvent::PRE_SAVE, $model, $data);
		$rows = $model->save();
		$this->dispatch(SkillEvent::POST_CHILDREN_ADD, $model, $data);
		$this->dispatch(SkillEvent::POST_SAVE, $model, $data);

		if ($rows > 0) {
			return Updated(['model' => $model]);
		}

		return NotUpdated(['model' => $model]);
	}
169487
public function children($id = null)
    {
        $id = ($id == null) ? $this->root : $id;
        foreach ($this->data as $v) {
            if ($v[$this->fields[1]] == $id) {
                $result[$v[$this->fields[0]]] = $v;
            }
        }
        return isset($result) ? $result : null;
    }
1335184
public function write($id, $data, $next)
    {
        $this->handler->write($id, $data);die;
        return $next($id, $data);
    }
1256242
function reveal(el) {
      if (el.hasChildNodes()) {
        // dealing with a container try and find children
        var els = el.querySelectorAll('[data-src], [data-bkg]');
        var elsl = els.length;
        if (elsl === 0) {
          // node has children, but none have the attributes, so reveal
          // the node itself (use case: div with a background)
          doReveal(el);
        } else {
          for (var j = 0; j < elsl; j++) {
            doReveal(els[j]);
          }
        }
      } else {
        doReveal(el);
      }
    }
756695
protected static function _retrieveNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
    {
        $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
        return self::_nestedResourceOperation('get', $url, $params, $options);
    }
73598
public function find_item($id, $suppresserror = false) {
        if (isset($this->items)) {
            foreach ($this->items as $key => $child) {
                if ($child->id == $id) {
                    return $this->items[$key];
                }
            }
            foreach (array_keys($this->items) as $key) {
                $thischild = $this->items[$key];
                $ref = $thischild->children->find_item($id, true);//error always reported at top level
                if ($ref !== null) {
                    return $ref;
                }
            }
        }

        if (!$suppresserror) {
            print_error('listnoitem');
        }
        return null;
    }
921687
@Override
    public R visitHidden(HiddenTree node, P p) {
        return defaultAction(node, p);
    }
906031
function find(data) {
                if (data === this.data) {
                    return this;
                }

                if (this.children) {
                    for (var i = 0, _length = this.children.length, target = null; i < _length; i++) {
                        target = this.children[i].find(data);
                        if (target) {
                            return target;
                        }
                    }
                }

                return null;
            }
1281830
public function setHidden($hidden): void
    {
        if ($this->isHidden() === $hidden) {
            return;
        }
        $this->materializeNodeDataAsNeeded();
        $this->nodeData->setHidden($hidden);

        $this->context->getFirstLevelNodeCache()->flush();
        $this->emitNodeUpdated($this);
    }
374828
public static function getTreeParent($data, $id, $key = 'parent_id', $id_key = 'id') {
		$result = [];
		$obj    = [];
		foreach ($data as $node) {
			$obj[$node[$id_key]] = $node[$key];
		}
		while ($id) {
			if (isset($obj[$id])) {
			    break;
            }
            if (in_array($obj[$id], $result)) {
			    // 数组有问题，陷入死循环，提前退出
			    break;
            }
            $result[] = $obj[$id];
            $id = $obj[$id];
		}
		unset($obj);
		return array_reverse($result);
	}
532970
public function hide($id)
    {
        $sourceNodeData = $this->locationGateway->getBasicNodeData($id);

        $this->locationGateway->hideSubtree($sourceNodeData['path_string']);
    }