original_string: protected function generate_rating_scale_object($scaleid) {
          global $DB;
          if (!array_key_exists('s'.$scaleid, $this->scales)) {
              $scale = new stdClass;
              $scale->id = $scaleid;
              $scale->name = null;
              $scale->courseid = null;
              $scale->scaleitems = array();
              $scale->isnumeric = true;
              $scale->max = $scaleid;
  
              if ($scaleid < 0) {
                  // It is a proper scale (not numeric).
                  $scalerecord = $DB->get_record('scale', array('id' => abs($scaleid)));
                  if ($scalerecord) {
                      // We need to generate an array with string keys starting at 1.
                      $scalearray = explode(',', $scalerecord->scale);
                      $c = count($scalearray);
                      for ($i = 0; $i < $c; $i++) {
                          // Treat index as a string to allow sorting without changing the value.
                          $scale->scaleitems[(string)($i + 1)] = $scalearray[$i];
                      }
                      krsort($scale->scaleitems); // Have the highest grade scale item appear first.
                      $scale->isnumeric = false;
                      $scale->name = $scalerecord->name;
                      $scale->courseid = $scalerecord->courseid;
                      $scale->max = count($scale->scaleitems);
                  }
              } else {
                  // Generate an array of values for numeric scales.
                  for ($i = 0; $i <= (int)$scaleid; $i++) {
                      $scale->scaleitems[(string)$i] = $i;
                  }
              }
              $this->scales['s'.$scaleid] = $scale;
          }
          return $this->scales['s'.$scaleid];
      }
code: protected function generate_rating_scale_object($scaleid) {
          global $DB;
          if (!array_key_exists('s'.$scaleid, $this->scales)) {
              $scale = new stdClass;
              $scale->id = $scaleid;
              $scale->name = null;
              $scale->courseid = null;
              $scale->scaleitems = array();
              $scale->isnumeric = true;
              $scale->max = $scaleid;
  
              if ($scaleid < 0) {
                  // It is a proper scale (not numeric).
                  $scalerecord = $DB->get_record('scale', array('id' => abs($scaleid)));
                  if ($scalerecord) {
                      // We need to generate an array with string keys starting at 1.
                      $scalearray = explode(',', $scalerecord->scale);
                      $c = count($scalearray);
                      for ($i = 0; $i < $c; $i++) {
                          // Treat index as a string to allow sorting without changing the value.
                          $scale->scaleitems[(string)($i + 1)] = $scalearray[$i];
                      }
                      krsort($scale->scaleitems); // Have the highest grade scale item appear first.
                      $scale->isnumeric = false;
                      $scale->name = $scalerecord->name;
                      $scale->courseid = $scalerecord->courseid;
                      $scale->max = count($scale->scaleitems);
                  }
              } else {
                  // Generate an array of values for numeric scales.
                  for ($i = 0; $i <= (int)$scaleid; $i++) {
                      $scale->scaleitems[(string)$i] = $i;
                  }
              }
              $this->scales['s'.$scaleid] = $scale;
          }
          return $this->scales['s'.$scaleid];
      }
code_tokens: protected function generate_rating_scale_object ( $ scaleid ) { global $ DB ; if ( ! array_key_exists ( 's' . $ scaleid , $ this -> scales ) ) { $ scale = new stdClass ; $ scale -> id = $ scaleid ; $ scale -> name = null ; $ scale -> courseid = null ; $ scale -> scaleitems = array ( ) ; $ scale -> isnumeric = true ; $ scale -> max = $ scaleid ; if ( $ scaleid < 0 ) { // It is a proper scale (not numeric). $ scalerecord = $ DB -> get_record ( 'scale' , array ( 'id' => abs ( $ scaleid ) ) ) ; if ( $ scalerecord ) { // We need to generate an array with string keys starting at 1. $ scalearray = explode ( ',' , $ scalerecord -> scale ) ; $ c = count ( $ scalearray ) ; for ( $ i = 0 ; $ i < $ c ; $ i ++ ) { // Treat index as a string to allow sorting without changing the value. $ scale -> scaleitems [ ( string ) ( $ i + 1 ) ] = $ scalearray [ $ i ] ; } krsort ( $ scale -> scaleitems ) ; // Have the highest grade scale item appear first. $ scale -> isnumeric = false ; $ scale -> name = $ scalerecord -> name ; $ scale -> courseid = $ scalerecord -> courseid ; $ scale -> max = count ( $ scale -> scaleitems ) ; } } else { // Generate an array of values for numeric scales. for ( $ i = 0 ; $ i <= ( int ) $ scaleid ; $ i ++ ) { $ scale -> scaleitems [ ( string ) $ i ] = $ i ; } } $ this -> scales [ 's' . $ scaleid ] = $ scale ; } return $ this -> scales [ 's' . $ scaleid ] ; }
docstring: Generates a scale object that can be returned
  
  @global moodle_database $DB moodle database object
  @param int $scaleid scale-type identifier
  @return stdClass scale for ratings
docstring_tokens: Generates a scale object that can be returned