original_string: public static function create_cohort_role_assignment(stdClass $record) {
          $cohortroleassignment = new cohort_role_assignment(0, $record);
          $context = context_system::instance();
  
          // First we do a permissions check.
          require_capability('moodle/role:manage', $context);
  
          // Validate before we check for existing records.
          if (!$cohortroleassignment->is_valid()) {
              throw new invalid_persistent_exception($cohortroleassignment->get_errors());
          }
  
          $existing = cohort_role_assignment::get_record((array) $record);
          if (!empty($existing)) {
              return false;
          } else {
              // OK - all set.
              $cohortroleassignment->create();
          }
          return $cohortroleassignment;
      }
code: public static function create_cohort_role_assignment(stdClass $record) {
          $cohortroleassignment = new cohort_role_assignment(0, $record);
          $context = context_system::instance();
  
          // First we do a permissions check.
          require_capability('moodle/role:manage', $context);
  
          // Validate before we check for existing records.
          if (!$cohortroleassignment->is_valid()) {
              throw new invalid_persistent_exception($cohortroleassignment->get_errors());
          }
  
          $existing = cohort_role_assignment::get_record((array) $record);
          if (!empty($existing)) {
              return false;
          } else {
              // OK - all set.
              $cohortroleassignment->create();
          }
          return $cohortroleassignment;
      }
code_tokens: public static function create_cohort_role_assignment ( stdClass $ record ) { $ cohortroleassignment = new cohort_role_assignment ( 0 , $ record ) ; $ context = context_system :: instance ( ) ; // First we do a permissions check. require_capability ( 'moodle/role:manage' , $ context ) ; // Validate before we check for existing records. if ( ! $ cohortroleassignment -> is_valid ( ) ) { throw new invalid_persistent_exception ( $ cohortroleassignment -> get_errors ( ) ) ; } $ existing = cohort_role_assignment :: get_record ( ( array ) $ record ) ; if ( ! empty ( $ existing ) ) { return false ; } else { // OK - all set. $ cohortroleassignment -> create ( ) ; } return $ cohortroleassignment ; }
docstring: Create a cohort role assignment from a record containing all the data for the class.
  
  Requires moodle/role:manage capability at the system context.
  
  @param stdClass $record Record containing all the data for an instance of the class.
  @return competency
docstring_tokens: Create a cohort role assignment from a record containing all the data for the class .