original_string: protected function change_parent_raw(core_course_category $newparentcat) {
          global $DB;
  
          $context = $this->get_context();
  
          $hidecat = false;
          if (empty($newparentcat->id)) {
              $DB->set_field('course_categories', 'parent', 0, array('id' => $this->id));
              $newparent = context_system::instance();
          } else {
              if ($newparentcat->id == $this->id || in_array($this->id, $newparentcat->get_parents())) {
                  // Can not move to itself or it's own child.
                  throw new moodle_exception('cannotmovecategory');
              }
              $DB->set_field('course_categories', 'parent', $newparentcat->id, array('id' => $this->id));
              $newparent = context_coursecat::instance($newparentcat->id);
  
              if (!$newparentcat->visible and $this->visible) {
                  // Better hide category when moving into hidden category, teachers may unhide afterwards and the hidden children
                  // will be restored properly.
                  $hidecat = true;
              }
          }
          $this->parent = $newparentcat->id;
  
          $context->update_moved($newparent);
  
          // Now make it last in new category.
          $DB->set_field('course_categories', 'sortorder', MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES, ['id' => $this->id]);
  
          if ($hidecat) {
              fix_course_sortorder();
              $this->restore();
              // Hide object but store 1 in visibleold, because when parent category visibility changes this category must
              // become visible again.
              $this->hide_raw(1);
          }
      }
code: protected function change_parent_raw(core_course_category $newparentcat) {
          global $DB;
  
          $context = $this->get_context();
  
          $hidecat = false;
          if (empty($newparentcat->id)) {
              $DB->set_field('course_categories', 'parent', 0, array('id' => $this->id));
              $newparent = context_system::instance();
          } else {
              if ($newparentcat->id == $this->id || in_array($this->id, $newparentcat->get_parents())) {
                  // Can not move to itself or it's own child.
                  throw new moodle_exception('cannotmovecategory');
              }
              $DB->set_field('course_categories', 'parent', $newparentcat->id, array('id' => $this->id));
              $newparent = context_coursecat::instance($newparentcat->id);
  
              if (!$newparentcat->visible and $this->visible) {
                  // Better hide category when moving into hidden category, teachers may unhide afterwards and the hidden children
                  // will be restored properly.
                  $hidecat = true;
              }
          }
          $this->parent = $newparentcat->id;
  
          $context->update_moved($newparent);
  
          // Now make it last in new category.
          $DB->set_field('course_categories', 'sortorder', MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES, ['id' => $this->id]);
  
          if ($hidecat) {
              fix_course_sortorder();
              $this->restore();
              // Hide object but store 1 in visibleold, because when parent category visibility changes this category must
              // become visible again.
              $this->hide_raw(1);
          }
      }
code_tokens: protected function change_parent_raw ( core_course_category $ newparentcat ) { global $ DB ; $ context = $ this -> get_context ( ) ; $ hidecat = false ; if ( empty ( $ newparentcat -> id ) ) { $ DB -> set_field ( 'course_categories' , 'parent' , 0 , array ( 'id' => $ this -> id ) ) ; $ newparent = context_system :: instance ( ) ; } else { if ( $ newparentcat -> id == $ this -> id || in_array ( $ this -> id , $ newparentcat -> get_parents ( ) ) ) { // Can not move to itself or it's own child. throw new moodle_exception ( 'cannotmovecategory' ) ; } $ DB -> set_field ( 'course_categories' , 'parent' , $ newparentcat -> id , array ( 'id' => $ this -> id ) ) ; $ newparent = context_coursecat :: instance ( $ newparentcat -> id ) ; if ( ! $ newparentcat -> visible and $ this -> visible ) { // Better hide category when moving into hidden category, teachers may unhide afterwards and the hidden children // will be restored properly. $ hidecat = true ; } } $ this -> parent = $ newparentcat -> id ; $ context -> update_moved ( $ newparent ) ; // Now make it last in new category. $ DB -> set_field ( 'course_categories' , 'sortorder' , MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES , [ 'id' => $ this -> id ] ) ; if ( $ hidecat ) { fix_course_sortorder ( ) ; $ this -> restore ( ) ; // Hide object but store 1 in visibleold, because when parent category visibility changes this category must // become visible again. $ this -> hide_raw ( 1 ) ; } }
docstring: Moves the category under another parent category. All associated contexts are moved as well
  
  This is protected function, use change_parent() or update() from outside of this class
  
  @see core_course_category::change_parent()
  @see core_course_category::update()
  
  @param core_course_category $newparentcat
  @throws moodle_exception
docstring_tokens: Moves the category under another parent category . All associated contexts are moved as well