original_string: public static function get_user_preferences($name = '', $userid = 0) {
          global $USER;
  
          $params = self::validate_parameters(self::get_user_preferences_parameters(),
                                              array(
                                                  'name' => $name,
                                                  'userid' => $userid
                                              ));
          $preferences = array();
          $warnings = array();
  
          $context = context_system::instance();
          self::validate_context($context);
  
          if (empty($params['name'])) {
              $name = null;
          }
          if (empty($params['userid'])) {
              $user = null;
          } else {
              $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
              core_user::require_active_user($user);
              if ($user->id != $USER->id) {
                  // Only admins can retrieve other users preferences.
                  require_capability('moodle/site:config', $context);
              }
          }
  
          $userpreferences = get_user_preferences($name, null, $user);
          // Check if we received just one preference.
          if (!is_array($userpreferences)) {
              $userpreferences = array($name => $userpreferences);
          }
  
          foreach ($userpreferences as $name => $value) {
              $preferences[] = array(
                  'name' => $name,
                  'value' => $value,
              );
          }
  
          $result = array();
          $result['preferences'] = $preferences;
          $result['warnings'] = $warnings;
          return $result;
      }
code: public static function get_user_preferences($name = '', $userid = 0) {
          global $USER;
  
          $params = self::validate_parameters(self::get_user_preferences_parameters(),
                                              array(
                                                  'name' => $name,
                                                  'userid' => $userid
                                              ));
          $preferences = array();
          $warnings = array();
  
          $context = context_system::instance();
          self::validate_context($context);
  
          if (empty($params['name'])) {
              $name = null;
          }
          if (empty($params['userid'])) {
              $user = null;
          } else {
              $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
              core_user::require_active_user($user);
              if ($user->id != $USER->id) {
                  // Only admins can retrieve other users preferences.
                  require_capability('moodle/site:config', $context);
              }
          }
  
          $userpreferences = get_user_preferences($name, null, $user);
          // Check if we received just one preference.
          if (!is_array($userpreferences)) {
              $userpreferences = array($name => $userpreferences);
          }
  
          foreach ($userpreferences as $name => $value) {
              $preferences[] = array(
                  'name' => $name,
                  'value' => $value,
              );
          }
  
          $result = array();
          $result['preferences'] = $preferences;
          $result['warnings'] = $warnings;
          return $result;
      }
code_tokens: public static function get_user_preferences ( $ name = '' , $ userid = 0 ) { global $ USER ; $ params = self :: validate_parameters ( self :: get_user_preferences_parameters ( ) , array ( 'name' => $ name , 'userid' => $ userid ) ) ; $ preferences = array ( ) ; $ warnings = array ( ) ; $ context = context_system :: instance ( ) ; self :: validate_context ( $ context ) ; if ( empty ( $ params [ 'name' ] ) ) { $ name = null ; } if ( empty ( $ params [ 'userid' ] ) ) { $ user = null ; } else { $ user = core_user :: get_user ( $ params [ 'userid' ] , '*' , MUST_EXIST ) ; core_user :: require_active_user ( $ user ) ; if ( $ user -> id != $ USER -> id ) { // Only admins can retrieve other users preferences. require_capability ( 'moodle/site:config' , $ context ) ; } } $ userpreferences = get_user_preferences ( $ name , null , $ user ) ; // Check if we received just one preference. if ( ! is_array ( $ userpreferences ) ) { $ userpreferences = array ( $ name => $ userpreferences ) ; } foreach ( $ userpreferences as $ name => $ value ) { $ preferences [ ] = array ( 'name' => $ name , 'value' => $ value , ) ; } $ result = array ( ) ; $ result [ 'preferences' ] = $ preferences ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
docstring: Return user preferences.
  
  @param string $name preference name, empty for all
  @param int $userid id of the user, 0 for current user
  @return array of warnings and preferences
  @since Moodle 3.2
  @throws moodle_exception
docstring_tokens: Return user preferences .