@param Model $concreteParent

@since  1.1.0

@author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
431393
private function proxySetup(self $concreteParent)
    {
        $this->getMeta()->setupProxy($concreteParent);
        $this->getMeta()->setConcreteModel($concreteParent->getMeta()->getConcreteModel());
    }
1200030
public function moveBefore($model)
    {
        if ( is_numeric($model) ) {
            $model = call_user_func("$this->ownerClassName::findOne", $model);
        }
        $parentId = $this->parentIdField ? $model->{$this->parentIdField} : 0;
        if ( $model->{$this->sortField} < 1 ) {
            $this->reorder($parentId);
            $model->refresh();
        }
        $prevIdx = $this->getMaxIdx($parentId, $model->{$this->sortField});
        if ( $model->{$this->sortField} - $prevIdx < 2 ) {
            $this->reorder($parentId);
            $model->refresh();
            $prevIdx = $this->getMaxIdx($parentId, $model->{$this->sortField});
        }
        $newIdx = $model->{$this->sortField} - floor(($model->{$this->sortField} - $prevIdx)/2);
        if ( $this->parentIdField ) {
            call_user_func("$this->ownerClassName::updateAll", [
                $this->sortField => $newIdx,
                $this->parentIdField => $parentId,
            ], [ $this->primaryKey => $this->owner->primaryKey ]);
        } else {
            call_user_func("$this->ownerClassName::updateAll",
                [ $this->sortField => $newIdx ],
                [ $this->primaryKey => $this->owner->primaryKey ]);
        }
        $this->invalidateTagDependency();
    }
