original_string: public static function change_sortorder($tagcoll, $direction) {
          global $DB;
          if ($direction != -1 && $direction != 1) {
              throw new coding_exception('Second argument in tag_coll_change_sortorder() can be only 1 or -1');
          }
          $tagcolls = self::get_collections();
          $keys = array_keys($tagcolls);
          $idx = array_search($tagcoll->id, $keys);
          if ($idx === false || $idx == 0 || $idx + $direction < 1 || $idx + $direction >= count($tagcolls)) {
              return false;
          }
          $otherid = $keys[$idx + $direction];
          $DB->update_record('tag_coll', array('id' => $tagcoll->id, 'sortorder' => $idx + $direction));
          $DB->update_record('tag_coll', array('id' => $otherid, 'sortorder' => $idx));
          // Reset cache.
          cache::make('core', 'tags')->delete('tag_coll');
          return true;
      }
code: public static function change_sortorder($tagcoll, $direction) {
          global $DB;
          if ($direction != -1 && $direction != 1) {
              throw new coding_exception('Second argument in tag_coll_change_sortorder() can be only 1 or -1');
          }
          $tagcolls = self::get_collections();
          $keys = array_keys($tagcolls);
          $idx = array_search($tagcoll->id, $keys);
          if ($idx === false || $idx == 0 || $idx + $direction < 1 || $idx + $direction >= count($tagcolls)) {
              return false;
          }
          $otherid = $keys[$idx + $direction];
          $DB->update_record('tag_coll', array('id' => $tagcoll->id, 'sortorder' => $idx + $direction));
          $DB->update_record('tag_coll', array('id' => $otherid, 'sortorder' => $idx));
          // Reset cache.
          cache::make('core', 'tags')->delete('tag_coll');
          return true;
      }
code_tokens: public static function change_sortorder ( $ tagcoll , $ direction ) { global $ DB ; if ( $ direction != - 1 && $ direction != 1 ) { throw new coding_exception ( 'Second argument in tag_coll_change_sortorder() can be only 1 or -1' ) ; } $ tagcolls = self :: get_collections ( ) ; $ keys = array_keys ( $ tagcolls ) ; $ idx = array_search ( $ tagcoll -> id , $ keys ) ; if ( $ idx === false || $ idx == 0 || $ idx + $ direction < 1 || $ idx + $ direction >= count ( $ tagcolls ) ) { return false ; } $ otherid = $ keys [ $ idx + $ direction ] ; $ DB -> update_record ( 'tag_coll' , array ( 'id' => $ tagcoll -> id , 'sortorder' => $ idx + $ direction ) ) ; $ DB -> update_record ( 'tag_coll' , array ( 'id' => $ otherid , 'sortorder' => $ idx ) ) ; // Reset cache. cache :: make ( 'core' , 'tags' ) -> delete ( 'tag_coll' ) ; return true ; }
docstring: Moves the tag collection in the list one position up or down
  
  @param stdClass $tagcoll existing record in DB table tag_coll
  @param int $direction move direction: +1 or -1
  @return bool
docstring_tokens: Moves the tag collection in the list one position up or down