original_string: public function get_grade_item() {
          if (empty($this->id)) {
              debugging("Attempt to obtain a grade_category's associated grade_item without the category's ID being set.");
              return false;
          }
  
          if (empty($this->parent)) {
              $params = array('courseid'=>$this->courseid, 'itemtype'=>'course', 'iteminstance'=>$this->id);
  
          } else {
              $params = array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id);
          }
  
          if (!$grade_items = grade_item::fetch_all($params)) {
              // create a new one
              $grade_item = new grade_item($params, false);
              $grade_item->gradetype = GRADE_TYPE_VALUE;
              $grade_item->insert('system');
  
          } else if (count($grade_items) == 1) {
              // found existing one
              $grade_item = reset($grade_items);
  
          } else {
              debugging("Found more than one grade_item attached to category id:".$this->id);
              // return first one
              $grade_item = reset($grade_items);
          }
  
          return $grade_item;
      }
code: public function get_grade_item() {
          if (empty($this->id)) {
              debugging("Attempt to obtain a grade_category's associated grade_item without the category's ID being set.");
              return false;
          }
  
          if (empty($this->parent)) {
              $params = array('courseid'=>$this->courseid, 'itemtype'=>'course', 'iteminstance'=>$this->id);
  
          } else {
              $params = array('courseid'=>$this->courseid, 'itemtype'=>'category', 'iteminstance'=>$this->id);
          }
  
          if (!$grade_items = grade_item::fetch_all($params)) {
              // create a new one
              $grade_item = new grade_item($params, false);
              $grade_item->gradetype = GRADE_TYPE_VALUE;
              $grade_item->insert('system');
  
          } else if (count($grade_items) == 1) {
              // found existing one
              $grade_item = reset($grade_items);
  
          } else {
              debugging("Found more than one grade_item attached to category id:".$this->id);
              // return first one
              $grade_item = reset($grade_items);
          }
  
          return $grade_item;
      }
code_tokens: public function get_grade_item ( ) { if ( empty ( $ this -> id ) ) { debugging ( "Attempt to obtain a grade_category's associated grade_item without the category's ID being set." ) ; return false ; } if ( empty ( $ this -> parent ) ) { $ params = array ( 'courseid' => $ this -> courseid , 'itemtype' => 'course' , 'iteminstance' => $ this -> id ) ; } else { $ params = array ( 'courseid' => $ this -> courseid , 'itemtype' => 'category' , 'iteminstance' => $ this -> id ) ; } if ( ! $ grade_items = grade_item :: fetch_all ( $ params ) ) { // create a new one $ grade_item = new grade_item ( $ params , false ) ; $ grade_item -> gradetype = GRADE_TYPE_VALUE ; $ grade_item -> insert ( 'system' ) ; } else if ( count ( $ grade_items ) == 1 ) { // found existing one $ grade_item = reset ( $ grade_items ) ; } else { debugging ( "Found more than one grade_item attached to category id:" . $ this -> id ) ; // return first one $ grade_item = reset ( $ grade_items ) ; } return $ grade_item ; }
docstring: Retrieves this grade categories' associated grade_item from the database
  
  If no grade_item exists yet, creates one.
  
  @return grade_item
docstring_tokens: Retrieves this grade categories associated grade_item from the database