original_string: public static function unenrol_user_enrolment($ueid) {
          global $CFG, $DB, $PAGE;
  
          $params = self::validate_parameters(self::unenrol_user_enrolment_parameters(), [
              'ueid' => $ueid
          ]);
  
          $result = false;
          $errors = [];
  
          $userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*');
          if ($userenrolment) {
              $userid = $userenrolment->userid;
              $enrolid = $userenrolment->enrolid;
              $enrol = $DB->get_record('enrol', ['id' => $enrolid], '*', MUST_EXIST);
              $courseid = $enrol->courseid;
              $course = get_course($courseid);
              $context = context_course::instance($course->id);
              self::validate_context($context);
          } else {
              $validationerrors['invalidrequest'] = get_string('invalidrequest', 'enrol');
          }
  
          // If the userenrolment exists, unenrol the user.
          if (!isset($validationerrors)) {
              require_once($CFG->dirroot . '/enrol/locallib.php');
              $manager = new course_enrolment_manager($PAGE, $course);
              $result = $manager->unenrol_user($userenrolment);
          } else {
              foreach ($validationerrors as $key => $errormessage) {
                  $errors[] = (object)[
                      'key' => $key,
                      'message' => $errormessage
                  ];
              }
          }
  
          return [
              'result' => $result,
              'errors' => $errors,
          ];
      }
code: public static function unenrol_user_enrolment($ueid) {
          global $CFG, $DB, $PAGE;
  
          $params = self::validate_parameters(self::unenrol_user_enrolment_parameters(), [
              'ueid' => $ueid
          ]);
  
          $result = false;
          $errors = [];
  
          $userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*');
          if ($userenrolment) {
              $userid = $userenrolment->userid;
              $enrolid = $userenrolment->enrolid;
              $enrol = $DB->get_record('enrol', ['id' => $enrolid], '*', MUST_EXIST);
              $courseid = $enrol->courseid;
              $course = get_course($courseid);
              $context = context_course::instance($course->id);
              self::validate_context($context);
          } else {
              $validationerrors['invalidrequest'] = get_string('invalidrequest', 'enrol');
          }
  
          // If the userenrolment exists, unenrol the user.
          if (!isset($validationerrors)) {
              require_once($CFG->dirroot . '/enrol/locallib.php');
              $manager = new course_enrolment_manager($PAGE, $course);
              $result = $manager->unenrol_user($userenrolment);
          } else {
              foreach ($validationerrors as $key => $errormessage) {
                  $errors[] = (object)[
                      'key' => $key,
                      'message' => $errormessage
                  ];
              }
          }
  
          return [
              'result' => $result,
              'errors' => $errors,
          ];
      }
code_tokens: public static function unenrol_user_enrolment ( $ ueid ) { global $ CFG , $ DB , $ PAGE ; $ params = self :: validate_parameters ( self :: unenrol_user_enrolment_parameters ( ) , [ 'ueid' => $ ueid ] ) ; $ result = false ; $ errors = [ ] ; $ userenrolment = $ DB -> get_record ( 'user_enrolments' , [ 'id' => $ params [ 'ueid' ] ] , '*' ) ; if ( $ userenrolment ) { $ userid = $ userenrolment -> userid ; $ enrolid = $ userenrolment -> enrolid ; $ enrol = $ DB -> get_record ( 'enrol' , [ 'id' => $ enrolid ] , '*' , MUST_EXIST ) ; $ courseid = $ enrol -> courseid ; $ course = get_course ( $ courseid ) ; $ context = context_course :: instance ( $ course -> id ) ; self :: validate_context ( $ context ) ; } else { $ validationerrors [ 'invalidrequest' ] = get_string ( 'invalidrequest' , 'enrol' ) ; } // If the userenrolment exists, unenrol the user. if ( ! isset ( $ validationerrors ) ) { require_once ( $ CFG -> dirroot . '/enrol/locallib.php' ) ; $ manager = new course_enrolment_manager ( $ PAGE , $ course ) ; $ result = $ manager -> unenrol_user ( $ userenrolment ) ; } else { foreach ( $ validationerrors as $ key => $ errormessage ) { $ errors [ ] = ( object ) [ 'key' => $ key , 'message' => $ errormessage ] ; } } return [ 'result' => $ result , 'errors' => $ errors , ] ; }
docstring: External function that unenrols a given user enrolment.
  
  @param int $ueid The user enrolment ID.
  @return array An array consisting of the processing result, errors.
docstring_tokens: External function that unenrols a given user enrolment .