original_string: public final function set_user_config($config, $userid=0) {
          global $DB;
  
          if (empty($userid)) {
              $userid = $this->user->id;
          }
  
          foreach ($config as $key => $value) {
              if ($key != 'visible' && !in_array($key, $this->get_allowed_user_config())) {
                  $a = (object)array('property' => $key, 'class' => get_class($this));
                  throw new portfolio_export_exception($this->get('exporter'), 'invaliduserproperty', 'portfolio', null, $a);
              }
              if (!$existing = $DB->get_record('portfolio_instance_user', array('instance'=> $this->id, 'userid' => $userid, 'name' => $key))) {
                  $DB->insert_record('portfolio_instance_user', (object)array(
                      'instance' => $this->id,
                      'name' => $key,
                      'value' => $value,
                      'userid' => $userid,
                  ));
              } else if ($existing->value != $value) {
                  $DB->set_field('portfolio_instance_user', 'value', $value, array('name' => $key, 'instance' => $this->id, 'userid' => $userid));
              }
              $this->userconfig[$userid]->{$key} = $value;
          }
  
      }
code: public final function set_user_config($config, $userid=0) {
          global $DB;
  
          if (empty($userid)) {
              $userid = $this->user->id;
          }
  
          foreach ($config as $key => $value) {
              if ($key != 'visible' && !in_array($key, $this->get_allowed_user_config())) {
                  $a = (object)array('property' => $key, 'class' => get_class($this));
                  throw new portfolio_export_exception($this->get('exporter'), 'invaliduserproperty', 'portfolio', null, $a);
              }
              if (!$existing = $DB->get_record('portfolio_instance_user', array('instance'=> $this->id, 'userid' => $userid, 'name' => $key))) {
                  $DB->insert_record('portfolio_instance_user', (object)array(
                      'instance' => $this->id,
                      'name' => $key,
                      'value' => $value,
                      'userid' => $userid,
                  ));
              } else if ($existing->value != $value) {
                  $DB->set_field('portfolio_instance_user', 'value', $value, array('name' => $key, 'instance' => $this->id, 'userid' => $userid));
              }
              $this->userconfig[$userid]->{$key} = $value;
          }
  
      }
code_tokens: public final function set_user_config ( $ config , $ userid = 0 ) { global $ DB ; if ( empty ( $ userid ) ) { $ userid = $ this -> user -> id ; } foreach ( $ config as $ key => $ value ) { if ( $ key != 'visible' && ! in_array ( $ key , $ this -> get_allowed_user_config ( ) ) ) { $ a = ( object ) array ( 'property' => $ key , 'class' => get_class ( $ this ) ) ; throw new portfolio_export_exception ( $ this -> get ( 'exporter' ) , 'invaliduserproperty' , 'portfolio' , null , $ a ) ; } if ( ! $ existing = $ DB -> get_record ( 'portfolio_instance_user' , array ( 'instance' => $ this -> id , 'userid' => $ userid , 'name' => $ key ) ) ) { $ DB -> insert_record ( 'portfolio_instance_user' , ( object ) array ( 'instance' => $ this -> id , 'name' => $ key , 'value' => $ value , 'userid' => $ userid , ) ) ; } else if ( $ existing -> value != $ value ) { $ DB -> set_field ( 'portfolio_instance_user' , 'value' , $ value , array ( 'name' => $ key , 'instance' => $ this -> id , 'userid' => $ userid ) ) ; } $ this -> userconfig [ $ userid ] -> { $ key } = $ value ; } }
docstring: Sets config options for a given user.
  
  @param array $config array containing key/value pairs to set
  @param int $userid userid to set config for (defaults to current)
docstring_tokens: Sets config options for a given user .