564581
protected function insertModelAsLastChildOf(Model &$model, Model &$parent)
    {
        if ($parent->isNew())
            throw new Exception('Parent model should be saved before child insert');

        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        if (!$model->isNew()) {
            $model->refreshTreeColumns();
            $this->removeFromTreeByElement($model);
        }
        $parent->refreshTreeColumns();

        $width = $model->getTreeWidth();

        $query = (new Query("
            UPDATE " . $tableName . "
            SET __rgt = __rgt + :width + 1
            WHERE __rgt >= :rgt
            "))
            ->params([':width' => $width, ':rgt' => $parent->__rgt]);
        $connection->execute($query);

        $query = (new Query("
            UPDATE " . $tableName . "
            SET __lft = __lft + :width + 1
            WHERE __lft > :rgt
            "))
            ->params([':width' => $width, ':rgt' => $parent->__rgt]);
        $connection->execute($query);

        $model->__lft = $parent->__rgt;
        $model->__rgt = $parent->__rgt + $width;
        $model->__lvl = $parent->__lvl + 1;
        $model->__prt = $parent->getPk();

        $parent->__rgt += $width + 1;

    }
728781
public function setParent (Logger $parent) {
    $this->handlers = $parent->handlers;
    $this->processors = $parent->processors;
    $this->level = $parent->level;
  }
1185074
public function bindForCallback(string $abstract, $concrete, callable $callback)
    {
        $hasOriginal      = $this->container->bound($abstract);
        $originalInstance = false;

        if ($hasOriginal) {
            $binding = $this->container->getBindings()[$abstract] ?? null;

            $hasInstance = $binding && $binding['shared'] && $this->container->resolved($abstract);

            if ($hasInstance) {
                $originalInstance = $this->container->make($abstract);
            }
        }

        $this->container->instance($abstract, $concrete);

        try {
            $return = $callback();
            return $return;
        } finally {
            unset($this->container[$abstract]);

            if ($hasOriginal && (isset($binding) && $binding)) {
                $this->container->bind($abstract, $binding['concrete'], $binding['shared']);

                if ($originalInstance) {
                    $this->container->instance($abstract, $originalInstance);
                }
            }
        }
    }
14676
private function searchParentOfInHierarchical(ModelInterface $model)
    {
        if ($this->isRootModel($model)) {
            throw new DcGeneralInvalidArgumentException('Invalid condition, root models can not have parents!');
        }
        // Start from the root data provider and walk through the whole tree.
        // To speed up, some conditions have an inverse filter - we should use them!
        $config = $this->rootProvider->getEmptyConfig()->setFilter($this->rootCondition->getFilterArray());

        return $this->searchParentOfIn($model, $this->rootProvider->fetchAll($config));
    }
483149
protected function _changeParent(Model $model, $id = null, $parentId = null) {
		$parentField = $this->_getBehaviorConfig($model, 'parent');
		if (empty($id) || ($parentField === null)) {
			return false;
		}

		$model->recursive = -1;
		$treeItem = $model->read(null, $id);
		if (empty($treeItem)) {
			return false;
		}

		$treeItem[$model->alias][$parentField] = $parentId;
		$result = (bool)$model->save($treeItem);

		return $result;
	}
126743
public function addCallback($concrete, callable $callback)
    {
        //Strip all leading backslashes
        if ($concrete[0] === '\\') {
            $concrete = substr($concrete, 1);
        }

        if (!isset($this->callbacks[$concrete])) {
            $this->callbacks[$concrete] = [];
        }
        $this->callbacks[$concrete][] = $callback;
    }
1304691
public function add(IEntity $parent, array $add)
	{
		if (!$add) {
			return;
		}

		$this->mapperCoordinator->beginTransaction();
		$list = $this->buildList($parent, $add);
		$this->connection->query('INSERT INTO %table %values[]', $this->joinTable, $list);
	}
821728
public function apply(Builder $builder, Model $model)
    {
        if (!UserUtils::hasDisplayAllStatus())
        {
            $builder->where($model->getQualifiedStatusColumn(), true);
        }
        $this->extend($builder);

    }
556735
public function setModel(Model $model)
    {
        parent::setModel($model);

        if ($model->exists) {
            $this->setInstance($model);
            $this->loadRelationValues();
        }
    }
1174681
public function setParent($parent)
    {
        if ($parent !== null &&  !$parent instanceof BaseEntry) {
            throw new \InvalidArgumentException('An entry may only have another entry as parent');
        }

        $this->parent = $parent;
    }
745570
public function changeParent(
        \Mirasvit\Blog\Model\Category $category,
        \Mirasvit\Blog\Model\Category $newParent,
        $afterCategoryId = null
    ) {
        $childrenCount = $this->getChildrenCount($category->getId()) + 1;
        $table = $this->getEntityTable();
        $connection = $this->getConnection();
        $levelFiled = $connection->quoteIdentifier('level');
        $pathField = $connection->quoteIdentifier('path');

        /**
         * Decrease children count for all old category parent categories
         */
        $connection->update(
            $table,
            ['children_count' => new \Zend_Db_Expr('children_count - ' . $childrenCount)],
            ['entity_id IN(?)' => $category->getParentIds()]
        );

        /**
         * Increase children count for new category parents
         */
        $connection->update(
            $table,
            ['children_count' => new \Zend_Db_Expr('children_count + ' . $childrenCount)],
            ['entity_id IN(?)' => $newParent->getPathIds()]
        );

        $position = $this->processPositions($category, $newParent, $afterCategoryId);

        $newPath = sprintf('%s/%s', $newParent->getPath(), $category->getId());
        $newLevel = $newParent->getLevel() + 1;
        $levelDisposition = $newLevel - $category->getLevel();

        /**
         * Update children nodes path
         */
        $connection->update(
            $table,
            [
                'path'  => new \Zend_Db_Expr(
                    'REPLACE(' . $pathField . ',' . $connection->quote(
                        $category->getPath() . '/'
                    ) . ', ' . $connection->quote(
                        $newPath . '/'
                    ) . ')'
                ),
                'level' => new \Zend_Db_Expr($levelFiled . ' + ' . $levelDisposition)
            ],
            [$pathField . ' LIKE ?' => $category->getPath() . '/%']
        );

        /**
         * Update moved category data
         */
        $data = [
            'path'      => $newPath,
            'level'     => $newLevel,
            'position'  => $position,
            'parent_id' => $newParent->getId(),
        ];
        $connection->update($table, $data, ['entity_id = ?' => $category->getId()]);

        // Update category object to new data
        $category->addData($data);
        $category->unsetData('path_ids');

        return $this;
    }
1227758
public function setParentForAll(CollectionInterface $models, ModelInterface $parentModel)
    {
        foreach ($models as $model) {
            $this->setParent($model, $parentModel);
        }
    }
863555
public function bindIf($abstract, $concrete = null, $shared = false)
    {
        if (! $this->bound($abstract)) {
            $this->bind($abstract, $concrete, $shared);
        }
    }
466556
public function findParentsRecursively(string $parentProperty, string $table, Model $instance): array
    {
        $parents = [];

        if (!$instance->{$parentProperty} || null === ($parentInstance = $this->findModelInstanceByPk($table, $instance->{$parentProperty}))) {
            return $parents;
        }

        return array_merge($this->findParentsRecursively($parentProperty, $table, $parentInstance), [$parentInstance]);
    }
518554
public function update_moved(context $newparent) {
        global $DB;

        $frompath = $this->_path;
        $newpath  = $newparent->path . '/' . $this->_id;

        $trans = $DB->start_delegated_transaction();

        $setdepth = '';
        if (($newparent->depth +1) != $this->_depth) {
            $diff = $newparent->depth - $this->_depth + 1;
            $setdepth = ", depth = depth + $diff";
        }
        $sql = "UPDATE {context}
                   SET path = ?
                       $setdepth
                 WHERE id = ?";
        $params = array($newpath, $this->_id);
        $DB->execute($sql, $params);

        $this->_path  = $newpath;
        $this->_depth = $newparent->depth + 1;

        $sql = "UPDATE {context}
                   SET path = ".$DB->sql_concat("?", $DB->sql_substr("path", strlen($frompath)+1))."
                       $setdepth
                 WHERE path LIKE ?";
        $params = array($newpath, "{$frompath}/%");
        $DB->execute($sql, $params);

        $this->mark_dirty();

        context::reset_caches();

        $trans->allow_commit();
    }