public function can_change_parent($newparentcat) {
        if (!has_capability('moodle/category:manage', $this->get_context())) {
            return false;
        }
        if (is_object($newparentcat)) {
            $newparentcat = self::get($newparentcat->id, IGNORE_MISSING);
        } else {
            $newparentcat = self::get((int)$newparentcat, IGNORE_MISSING);
        }
        if (!$newparentcat) {
            return false;
        }
        if ($newparentcat->id == $this->id || in_array($this->id, $newparentcat->get_parents())) {
            // Can not move to itself or it's own child.
            return false;
        }
        if ($newparentcat->id) {
            return has_capability('moodle/category:manage', context_coursecat::instance($newparentcat->id));
        } else {
            return has_capability('moodle/category:manage', context_system::instance());
        }
    }
public function can_change_parent($newparentcat) {
        if (!has_capability('moodle/category:manage', $this->get_context())) {
            return false;
        }
        if (is_object($newparentcat)) {
            $newparentcat = self::get($newparentcat->id, IGNORE_MISSING);
        } else {
            $newparentcat = self::get((int)$newparentcat, IGNORE_MISSING);
        }
        if (!$newparentcat) {
            return false;
        }
        if ($newparentcat->id == $this->id || in_array($this->id, $newparentcat->get_parents())) {
            // Can not move to itself or it's own child.
            return false;
        }
        if ($newparentcat->id) {
            return has_capability('moodle/category:manage', context_coursecat::instance($newparentcat->id));
        } else {
            return has_capability('moodle/category:manage', context_system::instance());
        }
    }
public function can_change_parent ( $ newparentcat ) { if ( ! has_capability ( 'moodle/category:manage' , $ this -> get_context ( ) ) ) { return false ; } if ( is_object ( $ newparentcat ) ) { $ newparentcat = self :: get ( $ newparentcat -> id , IGNORE_MISSING ) ; } else { $ newparentcat = self :: get ( ( int ) $ newparentcat , IGNORE_MISSING ) ; } if ( ! $ newparentcat ) { return false ; } if ( $ newparentcat -> id == $ this -> id || in_array ( $ this -> id , $ newparentcat -> get_parents ( ) ) ) { // Can not move to itself or it's own child. return false ; } if ( $ newparentcat -> id ) { return has_capability ( 'moodle/category:manage' , context_coursecat :: instance ( $ newparentcat -> id ) ) ; } else { return has_capability ( 'moodle/category:manage' , context_system :: instance ( ) ) ; } }
Checks if user can move current category to the new parent

This checks if new parent category exists, user has manage cap there
and new parent is not a child of this category

@param int|stdClass|core_course_category $newparentcat
@return bool
Checks if user can move current category to the new parent