original_string: protected function get_user_grade($courseitemid, $userid) {
          // If the user grade for this course is not available, get all the grades for the course.
          if (!isset($this->coursesgrades[$courseitemid])) {
              // Ony a course is cached to avoid high memory usage.
              unset($this->coursesgrades);
              $gg = new \grade_grade(null, false);
              $usersgrades = $gg->fetch_all(array('itemid' => $courseitemid));
  
              if ($usersgrades) {
                  foreach ($usersgrades as $ug) {
                      $this->coursesgrades[$courseitemid][$ug->userid] = $ug->finalgrade;
                  }
              }
          }
  
          if (!isset($this->coursesgrades[$courseitemid][$userid])) {
              $this->coursesgrades[$courseitemid][$userid] = null;
          }
  
          return $this->coursesgrades[$courseitemid][$userid];
      }
code: protected function get_user_grade($courseitemid, $userid) {
          // If the user grade for this course is not available, get all the grades for the course.
          if (!isset($this->coursesgrades[$courseitemid])) {
              // Ony a course is cached to avoid high memory usage.
              unset($this->coursesgrades);
              $gg = new \grade_grade(null, false);
              $usersgrades = $gg->fetch_all(array('itemid' => $courseitemid));
  
              if ($usersgrades) {
                  foreach ($usersgrades as $ug) {
                      $this->coursesgrades[$courseitemid][$ug->userid] = $ug->finalgrade;
                  }
              }
          }
  
          if (!isset($this->coursesgrades[$courseitemid][$userid])) {
              $this->coursesgrades[$courseitemid][$userid] = null;
          }
  
          return $this->coursesgrades[$courseitemid][$userid];
      }
code_tokens: protected function get_user_grade ( $ courseitemid , $ userid ) { // If the user grade for this course is not available, get all the grades for the course. if ( ! isset ( $ this -> coursesgrades [ $ courseitemid ] ) ) { // Ony a course is cached to avoid high memory usage. unset ( $ this -> coursesgrades ) ; $ gg = new \ grade_grade ( null , false ) ; $ usersgrades = $ gg -> fetch_all ( array ( 'itemid' => $ courseitemid ) ) ; if ( $ usersgrades ) { foreach ( $ usersgrades as $ ug ) { $ this -> coursesgrades [ $ courseitemid ] [ $ ug -> userid ] = $ ug -> finalgrade ; } } } if ( ! isset ( $ this -> coursesgrades [ $ courseitemid ] [ $ userid ] ) ) { $ this -> coursesgrades [ $ courseitemid ] [ $ userid ] = null ; } return $ this -> coursesgrades [ $ courseitemid ] [ $ userid ] ; }
docstring: Returns the grade of a user in a course.
  
  Saves the grades of all course users in $coursesgrades array to prevent new accesses to the database.
  
  @param  int $courseitemid The course item id.
  @param  int $userid the user whose grade is requested.
  @return array The courseitem id and the required grade to pass the course.
docstring_tokens: Returns the grade of a user in a course .