original_string: public static function add_rating($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $rating, $rateduserid,
                                          $aggregation = RATING_AGGREGATE_NONE) {
          $warnings = array();
  
          $params = array(
              'contextlevel' => $contextlevel,
              'instanceid'   => $instanceid,
              'component'    => $component,
              'ratingarea'   => $ratingarea,
              'itemid'       => $itemid,
              'scaleid'      => $scaleid,
              'rating'       => $rating,
              'rateduserid'  => $rateduserid,
              'aggregation'  => $aggregation,
          );
  
          // Validate and normalize parameters.
          $params = self::validate_parameters(self::add_rating_parameters(), $params);
  
          $context = self::get_context_from_params($params);
          self::validate_context($context);
          $cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
  
          require_capability('moodle/rating:rate', $context);
  
          $rm = new rating_manager();
          $result = $rm->add_rating($cm, $context, $params['component'], $params['ratingarea'], $params['itemid'], $params['scaleid'],
                                      $params['rating'], $params['rateduserid'], $params['aggregation']);
  
          if (!empty($result->error)) {
              throw new moodle_exception($result->error, 'rating');
          }
  
          $returndata = array(
              'success' => $result->success,
              'warnings' => $warnings
          );
  
          if (isset($result->aggregate)) {
              $returndata['aggregate'] = $result->aggregate;
              $returndata['count'] = $result->count;
              $returndata['itemid'] = $result->itemid;
          }
  
          return $returndata;
      }
code: public static function add_rating($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $rating, $rateduserid,
                                          $aggregation = RATING_AGGREGATE_NONE) {
          $warnings = array();
  
          $params = array(
              'contextlevel' => $contextlevel,
              'instanceid'   => $instanceid,
              'component'    => $component,
              'ratingarea'   => $ratingarea,
              'itemid'       => $itemid,
              'scaleid'      => $scaleid,
              'rating'       => $rating,
              'rateduserid'  => $rateduserid,
              'aggregation'  => $aggregation,
          );
  
          // Validate and normalize parameters.
          $params = self::validate_parameters(self::add_rating_parameters(), $params);
  
          $context = self::get_context_from_params($params);
          self::validate_context($context);
          $cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
  
          require_capability('moodle/rating:rate', $context);
  
          $rm = new rating_manager();
          $result = $rm->add_rating($cm, $context, $params['component'], $params['ratingarea'], $params['itemid'], $params['scaleid'],
                                      $params['rating'], $params['rateduserid'], $params['aggregation']);
  
          if (!empty($result->error)) {
              throw new moodle_exception($result->error, 'rating');
          }
  
          $returndata = array(
              'success' => $result->success,
              'warnings' => $warnings
          );
  
          if (isset($result->aggregate)) {
              $returndata['aggregate'] = $result->aggregate;
              $returndata['count'] = $result->count;
              $returndata['itemid'] = $result->itemid;
          }
  
          return $returndata;
      }
code_tokens: public static function add_rating ( $ contextlevel , $ instanceid , $ component , $ ratingarea , $ itemid , $ scaleid , $ rating , $ rateduserid , $ aggregation = RATING_AGGREGATE_NONE ) { $ warnings = array ( ) ; $ params = array ( 'contextlevel' => $ contextlevel , 'instanceid' => $ instanceid , 'component' => $ component , 'ratingarea' => $ ratingarea , 'itemid' => $ itemid , 'scaleid' => $ scaleid , 'rating' => $ rating , 'rateduserid' => $ rateduserid , 'aggregation' => $ aggregation , ) ; // Validate and normalize parameters. $ params = self :: validate_parameters ( self :: add_rating_parameters ( ) , $ params ) ; $ context = self :: get_context_from_params ( $ params ) ; self :: validate_context ( $ context ) ; $ cm = get_coursemodule_from_id ( false , $ context -> instanceid , 0 , false , MUST_EXIST ) ; require_capability ( 'moodle/rating:rate' , $ context ) ; $ rm = new rating_manager ( ) ; $ result = $ rm -> add_rating ( $ cm , $ context , $ params [ 'component' ] , $ params [ 'ratingarea' ] , $ params [ 'itemid' ] , $ params [ 'scaleid' ] , $ params [ 'rating' ] , $ params [ 'rateduserid' ] , $ params [ 'aggregation' ] ) ; if ( ! empty ( $ result -> error ) ) { throw new moodle_exception ( $ result -> error , 'rating' ) ; } $ returndata = array ( 'success' => $ result -> success , 'warnings' => $ warnings ) ; if ( isset ( $ result -> aggregate ) ) { $ returndata [ 'aggregate' ] = $ result -> aggregate ; $ returndata [ 'count' ] = $ result -> count ; $ returndata [ 'itemid' ] = $ result -> itemid ; } return $ returndata ; }
docstring: Adds a rating to an item
  
  @param string $contextlevel course, module, user...
  @param int $instanceid the instance if for the context element
  @param string $component the name of the component
  @param string $ratingarea rating area
  @param int $itemid the item id
  @param int $scaleid the scale id
  @param int $rating the user rating
  @param int $rateduserid the rated user id
  @param int $aggregation the aggregation method
  @return array result and possible warnings
  @throws moodle_exception
  @since Moodle 3.2
docstring_tokens: Adds a rating to an item