original_string: public function reposition_block($blockinstanceid, $newregion, $newweight) {
          global $DB;
  
          $this->check_region_is_known($newregion);
          $inst = $this->find_instance($blockinstanceid);
  
          $bi = $inst->instance;
          if ($bi->weight == $bi->defaultweight && $bi->region == $bi->defaultregion &&
                  !$bi->showinsubcontexts && strpos($bi->pagetypepattern, '*') === false &&
                  (!$this->page->subpage || $bi->subpagepattern)) {
  
              // Set default position
              $newbi = new stdClass;
              $newbi->id = $bi->id;
              $newbi->defaultregion = $newregion;
              $newbi->defaultweight = $newweight;
              $newbi->timemodified = time();
              $DB->update_record('block_instances', $newbi);
  
              if ($bi->blockpositionid) {
                  $bp = new stdClass;
                  $bp->id = $bi->blockpositionid;
                  $bp->region = $newregion;
                  $bp->weight = $newweight;
                  $DB->update_record('block_positions', $bp);
              }
  
          } else {
              // Just set position on this page.
              $bp = new stdClass;
              $bp->region = $newregion;
              $bp->weight = $newweight;
  
              if ($bi->blockpositionid) {
                  $bp->id = $bi->blockpositionid;
                  $DB->update_record('block_positions', $bp);
  
              } else {
                  $bp->blockinstanceid = $bi->id;
                  $bp->contextid = $this->page->context->id;
                  $bp->pagetype = $this->page->pagetype;
                  if ($this->page->subpage) {
                      $bp->subpage = $this->page->subpage;
                  } else {
                      $bp->subpage = '';
                  }
                  $bp->visible = $bi->visible;
                  $DB->insert_record('block_positions', $bp);
              }
          }
      }
code: public function reposition_block($blockinstanceid, $newregion, $newweight) {
          global $DB;
  
          $this->check_region_is_known($newregion);
          $inst = $this->find_instance($blockinstanceid);
  
          $bi = $inst->instance;
          if ($bi->weight == $bi->defaultweight && $bi->region == $bi->defaultregion &&
                  !$bi->showinsubcontexts && strpos($bi->pagetypepattern, '*') === false &&
                  (!$this->page->subpage || $bi->subpagepattern)) {
  
              // Set default position
              $newbi = new stdClass;
              $newbi->id = $bi->id;
              $newbi->defaultregion = $newregion;
              $newbi->defaultweight = $newweight;
              $newbi->timemodified = time();
              $DB->update_record('block_instances', $newbi);
  
              if ($bi->blockpositionid) {
                  $bp = new stdClass;
                  $bp->id = $bi->blockpositionid;
                  $bp->region = $newregion;
                  $bp->weight = $newweight;
                  $DB->update_record('block_positions', $bp);
              }
  
          } else {
              // Just set position on this page.
              $bp = new stdClass;
              $bp->region = $newregion;
              $bp->weight = $newweight;
  
              if ($bi->blockpositionid) {
                  $bp->id = $bi->blockpositionid;
                  $DB->update_record('block_positions', $bp);
  
              } else {
                  $bp->blockinstanceid = $bi->id;
                  $bp->contextid = $this->page->context->id;
                  $bp->pagetype = $this->page->pagetype;
                  if ($this->page->subpage) {
                      $bp->subpage = $this->page->subpage;
                  } else {
                      $bp->subpage = '';
                  }
                  $bp->visible = $bi->visible;
                  $DB->insert_record('block_positions', $bp);
              }
          }
      }
code_tokens: public function reposition_block ( $ blockinstanceid , $ newregion , $ newweight ) { global $ DB ; $ this -> check_region_is_known ( $ newregion ) ; $ inst = $ this -> find_instance ( $ blockinstanceid ) ; $ bi = $ inst -> instance ; if ( $ bi -> weight == $ bi -> defaultweight && $ bi -> region == $ bi -> defaultregion && ! $ bi -> showinsubcontexts && strpos ( $ bi -> pagetypepattern , '*' ) === false && ( ! $ this -> page -> subpage || $ bi -> subpagepattern ) ) { // Set default position $ newbi = new stdClass ; $ newbi -> id = $ bi -> id ; $ newbi -> defaultregion = $ newregion ; $ newbi -> defaultweight = $ newweight ; $ newbi -> timemodified = time ( ) ; $ DB -> update_record ( 'block_instances' , $ newbi ) ; if ( $ bi -> blockpositionid ) { $ bp = new stdClass ; $ bp -> id = $ bi -> blockpositionid ; $ bp -> region = $ newregion ; $ bp -> weight = $ newweight ; $ DB -> update_record ( 'block_positions' , $ bp ) ; } } else { // Just set position on this page. $ bp = new stdClass ; $ bp -> region = $ newregion ; $ bp -> weight = $ newweight ; if ( $ bi -> blockpositionid ) { $ bp -> id = $ bi -> blockpositionid ; $ DB -> update_record ( 'block_positions' , $ bp ) ; } else { $ bp -> blockinstanceid = $ bi -> id ; $ bp -> contextid = $ this -> page -> context -> id ; $ bp -> pagetype = $ this -> page -> pagetype ; if ( $ this -> page -> subpage ) { $ bp -> subpage = $ this -> page -> subpage ; } else { $ bp -> subpage = '' ; } $ bp -> visible = $ bi -> visible ; $ DB -> insert_record ( 'block_positions' , $ bp ) ; } } }
docstring: Move a block to a new position on this page.
  
  If this block cannot appear on any other pages, then we change defaultposition/weight
  in the block_instances table. Otherwise we just set the position on this page.
  
  @param $blockinstanceid the block instance id.
  @param $newregion the new region name.
  @param $newweight the new weight.
docstring_tokens: Move a block to a new position on this page .