original_string: public static function update_activity_completion_status_manually($cmid,  $completed) {
  
          // Validate and normalize parameters.
          $params = self::validate_parameters(self::update_activity_completion_status_manually_parameters(),
              array('cmid' => $cmid, 'completed' => $completed));
          $cmid = $params['cmid'];
          $completed = $params['completed'];
  
          $warnings = array();
  
          $context = context_module::instance($cmid);
          self::validate_context($context);
          require_capability('moodle/course:togglecompletion', $context);
  
          list($course, $cm) = get_course_and_cm_from_cmid($cmid);
  
          // Set up completion object and check it is enabled.
          $completion = new completion_info($course);
          if (!$completion->is_enabled()) {
              throw new moodle_exception('completionnotenabled', 'completion');
          }
  
          // Check completion state is manual.
          if ($cm->completion != COMPLETION_TRACKING_MANUAL) {
              throw new moodle_exception('cannotmanualctrack', 'error');
          }
  
          $targetstate = ($completed) ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
          $completion->update_state($cm, $targetstate);
  
          $result = array();
          $result['status'] = true;
          $result['warnings'] = $warnings;
          return $result;
      }
code: public static function update_activity_completion_status_manually($cmid,  $completed) {
  
          // Validate and normalize parameters.
          $params = self::validate_parameters(self::update_activity_completion_status_manually_parameters(),
              array('cmid' => $cmid, 'completed' => $completed));
          $cmid = $params['cmid'];
          $completed = $params['completed'];
  
          $warnings = array();
  
          $context = context_module::instance($cmid);
          self::validate_context($context);
          require_capability('moodle/course:togglecompletion', $context);
  
          list($course, $cm) = get_course_and_cm_from_cmid($cmid);
  
          // Set up completion object and check it is enabled.
          $completion = new completion_info($course);
          if (!$completion->is_enabled()) {
              throw new moodle_exception('completionnotenabled', 'completion');
          }
  
          // Check completion state is manual.
          if ($cm->completion != COMPLETION_TRACKING_MANUAL) {
              throw new moodle_exception('cannotmanualctrack', 'error');
          }
  
          $targetstate = ($completed) ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
          $completion->update_state($cm, $targetstate);
  
          $result = array();
          $result['status'] = true;
          $result['warnings'] = $warnings;
          return $result;
      }
code_tokens: public static function update_activity_completion_status_manually ( $ cmid , $ completed ) { // Validate and normalize parameters. $ params = self :: validate_parameters ( self :: update_activity_completion_status_manually_parameters ( ) , array ( 'cmid' => $ cmid , 'completed' => $ completed ) ) ; $ cmid = $ params [ 'cmid' ] ; $ completed = $ params [ 'completed' ] ; $ warnings = array ( ) ; $ context = context_module :: instance ( $ cmid ) ; self :: validate_context ( $ context ) ; require_capability ( 'moodle/course:togglecompletion' , $ context ) ; list ( $ course , $ cm ) = get_course_and_cm_from_cmid ( $ cmid ) ; // Set up completion object and check it is enabled. $ completion = new completion_info ( $ course ) ; if ( ! $ completion -> is_enabled ( ) ) { throw new moodle_exception ( 'completionnotenabled' , 'completion' ) ; } // Check completion state is manual. if ( $ cm -> completion != COMPLETION_TRACKING_MANUAL ) { throw new moodle_exception ( 'cannotmanualctrack' , 'error' ) ; } $ targetstate = ( $ completed ) ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE ; $ completion -> update_state ( $ cm , $ targetstate ) ; $ result = array ( ) ; $ result [ 'status' ] = true ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
docstring: Update completion status for the current user in an activity, only for activities with manual tracking.
  @param  int $cmid      Course module id
  @param  bool $completed Activity completed or not
  @return array            Result and possible warnings
  @since Moodle 2.9
  @throws moodle_exception
docstring_tokens: Update completion status for the current user in an activity only for activities with manual tracking .