original_string: public function force_preset($xml, array $options) {
          if (!$info = core_role_preset::parse_preset($xml)) {
              throw new coding_exception('Invalid role preset');
          }
  
          if ($options['shortname']) {
              if (isset($info['shortname'])) {
                  $this->role->shortname = $info['shortname'];
              }
          }
  
          if ($options['name']) {
              if (isset($info['name'])) {
                  $this->role->name = $info['name'];
              }
          }
  
          if ($options['description']) {
              if (isset($info['description'])) {
                  $this->role->description = $info['description'];
              }
          }
  
          if ($options['archetype']) {
              if (isset($info['archetype'])) {
                  $this->role->archetype = $info['archetype'];
              }
          }
  
          if ($options['contextlevels']) {
              if (isset($info['contextlevels'])) {
                  $this->contextlevels = $info['contextlevels'];
              }
          }
  
          foreach (array('assign', 'override', 'switch', 'view') as $type) {
              if ($options['allow'.$type]) {
                  if (isset($info['allow'.$type])) {
                      $this->{'allow'.$type} = $info['allow'.$type];
                  }
              }
          }
  
          if ($options['permissions']) {
              foreach ($this->permissions as $k => $v) {
                  // Note: do not set everything else to CAP_INHERIT here
                  //       because the xml file might not contain all capabilities.
                  if (isset($info['permissions'][$k])) {
                      $this->permissions[$k] = $info['permissions'][$k];
                  }
              }
          }
      }
code: public function force_preset($xml, array $options) {
          if (!$info = core_role_preset::parse_preset($xml)) {
              throw new coding_exception('Invalid role preset');
          }
  
          if ($options['shortname']) {
              if (isset($info['shortname'])) {
                  $this->role->shortname = $info['shortname'];
              }
          }
  
          if ($options['name']) {
              if (isset($info['name'])) {
                  $this->role->name = $info['name'];
              }
          }
  
          if ($options['description']) {
              if (isset($info['description'])) {
                  $this->role->description = $info['description'];
              }
          }
  
          if ($options['archetype']) {
              if (isset($info['archetype'])) {
                  $this->role->archetype = $info['archetype'];
              }
          }
  
          if ($options['contextlevels']) {
              if (isset($info['contextlevels'])) {
                  $this->contextlevels = $info['contextlevels'];
              }
          }
  
          foreach (array('assign', 'override', 'switch', 'view') as $type) {
              if ($options['allow'.$type]) {
                  if (isset($info['allow'.$type])) {
                      $this->{'allow'.$type} = $info['allow'.$type];
                  }
              }
          }
  
          if ($options['permissions']) {
              foreach ($this->permissions as $k => $v) {
                  // Note: do not set everything else to CAP_INHERIT here
                  //       because the xml file might not contain all capabilities.
                  if (isset($info['permissions'][$k])) {
                      $this->permissions[$k] = $info['permissions'][$k];
                  }
              }
          }
      }
code_tokens: public function force_preset ( $ xml , array $ options ) { if ( ! $ info = core_role_preset :: parse_preset ( $ xml ) ) { throw new coding_exception ( 'Invalid role preset' ) ; } if ( $ options [ 'shortname' ] ) { if ( isset ( $ info [ 'shortname' ] ) ) { $ this -> role -> shortname = $ info [ 'shortname' ] ; } } if ( $ options [ 'name' ] ) { if ( isset ( $ info [ 'name' ] ) ) { $ this -> role -> name = $ info [ 'name' ] ; } } if ( $ options [ 'description' ] ) { if ( isset ( $ info [ 'description' ] ) ) { $ this -> role -> description = $ info [ 'description' ] ; } } if ( $ options [ 'archetype' ] ) { if ( isset ( $ info [ 'archetype' ] ) ) { $ this -> role -> archetype = $ info [ 'archetype' ] ; } } if ( $ options [ 'contextlevels' ] ) { if ( isset ( $ info [ 'contextlevels' ] ) ) { $ this -> contextlevels = $ info [ 'contextlevels' ] ; } } foreach ( array ( 'assign' , 'override' , 'switch' , 'view' ) as $ type ) { if ( $ options [ 'allow' . $ type ] ) { if ( isset ( $ info [ 'allow' . $ type ] ) ) { $ this -> { 'allow' . $ type } = $ info [ 'allow' . $ type ] ; } } } if ( $ options [ 'permissions' ] ) { foreach ( $ this -> permissions as $ k => $ v ) { // Note: do not set everything else to CAP_INHERIT here //       because the xml file might not contain all capabilities. if ( isset ( $ info [ 'permissions' ] [ $ k ] ) ) { $ this -> permissions [ $ k ] = $ info [ 'permissions' ] [ $ k ] ; } } } }
docstring: Change the role definition to match given preset.
  
  @param string $xml
  @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 preset .