original_string: public static function delete_cohort_members($members) {
          global $CFG, $DB;
          require_once("$CFG->dirroot/cohort/lib.php");
  
          // Validate parameters.
          $params = self::validate_parameters(self::delete_cohort_members_parameters(), array('members' => $members));
  
          $transaction = $DB->start_delegated_transaction();
  
          foreach ($params['members'] as $member) {
              $cohortid = $member['cohortid'];
              $userid = $member['userid'];
  
              $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
              $user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id),
                  '*', MUST_EXIST);
  
              // Now security checks.
              $context = context::instance_by_id($cohort->contextid, MUST_EXIST);
              if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
                  throw new invalid_parameter_exception('Invalid context');
              }
              self::validate_context($context);
              if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:assign'), $context)) {
                  throw new required_capability_exception($context, 'moodle/cohort:assign', 'nopermissions', '');
              }
  
              cohort_remove_member($cohort->id, $user->id);
          }
          $transaction->allow_commit();
      }
code: public static function delete_cohort_members($members) {
          global $CFG, $DB;
          require_once("$CFG->dirroot/cohort/lib.php");
  
          // Validate parameters.
          $params = self::validate_parameters(self::delete_cohort_members_parameters(), array('members' => $members));
  
          $transaction = $DB->start_delegated_transaction();
  
          foreach ($params['members'] as $member) {
              $cohortid = $member['cohortid'];
              $userid = $member['userid'];
  
              $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
              $user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id),
                  '*', MUST_EXIST);
  
              // Now security checks.
              $context = context::instance_by_id($cohort->contextid, MUST_EXIST);
              if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
                  throw new invalid_parameter_exception('Invalid context');
              }
              self::validate_context($context);
              if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:assign'), $context)) {
                  throw new required_capability_exception($context, 'moodle/cohort:assign', 'nopermissions', '');
              }
  
              cohort_remove_member($cohort->id, $user->id);
          }
          $transaction->allow_commit();
      }
code_tokens: public static function delete_cohort_members ( $ members ) { global $ CFG , $ DB ; require_once ( "$CFG->dirroot/cohort/lib.php" ) ; // Validate parameters. $ params = self :: validate_parameters ( self :: delete_cohort_members_parameters ( ) , array ( 'members' => $ members ) ) ; $ transaction = $ DB -> start_delegated_transaction ( ) ; foreach ( $ params [ 'members' ] as $ member ) { $ cohortid = $ member [ 'cohortid' ] ; $ userid = $ member [ 'userid' ] ; $ cohort = $ DB -> get_record ( 'cohort' , array ( 'id' => $ cohortid ) , '*' , MUST_EXIST ) ; $ user = $ DB -> get_record ( 'user' , array ( 'id' => $ userid , 'deleted' => 0 , 'mnethostid' => $ CFG -> mnet_localhost_id ) , '*' , MUST_EXIST ) ; // Now security checks. $ context = context :: instance_by_id ( $ cohort -> contextid , MUST_EXIST ) ; if ( $ context -> contextlevel != CONTEXT_COURSECAT and $ context -> contextlevel != CONTEXT_SYSTEM ) { throw new invalid_parameter_exception ( 'Invalid context' ) ; } self :: validate_context ( $ context ) ; if ( ! has_any_capability ( array ( 'moodle/cohort:manage' , 'moodle/cohort:assign' ) , $ context ) ) { throw new required_capability_exception ( $ context , 'moodle/cohort:assign' , 'nopermissions' , '' ) ; } cohort_remove_member ( $ cohort -> id , $ user -> id ) ; } $ transaction -> allow_commit ( ) ; }
docstring: Delete cohort members
  
  @param array $members of arrays with keys userid, cohortid
  @since Moodle 2.5
docstring_tokens: Delete cohort members