Set parent category.

@param int|null $parent_id

@return self
192394
public function setParent($parent_id = null): self
    {
        $parent_id = ((int) $parent_id > 0) ? (int) $parent_id : null;

        $this->setAttribute('parent_id', $parent_id);

        return $this;
    }
315349
protected function setCategoryGroup($category_group_id)
    {
        $this->data_category_group = array();

        if (is_numeric($category_group_id)) {

            $conditions = array(
                'language' => 'und',
                'category_group_id' => $category_group_id
            );

            $this->data_category_group = $this->category_group->get($conditions);

            if (empty($this->data_category_group)) {
                $this->outputHttpStatus(404);
            }

            $this->prepareCategoryGroup($this->data_category_group);
        }
    }
991917
public function setParent(\BisonLab\SakonninBundle\Entity\MessageType $parent = null)
    {
        $this->parent = $parent;

        return $this;
    }
240315
public function setParent(\Haven\CoreBundle\Entity\ExternalLink $parent = null)
    {
        $this->parent = $parent;
    
        return $this;
    }
145594
private function setParent(&$parent)
    {
        if (! is_null($parent)) {
            $this->parent = $parent;

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

        return $this;
    }
1140395
public function setCategory(\Amulen\ClassificationBundle\Entity\Category $category = null)
    {
        $this->category = $category;

        return $this;
    }
420317
public function setNullParent()
    {
        if ($this->hasParent()) {
            unset($this->parent->children);
        }
        unset($this->parent);
        $this->setParentId(static::$nullParent);
    }
462975
public function setParent($parent)
    {
        if ($parent !== null && !$parent instanceof self) {
            throw new \InvalidArgumentException('An entry may only have another entry as parent');
        }

        $this->parent = $parent;
    }
874501
protected function setCategory($category_id)
    {
        $options = array(
            'category_id' => $category_id,
            'language' => $this->langcode,
            'store_id' => $this->store_id
        );

        $this->data_category = $this->category->get($options);

        if (empty($this->data_category['status'])) {
            $this->outputHttpStatus(404);
        }

        $this->prepareCategory($this->data_category);
    }
34356
public function setParent(Node $parent)
    {
        $this->_parent = $parent;
        if ($id = $parent->getId()) {
            $this->updateParentId($id);
        }
        $parent->getChildren()->append($this);
        return $this;
    }
96951
protected function setChildrenCategory()
    {
        $this->data_children = array();

        foreach ($this->data_categories as $item) {
            if (in_array($this->data_category['category_id'], $item['parents'])) {
                $this->data_children[] = $item;
            }
        }
    }
570627
private void setParent(DepTreeNode parent) {
		if (this.name.length() == 0) {
			// A child node must have a name.
			throw new IllegalStateException();
		}
		this.parent = new WeakReference<DepTreeNode>(parent);
	}
159351
public function set_parent(Node_Container $parent=null)
	{
		$this->parent = $parent;

		if($parent instanceof Node_Container_Document)
			$this->root = $parent;
		else
			$this->root = $parent->root();
	}
1349219
protected function setCategoryGroup($category_group_id)
    {
        $this->data_category_group = $this->category_group->get($category_group_id);

        if (empty($this->data_category_group)) {
            $this->outputHttpStatus(404);
        }
    }
790811
public static function set_parent_competency($id, $newparentid) {
        global $DB;
        static::require_enabled();
        $current = new competency($id);

        // First we do a permissions check.
        require_capability('moodle/competency:competencymanage', $current->get_context());
        if ($id == $newparentid) {
            throw new coding_exception('Can not set a competency as a parent of itself.');
        } if ($newparentid == $current->get('parentid')) {
            throw new coding_exception('Can not move a competency to the same location.');
        }

        // Some great variable assignment right here.
        $currentparent = $current->get_parent();
        $parent = !empty($newparentid) ? new competency($newparentid) : null;
        $parentpath = !empty($parent) ? $parent->get('path') : '/0/';

        // We're going to change quite a few things.
        $transaction = $DB->start_delegated_transaction();

        // If we are moving a node to a child of itself:
        // - promote all the child nodes by one level.
        // - remove the rule on self.
        // - re-read the parent.
        $newparents = explode('/', $parentpath);
        if (in_array($current->get('id'), $newparents)) {
            $children = competency::get_records(array('parentid' => $current->get('id')), 'id');
            foreach ($children as $child) {
                $child->set('parentid', $current->get('parentid'));
                $child->update();
            }

            // Reset the rule on self as our children have changed.
            $current->reset_rule();

            // The destination parent is one of our descendants, we need to re-fetch its values (path, parentid).
            $parent->read();
        }

        // Reset the rules of initial parent and destination.
        if (!empty($currentparent)) {
            $currentparent->reset_rule();
            $currentparent->update();
        }
        if (!empty($parent)) {
            $parent->reset_rule();
            $parent->update();
        }

        // Do the actual move.
        $current->set('parentid', $newparentid);
        $result = $current->update();

        // All right, let's commit this.
        $transaction->allow_commit();

        return $result;
    }
348873
public function actionAdd($id, $parent_id, $add = 1)
    {
        $parent = $this->findParentModel($parent_id);
        $model = $this->findParentModel();
        $model->type = Item::TYPE_PERMISSION;
        $model->name = $id;
        if ((!$child = $model::findOne($id)) && $add) {
            $child = $model;
        }
        if ($add) {
            $parent->addChild($child);
        } else if ($child){
            $parent->removeChild($child);
        }
    }
519285
public static function set_parent_competency($competencyid, $parentid) {
        $params = self::validate_parameters(self::set_parent_competency_parameters(), array(
            'competencyid' => $competencyid,
            'parentid' => $parentid
        ));

        $competency = api::read_competency($params['competencyid']);
        self::validate_context($competency->get_context());

        return api::set_parent_competency($params['competencyid'], $params['parentid']);
    }