Normalizes 'parent' query parameter for list parent update.

@param mixed $parent
@return int|null
774455
protected function normalizeListParentParameter($parent)
    {
        $separator = $this->getListParentSeparator();

        if (is_integer($parent) && $parent < 0 || is_string($parent) && preg_match('#-\d+#', $parent)) {
            $parent = (int) $parent;

            if ($parent < 0) {
                // The the parent that conforms to the index in the parent chain
                // This only works within the context of this model, so no cross-model logic is expected
                $index = count($this->listParents) + $parent - 1;

                if ($index >= 0 && isset($this->listParents[ $index ])) {
                    $parent = $this->listParents[ $index ]->relation . $separator . $this->listParents[ $index ]->key;
                } else {
                    $parent = null;
                }

            } else {
                $parent = null;
            }
        }

        if (is_string($parent) && false === strpos($parent, $separator)) {
            $parent = null;
        }

        return $parent;
    }
29351
public function parent($id = '')
    {
        // Return value
        if (empty($id)) {
            return $this->parent;
        }

        // Set value
        $this->parent = $id;

        return $this;
    }
369725
public static function queryByParentType( $parentType, $config = [] ) {

		$type	= isset( $config[ 'type' ] ) ? $config[ 'type' ] : self::TYPE_COMMENT;
		$status	= isset( $config[ 'status' ] ) ? $config[ 'status' ] : self::STATUS_APPROVED;

		return self::find()->where( [ 'parentType' => $parentType, 'type' => $type, 'status' => $status ] );
	}
145594
private function setParent(&$parent)
    {
        if (! is_null($parent)) {
            $this->parent = $parent;

            $this->parent->elements->add($this);
        }

        return $this;
    }
1072966
public function getDepth ($parent = 0)
    {
        $counter = 0;
        $r = true;

        while ($r) {
            $category = self::where('id' , $parent)->first();
            if ($category) {
                $counter++;
                $parent = $category->parent;
                if ($category->parent == 0) {
                    break;
                }
            } else
                break;
        }
        return $counter;
    }
448419
public function setParent($parent)
    {
        if (null === $parent) {
            $this->parent = null;

            return $this;
        }

        if (is_string($parent)) {
            $this->parent = new Role($parent);

            return $this;
        }

        if ($parent instanceof RoleInterface) {
            $this->parent = $parent;

            return $this;
        }

        throw Exception\InvalidRoleException::invalidRoleInstance($parent);
    }
1337960
public function findChildrenByParentId($parent_id)
    {
        $qb = $this->createQueryBuilder();
        $qb->andWhere($qb->getRootAliases()[0] . '.parent = ' . $this->addNamedParameter('parent', $parent_id, $qb))
            ->orderBy($qb->getRootAliases()[0] . '.position', 'ASC');
        return $qb->getQuery()->getResult();
    }
1025931
public function setParent(Result $parent)
    {
        if ($this->parent !== $parent) {
            $this->parent = $parent;
            if ($this->hasErrors()) {
                $parent->setErrorsExist();
            }
            if ($this->hasWarnings()) {
                $parent->setWarningsExist();
            }
            if ($this->hasNotices()) {
                $parent->setNoticesExist();
            }
        }
    }
988978
private function valuesToFormParameters($values, $parent)
    {
        $ret = array();
        foreach ($values as $key => $value) {
            if (null !== $parent) {
                $keyName = sprintf('%s[%s]', $parent, $key);
            } else {
                $keyName = $key;
            }
            if (is_scalar($value)) {
                $ret[$keyName] = $value;
            } else {
                $ret = array_merge($ret, $this->valuesToFormParameters($value, $keyName));
            }
        }
        return $ret;
    }
534178
public function setParent($parent)
    {
        if (empty($parent) || $this->getRefId() == $parent->getRefId() ||
            $parent->hasAncestor($this) || $this->hasReachedAncestorLimit()) {
            return false;
        }
        unset($this->parent);
        unset($parent->children);
        $this->trigger(static::$eventParentChanged);
        $parent->trigger(static::$eventChildAdded);
        return $this->{$this->parentAttribute} = $parent->getRefId();
    }
382159
public function setParent(InnerNode $parent)
    {
        // remove from old parent
        if ( ! is_null($this->parent)) {
            if ($this->parent->id() == $parent->id()) {
                // already the parent
                return $this;
            }

            $this->parent->removeChild($this->id);
        }

        $this->parent = $parent;

        // assign child to parent
        $this->parent->addChild($this);

        //clear any cache
        $this->clear();

        return $this;
    }
