original_string: public function resort_subcategories($field, $cleanup = true) {
          global $DB;
          $desc = false;
          if (substr($field, -4) === "desc") {
              $desc = true;
              $field = substr($field, 0, -4);  // Remove "desc" from field name.
          }
          if ($field !== 'name' && $field !== 'idnumber') {
              throw new coding_exception('Invalid field requested');
          }
          $children = $this->get_children();
          core_collator::asort_objects_by_property($children, $field, core_collator::SORT_NATURAL);
          if (!empty($desc)) {
              $children = array_reverse($children);
          }
          $i = 1;
          foreach ($children as $cat) {
              $i++;
              $DB->set_field('course_categories', 'sortorder', $i, array('id' => $cat->id));
              $i += $cat->coursecount;
          }
          if ($cleanup) {
              self::resort_categories_cleanup();
          }
          return true;
      }
code: public function resort_subcategories($field, $cleanup = true) {
          global $DB;
          $desc = false;
          if (substr($field, -4) === "desc") {
              $desc = true;
              $field = substr($field, 0, -4);  // Remove "desc" from field name.
          }
          if ($field !== 'name' && $field !== 'idnumber') {
              throw new coding_exception('Invalid field requested');
          }
          $children = $this->get_children();
          core_collator::asort_objects_by_property($children, $field, core_collator::SORT_NATURAL);
          if (!empty($desc)) {
              $children = array_reverse($children);
          }
          $i = 1;
          foreach ($children as $cat) {
              $i++;
              $DB->set_field('course_categories', 'sortorder', $i, array('id' => $cat->id));
              $i += $cat->coursecount;
          }
          if ($cleanup) {
              self::resort_categories_cleanup();
          }
          return true;
      }
code_tokens: public function resort_subcategories ( $ field , $ cleanup = true ) { global $ DB ; $ desc = false ; if ( substr ( $ field , - 4 ) === "desc" ) { $ desc = true ; $ field = substr ( $ field , 0 , - 4 ) ; // Remove "desc" from field name. } if ( $ field !== 'name' && $ field !== 'idnumber' ) { throw new coding_exception ( 'Invalid field requested' ) ; } $ children = $ this -> get_children ( ) ; core_collator :: asort_objects_by_property ( $ children , $ field , core_collator :: SORT_NATURAL ) ; if ( ! empty ( $ desc ) ) { $ children = array_reverse ( $ children ) ; } $ i = 1 ; foreach ( $ children as $ cat ) { $ i ++ ; $ DB -> set_field ( 'course_categories' , 'sortorder' , $ i , array ( 'id' => $ cat -> id ) ) ; $ i += $ cat -> coursecount ; } if ( $ cleanup ) { self :: resort_categories_cleanup ( ) ; } return true ; }
docstring: Resorts the sub categories of this category by the given field.
  
  @param string $field One of name, idnumber or descending values of each (appended desc)
  @param bool $cleanup If true cleanup will be done, if false you will need to do it manually later.
  @return bool True on success.
  @throws coding_exception
docstring_tokens: Resorts the sub categories of this category by the given field .