original_string: public static function unenrol_users($enrolments) {
          global $CFG, $DB;
          $params = self::validate_parameters(self::unenrol_users_parameters(), array('enrolments' => $enrolments));
          require_once($CFG->libdir . '/enrollib.php');
          $transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs.
          $enrol = enrol_get_plugin('manual');
          if (empty($enrol)) {
              throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual');
          }
  
          foreach ($params['enrolments'] as $enrolment) {
              $context = context_course::instance($enrolment['courseid']);
              self::validate_context($context);
              require_capability('enrol/manual:unenrol', $context);
              $instance = $DB->get_record('enrol', array('courseid' => $enrolment['courseid'], 'enrol' => 'manual'));
              if (!$instance) {
                  throw new moodle_exception('wsnoinstance', 'enrol_manual', $enrolment);
              }
              $user = $DB->get_record('user', array('id' => $enrolment['userid']));
              if (!$user) {
                  throw new invalid_parameter_exception('User id not exist: '.$enrolment['userid']);
              }
              if (!$enrol->allow_unenrol($instance)) {
                  throw new moodle_exception('wscannotunenrol', 'enrol_manual', '', $enrolment);
              }
              $enrol->unenrol_user($instance, $enrolment['userid']);
          }
          $transaction->allow_commit();
      }
code: public static function unenrol_users($enrolments) {
          global $CFG, $DB;
          $params = self::validate_parameters(self::unenrol_users_parameters(), array('enrolments' => $enrolments));
          require_once($CFG->libdir . '/enrollib.php');
          $transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs.
          $enrol = enrol_get_plugin('manual');
          if (empty($enrol)) {
              throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual');
          }
  
          foreach ($params['enrolments'] as $enrolment) {
              $context = context_course::instance($enrolment['courseid']);
              self::validate_context($context);
              require_capability('enrol/manual:unenrol', $context);
              $instance = $DB->get_record('enrol', array('courseid' => $enrolment['courseid'], 'enrol' => 'manual'));
              if (!$instance) {
                  throw new moodle_exception('wsnoinstance', 'enrol_manual', $enrolment);
              }
              $user = $DB->get_record('user', array('id' => $enrolment['userid']));
              if (!$user) {
                  throw new invalid_parameter_exception('User id not exist: '.$enrolment['userid']);
              }
              if (!$enrol->allow_unenrol($instance)) {
                  throw new moodle_exception('wscannotunenrol', 'enrol_manual', '', $enrolment);
              }
              $enrol->unenrol_user($instance, $enrolment['userid']);
          }
          $transaction->allow_commit();
      }
code_tokens: public static function unenrol_users ( $ enrolments ) { global $ CFG , $ DB ; $ params = self :: validate_parameters ( self :: unenrol_users_parameters ( ) , array ( 'enrolments' => $ enrolments ) ) ; require_once ( $ CFG -> libdir . '/enrollib.php' ) ; $ transaction = $ DB -> start_delegated_transaction ( ) ; // Rollback all enrolment if an error occurs. $ enrol = enrol_get_plugin ( 'manual' ) ; if ( empty ( $ enrol ) ) { throw new moodle_exception ( 'manualpluginnotinstalled' , 'enrol_manual' ) ; } foreach ( $ params [ 'enrolments' ] as $ enrolment ) { $ context = context_course :: instance ( $ enrolment [ 'courseid' ] ) ; self :: validate_context ( $ context ) ; require_capability ( 'enrol/manual:unenrol' , $ context ) ; $ instance = $ DB -> get_record ( 'enrol' , array ( 'courseid' => $ enrolment [ 'courseid' ] , 'enrol' => 'manual' ) ) ; if ( ! $ instance ) { throw new moodle_exception ( 'wsnoinstance' , 'enrol_manual' , $ enrolment ) ; } $ user = $ DB -> get_record ( 'user' , array ( 'id' => $ enrolment [ 'userid' ] ) ) ; if ( ! $ user ) { throw new invalid_parameter_exception ( 'User id not exist: ' . $ enrolment [ 'userid' ] ) ; } if ( ! $ enrol -> allow_unenrol ( $ instance ) ) { throw new moodle_exception ( 'wscannotunenrol' , 'enrol_manual' , '' , $ enrolment ) ; } $ enrol -> unenrol_user ( $ instance , $ enrolment [ 'userid' ] ) ; } $ transaction -> allow_commit ( ) ; }
docstring: Unenrolment of users.
  
  @param array $enrolments an array of course user and role ids
  @throws coding_exception
  @throws dml_transaction_exception
  @throws invalid_parameter_exception
  @throws moodle_exception
  @throws required_capability_exception
  @throws restricted_context_exception
docstring_tokens: Unenrolment of users .