906641
private function getLargestLeaf(int $parent)
    {
        $left  = $this->left($parent);
        $right = $this->right($parent);

        if ($right < count($this->heap) && $this->compare($left, $right) < 0) {
            return $right;
        }

        return $left;
    }
677128
public function setParent(&$parent)
	{
		JLog::add('JNode::setParent() is deprecated.', JLog::WARNING, 'deprecated');

		if ($parent instanceof JNode || is_null($parent))
		{
			$hash = spl_object_hash($this);

			if (!is_null($this->_parent))
			{
				unset($this->_parent->children[$hash]);
			}

			if (!is_null($parent))
			{
				$parent->_children[$hash] = & $this;
			}

			$this->_parent = & $parent;
		}
	}
1200534
public function setParent($parent)
    {
        if (null !== $parent) {
            $this->entity->setParent($parent->getEntity());
        } else {
            $this->entity->setParent(null);
        }

        // FIXME remove cache for parent and generate it on the fly
        //       reason: preview images cannot be generated without a service
        $this->parent = $parent;

        return $this;
    }
713174
protected function updateActiveParent()
    {
        // If no update is required, return immediately
        if ( ! request()->has('parents') && ! request()->filled('home') && ! request()->has('parent')) {
            return $this;
        }

        $separator = $this->getListParentSeparator();

        // Check for either a full hierarchy or a 'current level' update
        if (request()->has('parents') || request()->filled('home')) {

            $parents = request()->get('parents');

            if ($parents === 'all' || empty($parents)) {

                // No need to update if no current memorized parent chain
                if (count($this->listParents)) {
                    $this->clearEntireListParentHierarchy();
                }

                $defaultTopRelation = $this->getModelInformation()->list->default_top_relation;

                // Toggling display to all for relations that limit to top by default,
                // which should reset on a home reset aswell.
                if ($parents == 'all') {
                    $this->listParentRelation  = false;
                    $this->listParentRecordKey = null;
                } elseif (request()->filled('home') && $defaultTopRelation) {
                    $this->listParentRelation  = null;
                    $this->listParentRecordKey = null;
                }

            } else {

                if (is_string($parents)) {
                    $parents = explode(';', $parents);
                }

                $parents = array_values($parents);

                // No need to update if everything is the same down the chain
                if (count($this->listParents) == count($parents)) {
                    $same = true;
                    foreach ($this->listParents as $index => $currentParent) {
                        if ($currentParent->relation . $separator . $currentParent->key !== $parents[$index]) {
                            $same = false;
                            break;
                        }
                    }

                    if ($same) {
                        return $this;
                    }
                }

                $this->clearEntireListParentHierarchy();

                // Update, working backwards, starting at the current list; then re-collect the active parent chain
                $this->updateActiveParents(array_reverse($parents));
            }

        } elseif (request()->has('parent')) {

            $parent = request()->get('parent');

            // Interpret special parent values
            $parent = $this->normalizeListParentParameter($parent);

            // If nothing has changed, no need to update
            if (    ! $parent && $this->listParentRelation == $parent
                ||  $parent == $this->listParentRelation . $separator . $this->listParentRecordKey
            ) {
                return $this;
            }

            if ( ! $parent) {
                // Reset this level to its previous list parent, if any
                $this->listParentRelation  = $parent;
                $this->listParentRecordKey = null;
            } else {

                // If the parent is already present in the current history, switch to it
                if ( ! count(array_filter(
                    $this->listParents,
                    function ($checkParent) use ($parent, $separator) {
                        /** @var ListParentData $checkParent */
                        return $checkParent->relation . $separator . $checkParent->key == $parent;
                    }
                ))) {
                    // Not set yet, prepare old parent as one layer deeper

                    $this->setListParentDataInMemory(
                        $this->listParentRelation,
                        $this->listParentRecordKey,
                        $parent
                    );
                }

                list($this->listParentRelation, $this->listParentRecordKey) = explode($separator, $parent, 2);
            }
        }

        $this->storeActiveParentInSession();
        $this->collectListParentHierarchy();

        return $this;
    }
575903
public function getParent($n = null)
	{
		return ($n > 1) ? $this->parent->getParent(--$n) : $this->parent;
	}
582244
public function bindParent($parent, $parentPropertyName=NULL)
	{
		$this->_parent = $parent;
		$this->_parentPropertyName = $parentPropertyName;
		return $this;
	}