original_string: public function force_archetype($archetype, array $options) {
          $archetypes = get_role_archetypes();
          if (!isset($archetypes[$archetype])) {
              throw new coding_exception('Unknown archetype: '.$archetype);
          }
  
          if ($options['shortname']) {
              $this->role->shortname = '';
          }
  
          if ($options['name']) {
              $this->role->name = '';
          }
  
          if ($options['description']) {
              $this->role->description = '';
          }
  
          if ($options['archetype']) {
              $this->role->archetype = $archetype;
          }
  
          if ($options['contextlevels']) {
              $this->contextlevels = array();
              $defaults = get_default_contextlevels($archetype);
              foreach ($defaults as $cl) {
                  $this->contextlevels[$cl] = $cl;
              }
          }
  
          if ($options['allowassign']) {
              $this->allowassign = get_default_role_archetype_allows('assign', $archetype);
          }
          if ($options['allowoverride']) {
              $this->allowoverride = get_default_role_archetype_allows('override', $archetype);
          }
          if ($options['allowswitch']) {
              $this->allowswitch = get_default_role_archetype_allows('switch', $archetype);
          }
          if ($options['allowview']) {
              $this->allowview = get_default_role_archetype_allows('view', $archetype);
          }
  
          if ($options['permissions']) {
              $defaultpermissions = get_default_capabilities($archetype);
              foreach ($this->permissions as $k => $v) {
                  if (isset($defaultpermissions[$k])) {
                      $this->permissions[$k] = $defaultpermissions[$k];
                      continue;
                  }
                  $this->permissions[$k] = CAP_INHERIT;
              }
          }
      }
code: public function force_archetype($archetype, array $options) {
          $archetypes = get_role_archetypes();
          if (!isset($archetypes[$archetype])) {
              throw new coding_exception('Unknown archetype: '.$archetype);
          }
  
          if ($options['shortname']) {
              $this->role->shortname = '';
          }
  
          if ($options['name']) {
              $this->role->name = '';
          }
  
          if ($options['description']) {
              $this->role->description = '';
          }
  
          if ($options['archetype']) {
              $this->role->archetype = $archetype;
          }
  
          if ($options['contextlevels']) {
              $this->contextlevels = array();
              $defaults = get_default_contextlevels($archetype);
              foreach ($defaults as $cl) {
                  $this->contextlevels[$cl] = $cl;
              }
          }
  
          if ($options['allowassign']) {
              $this->allowassign = get_default_role_archetype_allows('assign', $archetype);
          }
          if ($options['allowoverride']) {
              $this->allowoverride = get_default_role_archetype_allows('override', $archetype);
          }
          if ($options['allowswitch']) {
              $this->allowswitch = get_default_role_archetype_allows('switch', $archetype);
          }
          if ($options['allowview']) {
              $this->allowview = get_default_role_archetype_allows('view', $archetype);
          }
  
          if ($options['permissions']) {
              $defaultpermissions = get_default_capabilities($archetype);
              foreach ($this->permissions as $k => $v) {
                  if (isset($defaultpermissions[$k])) {
                      $this->permissions[$k] = $defaultpermissions[$k];
                      continue;
                  }
                  $this->permissions[$k] = CAP_INHERIT;
              }
          }
      }
code_tokens: public function force_archetype ( $ archetype , array $ options ) { $ archetypes = get_role_archetypes ( ) ; if ( ! isset ( $ archetypes [ $ archetype ] ) ) { throw new coding_exception ( 'Unknown archetype: ' . $ archetype ) ; } if ( $ options [ 'shortname' ] ) { $ this -> role -> shortname = '' ; } if ( $ options [ 'name' ] ) { $ this -> role -> name = '' ; } if ( $ options [ 'description' ] ) { $ this -> role -> description = '' ; } if ( $ options [ 'archetype' ] ) { $ this -> role -> archetype = $ archetype ; } if ( $ options [ 'contextlevels' ] ) { $ this -> contextlevels = array ( ) ; $ defaults = get_default_contextlevels ( $ archetype ) ; foreach ( $ defaults as $ cl ) { $ this -> contextlevels [ $ cl ] = $ cl ; } } if ( $ options [ 'allowassign' ] ) { $ this -> allowassign = get_default_role_archetype_allows ( 'assign' , $ archetype ) ; } if ( $ options [ 'allowoverride' ] ) { $ this -> allowoverride = get_default_role_archetype_allows ( 'override' , $ archetype ) ; } if ( $ options [ 'allowswitch' ] ) { $ this -> allowswitch = get_default_role_archetype_allows ( 'switch' , $ archetype ) ; } if ( $ options [ 'allowview' ] ) { $ this -> allowview = get_default_role_archetype_allows ( 'view' , $ archetype ) ; } if ( $ options [ 'permissions' ] ) { $ defaultpermissions = get_default_capabilities ( $ archetype ) ; foreach ( $ this -> permissions as $ k => $ v ) { if ( isset ( $ defaultpermissions [ $ k ] ) ) { $ this -> permissions [ $ k ] = $ defaultpermissions [ $ k ] ; continue ; } $ this -> permissions [ $ k ] = CAP_INHERIT ; } } }
docstring: Change the role definition to match given archetype.
  
  @param string $archetype
  @param array $options array with following keys:
  'name', 'shortname', 'description', 'permissions', 'archetype',
  'contextlevels', 'allowassign', 'allowoverride', 'allowswitch',
  'allowview'
docstring_tokens: Change the role definition to match given archetype .