Get the position of a child in the tree

@param int $id
@return \UthandoCommon\Model\NestedSetInterface $row
967176
protected function getPosition($id)
    {
        $cols = [
            self::COLUMN_LEFT,
            self::COLUMN_RIGHT,
            'width' => new Expression(self::COLUMN_RIGHT . ' - ' . self::COLUMN_LEFT . ' + 1'),
        ];

        $select = $this->getSelect();

        $where = new Where;
        $where->equalTo($this->getPrimaryKey(), $id);
        $select->columns($cols)->where($where);

        $row = $this->fetchResult($select)->current();

        return $row;
    }
248160
public function getParent(string $id = null)
    {
        if (!$this->_parents || ($id !== null && !isset($this->_parents[$id]))) {
            return null;
        }

        return $id !== null ?
            $this->_parents[$id] :
            $this->_parents[array_rand($this->_parents)];
    }
132408
public function getChild(string $id): NodeInterface
    {
        if (!$this->hasChild($id)) {
            throw ChildDoesNotExistException::create($this->getId(), $id);
        }

        return $this->_children[$id];
    }
1299515
public function getById($id)
    {
        $node = $this->mainNode->getById($id);
        if (!$node) {
            return null;
        }

        return $node->getData();
    }
990168
public function getParent($id)
    {
        if ($parent = $this->qb
            ->from($this->table)
            ->where($this->parentKey, $id)
            ->get(1)) {
            if ($parent->count() == 1) {
                return $parent;
            }
        }

        return false;
    }
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;
    }
706838
public static function find_by_id($id)
	{
		$row = self::oneOrNew($id);

		if (!$row->get('id'))
		{
			return false;
		}

		return $row;
	}
1012396
public function findOneById($id)
    {
        $qb = $this->getQueryBuilder();

        return $qb
            ->leftJoin('c.rows', 'row')
            ->leftJoin('row.blocks', 'block')
            ->leftJoin('block.translations', 'translation')
            ->addSelect('row', 'block', 'translation')
            ->andWhere($qb->expr()->eq('c.id', ':id'))
            ->getQuery()
            ->useQueryCache(true)
            // TODO ->useResultCache(true, 3600, Container::getEntityTagPrefix() . '[id:'.$id.']')
            ->setParameter('id', $id)
            ->getOneOrNullResult();
    }
1305818
public function getPathwayByChildId($id)
    {

        $select = $this->getSql()->select();
        $select->from(['child' => $this->getTable()])
            ->columns([])
            ->join(
                ['parent' => $this->getTable()],
                'child.' . self::COLUMN_LEFT . ' BETWEEN parent.' . self::COLUMN_LEFT . ' AND parent.' . self::COLUMN_RIGHT,
                [Select::SQL_STAR],
                Select::JOIN_INNER
            )
            ->where(['child.' . $this->getPrimaryKey() . ' = ?' => $id])
            ->order('parent.' . self::COLUMN_LEFT);

        return $select;
    }
997155
public function getTree($id = null) {
        $parent = $this->getConfig('parentField');
        $left = $this->getConfig('leftField');
        $right = $this->getConfig('rightField');

        $query = $this->getRepository()->select()->orderBy($left, 'asc');

        if ($id) {
            if ($parentNode = $this->getNode($id)) {
                $query->where($left, 'between', [$parentNode[$left], $parentNode[$right]]);
            } else {
                return [];
            }
        }

        $nodes = $query->all();

        if ($nodes->isEmpty()) {
            return [];
        }

        $map = [];
        $stack = [];
        $pk = $this->getRepository()->getPrimaryKey();

        foreach ($nodes as $node) {
            if ($node[$parent] && $node[$pk] != $id) {
                $map[$node[$parent]][] = $node;
            } else {
                $stack[] = $node;
            }
        }

        $results = $this->mapTree($stack, $map);

        if ($id) {
            return $results[0];
        }

        return $results;
    }
510957
public function getChildren($id)
    {
        $table = $this->getTable();
        $closure = $table . '_closure';
        $tableAlias = 'c';
        $closureAlias = 'cc';
        $primaryKey = $this->mapper->getPrimaryKey($table);
        $fluent = $this->connection->command()
            ->select('%n.*', $tableAlias)
            ->from('%n AS %n', $table, $tableAlias)
            ->join('%n AS %n', $closure, $closureAlias)
            ->on('%n.%n = %n.descendant', $tableAlias, $primaryKey, $closureAlias)
            ->where('%n.ancestor = %s', $closureAlias, $id)
            ->where('%n.depth = 1', $closureAlias);

        $entityClass = $this->mapper->getEntityClass($this->getTable());
        $rc = new ReflectionClass($entityClass);
        $closureEntityClass = $entityClass . 'Closure';
        if ($rc->implementsInterface('Joseki\LeanMapper\ClosureTable\ISortable')) {
            $fluent->orderBy('%n.order', $tableAlias);
        } else if (class_exists($closureEntityClass)) {
            /** @var Entity $closureEntity */
            $closureEntity = new $closureEntityClass;
            if ($closureEntity->getReflection($this->mapper)->getEntityProperty('order')) {
                $fluent->orderBy('%n.order', $closureAlias);
            }
        }

        return $this->createEntities($fluent->fetchAll());
    }
24740
public function getChilds($id)
    {
        $result = [];
        if (array_key_exists($id, $this->finder)) {
            return $this->recursiveGetChilds($this->finder[$id][$this->config['childs']], $result);
        } else {
            return $result;
        }
    }
936465
public function getAncestry($id)
    {
        $tbl = $this->hierarchyTable;
        $recursive = "SELECT c.term_id, c.parent_id from $tbl as c join :tmp_tbl as p on p.parent_id = c.term_id";

        $raw_query = $this->assembleQuery($this->getAncestryInitialQuery(), $recursive);

        return $this->runQuery($raw_query, $id);
    }
918694
public function getById($id)
    {
        $id = (int) $id;
        $rowSet = $this->getTableGateway()->select([$this->getPrimaryKey() => $id]);
        $row = $rowSet->current();
        return $row;
    }
9953
public static function oneOrNew($id)
	{
		$row = self::one($id);

		// See if we have a valid row
		if ($row === false)
		{
			$row = self::blank();
		}

		return $row;
	}
645411
public function getElementById($id)
    {
        // start with document
        $stack = array($this);

        while (!empty($stack)) {
            $elem = array_pop($stack);
            // check current node
            if ($elem->getAttribute('id') === $id) {
                return $elem;
            }
            // add children to stack (tree order traversal)
            if ($elem instanceof SVGNodeContainer) {
                for ($i = $elem->countChildren() - 1; $i >= 0; --$i) {
                    array_push($stack, $elem->getChild($i));
                }
            }
        }

        return null;
    }
327176
public function getOneById($id)
    {
        $id = (string)$id;

        $fields = implode(', ', $this->fields);
        $sql = 'SELECT ' . $fields . ' FROM ' . $this->table . ' WHERE ' . $this->table . '.id = :id';
        $query = $this->pdo->prepare($sql);
        $query->bindParam(':id', $id);
        $query->execute();

        return $query->fetch(PDO::FETCH_ASSOC);
    }