本文整理汇总了PHP中profile_save_data函数的典型用法代码示例。如果您正苦于以下问题:PHP profile_save_data函数的具体用法?PHP profile_save_data怎么用?PHP profile_save_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了profile_save_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object (with system magic quotes)
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG;
require_once $CFG->dirroot . '/user/profile/lib.php';
$user->password = hash_internal_user_password($user->password);
if (!($user->id = insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
/// Save any custom profile field information
profile_save_data($user);
$user = get_record('user', 'id', $user->id);
events_trigger('user_created', $user);
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
global $CFG;
$emailconfirm = get_string('emailconfirm');
$navlinks = array();
$navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header($emailconfirm, $emailconfirm, $navigation);
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
示例2: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
$user->password = hash_internal_user_password($user->password);
$user->id = $DB->insert_record('user', $user);
/// Save any custom profile field information
profile_save_data($user);
$user = $DB->get_record('user', array('id' => $user->id));
events_trigger('user_created', $user);
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth_email');
}
if ($notify) {
global $CFG, $PAGE, $OUTPUT;
$emailconfirm = get_string('emailconfirm');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($PAGE->course->fullname);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
示例3: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
public function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
$plainpassword = $user->password;
$user->password = hash_internal_user_password($user->password);
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$user->id = user_create_user($user, false, false);
user_add_password_history($user->id, $plainpassword);
// Save any custom profile field information.
profile_save_data($user);
// Trigger event.
\core\event\user_created::create_from_userid($user->id)->trigger();
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail, auth_email');
}
if ($notify) {
global $CFG, $PAGE, $OUTPUT;
$emailconfirm = get_string('emailconfirm');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($PAGE->course->fullname);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
示例4: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object (with system magic quotes)
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify = true)
{
global $CFG;
require_once $CFG->dirroot . '/user/profile/lib.php';
$user->password = hash_internal_user_password($user->password);
if (!($user->id = insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
/// Save any custom profile field information
profile_save_data($user);
//Added by JAM: 12.02.2010 - Call the set user time-zone for WS, cannot set time-zone until, user is created
setWSUserDefaultTimeZone($user->username, $user);
$user = get_record('user', 'id', $user->id);
events_trigger('user_created', $user);
//Added by JAM: 01.06.2011 - this is where the user id exists
if (!addQSUser($user)) {
admin_signuperror_email($user);
// Added: JAM - 01.06.2011
//error('An error has occured, please try again shortly.');
}
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
global $CFG;
$emailconfirm = get_string('emailconfirm');
$navlinks = array();
$navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header($emailconfirm, $emailconfirm, $navigation);
// Added by SMS: 7/28/2011
$data = new object();
$data->useremail = $user->email;
$supportuser = generate_email_supportuser();
$data->adminemail = $supportuser->email;
// Edited by SMS: 7/28/2011
// notice(get_string('emailconfirmsent', '', $user->email), "$CFG->wwwroot/index.php");
notice(get_string('emailconfirmsent', '', $data), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
示例5: application_user_signup
function application_user_signup($user)
{
// Derived from email->user_signup
global $CFG, $PAGE, $OUTPUT;
$user->password = hash_internal_user_password($user->password);
if (empty($user->calendartype)) {
$user->calendartype = $CFG->calendartype;
}
$user->id = user_create_user($user, false, false);
// Save any custom profile field information
profile_save_data($user);
// Save contact information
write_contact_details($user->id, $user);
// Trigger event
\core\event\user_created::create_from_userid($user->id)->trigger();
if (!send_application_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth_email');
}
$PAGE->set_title($CFG->pageheading . ': ' . get_string('emailconfirm'));
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), $CFG->wwwroot . '/local/obu_application/login.php');
}
示例6: user_signup
function user_signup($user, $notify = true)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
$password_clear = $user->password;
$user->password = hash_internal_user_password($user->password);
if (!($user->id = $DB->insert_record('user', $user))) {
print_error('auth_emailnoinsert', 'auth');
}
/// Save any custom profile field information
profile_save_data($user);
$conditions = array('id' => $user->id);
$user = $DB->get_record('user', $conditions);
/* Create user in Joomla */
$userinfo['username'] = $user->username;
$userinfo['password'] = $password_clear;
$userinfo['password2'] = $password_clear;
$userinfo['name'] = $user->firstname . " " . $user->lastname;
$userinfo['email'] = $user->email;
$userinfo['block'] = 1;
$this->call_method("createUser", $userinfo);
events_trigger('user_created', $user);
if (!send_confirmation_email($user)) {
print_error('auth_emailnoemail', 'auth');
}
if ($notify) {
global $CFG;
$emailconfirm = get_string('emailconfirm');
$navlinks = array();
$navlinks[] = array('name' => $emailconfirm, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header($emailconfirm, $emailconfirm, $navigation);
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
示例7: test_profile_has_required_custom_fields_set
/**
* Test that {@link user_not_fully_set_up()} takes required custom fields into account.
*/
public function test_profile_has_required_custom_fields_set()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/mnet/lib.php';
$this->resetAfterTest();
// Add a required, visible, unlocked custom field.
$DB->insert_record('user_info_field', ['shortname' => 'house', 'name' => 'House', 'required' => 1, 'visible' => 1, 'locked' => 0, 'categoryid' => 1, 'datatype' => 'text']);
// Add an optional, visible, unlocked custom field.
$DB->insert_record('user_info_field', ['shortname' => 'pet', 'name' => 'Pet', 'required' => 0, 'visible' => 1, 'locked' => 0, 'categoryid' => 1, 'datatype' => 'text']);
// Add required but invisible custom field.
$DB->insert_record('user_info_field', ['shortname' => 'secretid', 'name' => 'Secret ID', 'required' => 1, 'visible' => 0, 'locked' => 0, 'categoryid' => 1, 'datatype' => 'text']);
// Add required but locked custom field.
$DB->insert_record('user_info_field', ['shortname' => 'muggleborn', 'name' => 'Muggle-born', 'required' => 1, 'visible' => 1, 'locked' => 1, 'categoryid' => 1, 'datatype' => 'checkbox']);
// Create some student accounts.
$hermione = $this->getDataGenerator()->create_user();
$harry = $this->getDataGenerator()->create_user();
$ron = $this->getDataGenerator()->create_user();
$draco = $this->getDataGenerator()->create_user();
// Hermione has all available custom fields filled (of course she has).
profile_save_data((object) ['id' => $hermione->id, 'profile_field_house' => 'Gryffindor']);
profile_save_data((object) ['id' => $hermione->id, 'profile_field_pet' => 'Crookshanks']);
// Harry has only the optional field filled.
profile_save_data((object) ['id' => $harry->id, 'profile_field_pet' => 'Hedwig']);
// Draco has only the required field filled.
profile_save_data((object) ['id' => $draco->id, 'profile_field_house' => 'Slytherin']);
// Only students with required fields filled should be considered as fully set up in the default (strict) mode.
$this->assertFalse(user_not_fully_set_up($hermione));
$this->assertFalse(user_not_fully_set_up($draco));
$this->assertTrue(user_not_fully_set_up($harry));
$this->assertTrue(user_not_fully_set_up($ron));
// In the lax mode, students do not need to have required fields filled.
$this->assertFalse(user_not_fully_set_up($hermione, false));
$this->assertFalse(user_not_fully_set_up($draco, false));
$this->assertFalse(user_not_fully_set_up($harry, false));
$this->assertFalse(user_not_fully_set_up($ron, false));
// Lack of required core field is seen as a problem in either mode.
unset($hermione->email);
$this->assertTrue(user_not_fully_set_up($hermione, true));
$this->assertTrue(user_not_fully_set_up($hermione, false));
// When confirming remote MNet users, we do not have custom fields available.
$roamingharry = mnet_strip_user($harry, ['firstname', 'lastname', 'email']);
$roaminghermione = mnet_strip_user($hermione, ['firstname', 'lastname', 'email']);
$this->assertTrue(user_not_fully_set_up($roamingharry, true));
$this->assertFalse(user_not_fully_set_up($roamingharry, false));
$this->assertTrue(user_not_fully_set_up($roaminghermione, true));
$this->assertTrue(user_not_fully_set_up($roaminghermione, false));
}
示例8: user_signup
/**
* Sign up a new user ready for confirmation.
* Password is passed in plaintext.
*
* @param object $user new user object
* @param boolean $notify print notice with link and terminate
*/
function user_signup($user, $notify=true) {
global $CFG, $DB, $PAGE, $OUTPUT;
require_once($CFG->dirroot.'/user/profile/lib.php');
if ($this->user_exists($user->username)) {
print_error('auth_ldap_user_exists', 'auth_ldap');
}
$plainslashedpassword = $user->password;
unset($user->password);
if (! $this->user_create($user, $plainslashedpassword)) {
print_error('auth_ldap_create_error', 'auth_ldap');
}
$user->id = $DB->insert_record('user', $user);
// Save any custom profile field information
profile_save_data($user);
$this->update_user_record($user->username);
update_internal_user_password($user, $plainslashedpassword);
$user = $DB->get_record('user', array('id'=>$user->id));
events_trigger('user_created', $user);
if (! send_confirmation_email($user)) {
print_error('noemail', 'auth_ldap');
}
if ($notify) {
$emailconfirm = get_string('emailconfirm');
$PAGE->set_url('/auth/ldap/auth.php');
$PAGE->navbar->add($emailconfirm);
$PAGE->set_title($emailconfirm);
$PAGE->set_heading($emailconfirm);
echo $OUTPUT->header();
notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
} else {
return true;
}
}
示例9: update_users
/**
* Update users
*
* @param array $users
* @return null
* @since Moodle 2.2
*/
public static function update_users($users)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/user/lib.php";
require_once $CFG->dirroot . "/user/profile/lib.php";
// Required for customfields related function.
// Ensure the current user is allowed to run this function.
$context = context_system::instance();
require_capability('moodle/user:update', $context);
self::validate_context($context);
$params = self::validate_parameters(self::update_users_parameters(), array('users' => $users));
$transaction = $DB->start_delegated_transaction();
foreach ($params['users'] as $user) {
user_update_user($user, true, false);
// Update user custom fields.
if (!empty($user['customfields'])) {
foreach ($user['customfields'] as $customfield) {
// Profile_save_data() saves profile file it's expecting a user with the correct id,
// and custom field to be named profile_field_"shortname".
$user["profile_field_" . $customfield['type']] = $customfield['value'];
}
profile_save_data((object) $user);
}
// Trigger event.
\core\event\user_updated::create_from_userid($user['id'])->trigger();
// Preferences.
if (!empty($user['preferences'])) {
foreach ($user['preferences'] as $preference) {
set_user_preference($preference['type'], $preference['value'], $user['id']);
}
}
}
$transaction->allow_commit();
return null;
}
示例10: create_users
/**
* Create one or more users.
*
* @throws invalid_parameter_exception
* @param array $users An array of users to create.
* @return array An array of arrays
* @since Moodle 2.2
*/
public static function create_users($users)
{
global $CFG, $DB;
require_once $CFG->dirroot . "/lib/weblib.php";
require_once $CFG->dirroot . "/user/lib.php";
require_once $CFG->dirroot . "/user/profile/lib.php";
// Required for customfields related function.
// Ensure the current user is allowed to run this function.
$context = context_system::instance();
self::validate_context($context);
require_capability('moodle/user:create', $context);
// Do basic automatic PARAM checks on incoming data, using params description.
// If any problems are found then exceptions are thrown with helpful error messages.
$params = self::validate_parameters(self::create_users_parameters(), array('users' => $users));
$availableauths = core_component::get_plugin_list('auth');
unset($availableauths['mnet']);
// These would need mnethostid too.
unset($availableauths['webservice']);
// We do not want new webservice users for now.
$availablethemes = core_component::get_plugin_list('theme');
$availablelangs = get_string_manager()->get_list_of_translations();
$transaction = $DB->start_delegated_transaction();
$userids = array();
foreach ($params['users'] as $user) {
// Make sure that the username doesn't already exist.
if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
throw new invalid_parameter_exception('Username already exists: ' . $user['username']);
}
// Make sure auth is valid.
if (empty($availableauths[$user['auth']])) {
throw new invalid_parameter_exception('Invalid authentication type: ' . $user['auth']);
}
// Make sure lang is valid.
if (empty($availablelangs[$user['lang']])) {
throw new invalid_parameter_exception('Invalid language code: ' . $user['lang']);
}
// Make sure lang is valid.
if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) {
// Theme is VALUE_OPTIONAL,
// so no default value
// We need to test if the client sent it
// => !empty($user['theme']).
throw new invalid_parameter_exception('Invalid theme: ' . $user['theme']);
}
$user['confirmed'] = true;
$user['mnethostid'] = $CFG->mnet_localhost_id;
// Start of user info validation.
// Make sure we validate current user info as handled by current GUI. See user/editadvanced_form.php func validation().
if (!validate_email($user['email'])) {
throw new invalid_parameter_exception('Email address is invalid: ' . $user['email']);
} else {
if ($DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $user['mnethostid']))) {
throw new invalid_parameter_exception('Email address already exists: ' . $user['email']);
}
}
// End of user info validation.
// Create the user data now!
$user['id'] = user_create_user($user, true, false);
// Custom fields.
if (!empty($user['customfields'])) {
foreach ($user['customfields'] as $customfield) {
// Profile_save_data() saves profile file it's expecting a user with the correct id,
// and custom field to be named profile_field_"shortname".
$user["profile_field_" . $customfield['type']] = $customfield['value'];
}
profile_save_data((object) $user);
}
// Trigger event.
\core\event\user_created::create_from_userid($user['id'])->trigger();
// Preferences.
if (!empty($user['preferences'])) {
foreach ($user['preferences'] as $preference) {
set_user_preference($preference['type'], $preference['value'], $user['id']);
}
}
//var_dump(array('id' => $user['id'], 'username' => $user['username']));
$userids[] = array('id' => $user['id'], 'username' => $user['username']);
}
$transaction->allow_commit();
return $userids;
}
示例11: test_modifyingmoodleuserupdatespmuser
/**
* Test that modifying a Moodle user also updates the corresponding PM user.
*/
public function test_modifyingmoodleuserupdatespmuser()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/admin/tool/uploaduser/locallib.php';
$this->load_csv_data();
// Update a record.
$src = new stdClass();
$src->id = 100;
$src->firstname = 'Testuser';
$src->lastname = 'One';
$src->profile_field_sometext = 'boo';
$src->profile_field_sometextfrompm = 'bla';
$DB->update_record('user', $src);
$mdluser = $DB->get_record('user', array('id' => 100));
$mcopy = clone $src;
$mcopy = uu_pre_process_custom_profile_data($mcopy);
profile_save_data($mcopy);
events_trigger('user_updated', $mdluser);
// Read the PM user and compare.
$retr = new user(103, null, array(), false, array());
$retr->reset_custom_field_list();
$this->assertEquals($mdluser->firstname, $retr->firstname);
$this->assertEquals($mdluser->lastname, $retr->lastname);
// Check custom fields.
$result = new PHPUnit_Extensions_Database_DataSet_DefaultDataSet();
$result->addTable(new moodle_recordset_phpunit_datatable(field_data_int::TABLE, $DB->get_recordset(field_data_int::TABLE, null, '', 'contextid, fieldid, data')));
$result->addTable(new moodle_recordset_phpunit_datatable(field_data_char::TABLE, $DB->get_recordset(field_data_char::TABLE, null, '', 'contextid, fieldid, data')));
$result->addTable(new moodle_recordset_phpunit_datatable(field_data_text::TABLE, $DB->get_recordset(field_data_text::TABLE, null, '', 'contextid, fieldid, data')));
$usercontext = \local_elisprogram\context\user::instance(103);
$dataset = new PHPUnit_Extensions_Database_DataSet_CsvDataSet();
$dataset->addTable(field_data_int::TABLE, elispm::file('tests/fixtures/user_field_data_int.csv'));
$dataset->addTable(field_data_char::TABLE, elispm::file('tests/fixtures/user_field_data_char.csv'));
$dataset->addTable(field_data_text::TABLE, elispm::file('tests/fixtures/user_field_data_text.csv'));
$dataset = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($dataset);
$dataset->addFullReplacement('##USERCTXID##', $usercontext->id);
$dataset->addFullReplacement('##USERCTXLVL##', CONTEXT_ELIS_USER);
// Only the first text field should be changed; everything else should be the same.
$dataset->addFullReplacement('First text entry field', $src->profile_field_sometext);
$ret = $dataset->addFullReplacement('Second text entry field', $src->profile_field_sometextfrompm);
$this->assertDataSetsEqual($dataset, $result);
}
示例12: get_additional_user_info
/**
* Get additional information about a user from Azure AD.
*
* @param int $userid The ID of the user we want more information about.
* @param string $eventtype The type of event that triggered this call. "login" or "create".
* @return bool Success/Failure.
*/
public static function get_additional_user_info($userid, $eventtype)
{
global $DB;
try {
// Azure AD must be configured for us to fetch data.
if (\local_o365\rest\azuread::is_configured() !== true) {
return true;
}
$aadresource = \local_o365\rest\azuread::get_resource();
$sql = 'SELECT tok.*
FROM {auth_oidc_token} tok
JOIN {user} u
ON tok.username = u.username
WHERE u.id = ? AND tok.resource = ?';
$params = [$userid, $aadresource];
$tokenrec = $DB->get_record_sql($sql, $params);
if (empty($tokenrec)) {
// No OIDC token for this user and resource - maybe not an Azure AD user.
return false;
}
$httpclient = new \local_o365\httpclient();
$clientdata = \local_o365\oauth2\clientdata::instance_from_oidc();
$token = \local_o365\oauth2\token::instance($userid, $aadresource, $clientdata, $httpclient);
$apiclient = new \local_o365\rest\azuread($token, $httpclient);
$aaduserdata = $apiclient->get_user($tokenrec->oidcuniqid);
$updateduser = new \stdClass();
$updateduser = \local_o365\feature\usersync\main::apply_configured_fieldmap($aaduserdata, $updateduser, $eventtype);
if (!empty($updateduser)) {
$updateduser->id = $userid;
$DB->update_record('user', $updateduser);
profile_save_data($updateduser);
}
return true;
} catch (\Exception $e) {
\local_o365\utils::debug($e->getMessage());
}
return false;
}
示例13: create_user_from_aaddata
/**
* Create a Moodle user from Azure AD user data.
*
* @param array $aaddata Array of Azure AD user data.
* @return \stdClass An object representing the created Moodle user.
*/
public function create_user_from_aaddata($aaddata)
{
global $CFG;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
$newuser = (object) ['auth' => 'oidc', 'username' => trim(\core_text::strtolower($aaddata['userPrincipalName'])), 'email' => isset($aaddata['mail']) ? $aaddata['mail'] : '', 'firstname' => isset($aaddata['givenName']) ? $aaddata['givenName'] : '', 'lastname' => isset($aaddata['surname']) ? $aaddata['surname'] : '', 'city' => isset($aaddata['city']) ? $aaddata['city'] : '', 'country' => isset($aaddata['country']) ? $aaddata['country'] : '', 'department' => isset($aaddata['department']) ? $aaddata['department'] : '', 'lang' => isset($aaddata['preferredLanguage']) ? substr($aaddata['preferredLanguage'], 0, 2) : 'en', 'confirmed' => 1, 'timecreated' => time(), 'mnethostid' => $CFG->mnet_localhost_id];
$password = null;
$newuser->idnumber = $newuser->username;
if (!empty($newuser->email)) {
if (email_is_not_allowed($newuser->email)) {
unset($newuser->email);
}
}
if (empty($newuser->lang) || !get_string_manager()->translation_exists($newuser->lang)) {
$newuser->lang = $CFG->lang;
}
$newuser->timemodified = $newuser->timecreated;
$newuser->id = user_create_user($newuser, false, false);
// Save user profile data.
profile_save_data($newuser);
$user = get_complete_user_data('id', $newuser->id);
if (!empty($CFG->{'auth_' . $newuser->auth . '_forcechangepassword'})) {
set_user_preference('auth_forcepasswordchange', 1, $user);
}
// Set the password.
update_internal_user_password($user, $password);
// Trigger event.
\core\event\user_created::create_from_userid($newuser->id)->trigger();
return $user;
}
示例14: update_profile_fields
function update_profile_fields($user, $data)
{
profile_load_data($user);
$user->profile_field_state = $data->state;
$user->profile_field_companyName = $data->companyName;
$user->profile_field_website = $data->website;
$user->profile_field_zone = $data->zone;
//echo "<br/>-".$data->zone."-";
profile_save_data($user);
}
示例15: moodle_user_update_users
function moodle_user_update_users($client) {
global $DB, $CFG;
//Set test data
//a full user: user1
$user1 = new stdClass();
$user1->username = 'veryimprobabletestusername1';
$user1->password = 'testpassword1';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1@moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = 99;
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1'),
array('type' => $preferencename2, 'value' => 'preferencevalue2'));
$customfieldname1 = 'testdatacustom1';
$customfieldname2 = 'testdatacustom2';
$user1->customfields = array(
array('type' => $customfieldname1, 'value' => 'customvalue'),
array('type' => $customfieldname2, 'value' => 'customvalue2'));
//a small user: user2
$user2 = new stdClass();
$user2->username = 'veryimprobabletestusername2';
$user2->password = 'testpassword2';
$user2->firstname = 'testfirstname2';
$user2->lastname = 'testlastname2';
$user2->email = 'testemail1@moodle.com';
$users = array($user1, $user2);
//can run this test only if test usernames don't exist
$searchusers = $DB->get_records_list('user', 'username',
array($user1->username, $user1->username));
if (count($searchusers) == 0) {
//create two users
require_once($CFG->dirroot."/user/lib.php");
require_once($CFG->dirroot."/user/profile/lib.php");
$user1->id = user_create_user($user1);
//unset field created by user_create_user
unset($user1->timemodified);
unset($user1->timecreated);
// custom fields
if(!empty($user1->customfields)) {
foreach($user1->customfields as $customfield) {
$customuser1->id = $user1->id;
$customuser1->{"profile_field_".$customfield['type']} = $customfield['value'];
}
profile_save_data((object) $customuser1);
}
//preferences
if (!empty($user1->preferences)) {
foreach($user1->preferences as $preference) {
set_user_preference($preference['type'], $preference['value'],$user1->id);
}
}
$user2->id = user_create_user($user2);
unset($user2->timemodified);
unset($user2->timecreated);
//create the custom fields
$customfield = new stdClass();
$customfield->shortname = $customfieldname1;
$customfield->name = $customfieldname1;
$customfield->datatype = 'text';
$DB->insert_record('user_info_field', $customfield);
$customfield = new stdClass();
$customfield->shortname = $customfieldname2;
$customfield->name = $customfieldname2;
$customfield->datatype = 'text';
$DB->insert_record('user_info_field', $customfield);
//search for them => TEST they exists
$searchusers = $DB->get_records_list('user', 'username',
array($user1->username, $user2->username));
$this->assertEqual(count($users), count($searchusers));
//update the test data
$user1->username = 'veryimprobabletestusername1_updated';
$user1->password = 'testpassword1_updated';
$user1->firstname = 'testfirstname1_updated';
$user1->lastname = 'testlastname1_updated';
$user1->email = 'testemail1_updated@moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1_updated';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = 98;
$user1->mailformat = 1;
$user1->description = 'Hello World!_updated';
$user1->city = 'testcity1_updated';
//.........这里部分代码省略.........