本文整理汇总了PHP中profile_user_record函数的典型用法代码示例。如果您正苦于以下问题:PHP profile_user_record函数的具体用法?PHP profile_user_record怎么用?PHP profile_user_record使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了profile_user_record函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_get_custom_fields
/**
* Tests profile_get_custom_fields function and checks it is consistent
* with profile_user_record.
*/
public function test_get_custom_fields()
{
global $DB, $CFG;
require_once $CFG->dirroot . '/user/profile/lib.php';
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();
// Add a custom field of textarea type.
$id1 = $DB->insert_record('user_info_field', array('shortname' => 'frogdesc', 'name' => 'Description of frog', 'categoryid' => 1, 'datatype' => 'textarea'));
// Check the field is returned.
$result = profile_get_custom_fields();
$this->assertArrayHasKey($id1, $result);
$this->assertEquals('frogdesc', $result[$id1]->shortname);
// Textarea types are not included in user data though, so if we
// use the 'only in user data' parameter, there is still nothing.
$this->assertArrayNotHasKey($id1, profile_get_custom_fields(true));
// Check that profile_user_record returns same (no) fields.
$this->assertObjectNotHasAttribute('frogdesc', profile_user_record($user->id));
// Check that profile_user_record returns all the fields when requested.
$this->assertObjectHasAttribute('frogdesc', profile_user_record($user->id, false));
// Add another custom field, this time of normal text type.
$id2 = $DB->insert_record('user_info_field', array('shortname' => 'frogname', 'name' => 'Name of frog', 'categoryid' => 1, 'datatype' => 'text'));
// Check both are returned using normal option.
$result = profile_get_custom_fields();
$this->assertArrayHasKey($id2, $result);
$this->assertEquals('frogname', $result[$id2]->shortname);
// And check that only the one is returned the other way.
$this->assertArrayHasKey($id2, profile_get_custom_fields(true));
// Check profile_user_record returns same field.
$this->assertObjectHasAttribute('frogname', profile_user_record($user->id));
// Check that profile_user_record returns all the fields when requested.
$this->assertObjectHasAttribute('frogname', profile_user_record($user->id, false));
}
示例2: find_user_level
public function find_user_level($user)
{
if (empty($user)) {
return null;
}
$user_custom_fields = profile_user_record($user->id);
if (empty($user_custom_fields->Position)) {
$position = 'None Set';
} else {
$position = $user_custom_fields->Position;
}
$level_one = array('production associate', 'officer', 'assistants', 'inventory clerk');
$level_two = array('cell leader', 'associates', 'coordinator', 'service rep', 'sales rep', 'technician', 'executive assistant', 'estimator');
$level_three = array('team lead', 'supervisor', 'assistant manager');
$level_four = array('manager');
if (in_array($position, $level_one)) {
return 1;
} elseif (in_array($position, $level_two)) {
return 2;
} elseif (in_array($position, $level_three)) {
return 3;
} elseif (in_array($position, $level_four)) {
return 4;
} else {
return null;
}
}
示例3: get_user_custom_values
public function get_user_custom_values($user)
{
$userinfo = profile_user_record($user->id);
$values = array();
foreach ($this->customfields as $field) {
$fieldname = $field;
if (isset($userinfo->{$fieldname})) {
$values[$field] = $userinfo->{$fieldname};
} else {
$values[$field] = '';
}
}
return $values;
}
示例4: profile_load_custom_fields
/**
* Load custom profile fields into user object
*
* Please note originally in 1.9 we were using the custom field names directly,
* but it was causing unexpected collisions when adding new fields to user table,
* so instead we now use 'profile_' prefix.
*
* @param stdClass $user user object
*/
function profile_load_custom_fields($user)
{
$user->profile = (array) profile_user_record($user->id);
}
示例5: get_complete_user_data
/**
* Get a complete user record, which includes all the info
* in the user record
* Intended for setting as $USER session variable
*
* @uses $CFG
* @uses SITEID
* @param string $field The user field to be checked for a given value.
* @param string $value The value to match for $field.
* @return user A {@link $USER} object.
*/
function get_complete_user_data($field, $value, $mnethostid = null)
{
global $CFG;
if (!$field || !$value) {
return false;
}
/// Build the WHERE clause for an SQL query
$constraints = $field . ' = \'' . $value . '\' AND deleted <> \'1\'';
// If we are loading user data based on anything other than id,
// we must also restrict our search based on mnet host.
if ($field != 'id') {
if (empty($mnethostid)) {
// if empty, we restrict to local users
$mnethostid = $CFG->mnet_localhost_id;
}
}
if (!empty($mnethostid)) {
$mnethostid = (int) $mnethostid;
$constraints .= ' AND mnethostid = ' . $mnethostid;
}
/// Get all the basic user data
if (!($user = get_record_select('user', $constraints))) {
return false;
}
/// Get various settings and preferences
if ($displays = get_records('course_display', 'userid', $user->id)) {
foreach ($displays as $display) {
$user->display[$display->course] = $display->display;
}
}
$user->preference = get_user_preferences(null, null, $user->id);
$user->lastcourseaccess = array();
// during last session
$user->currentcourseaccess = array();
// during current session
if ($lastaccesses = get_records('user_lastaccess', 'userid', $user->id)) {
foreach ($lastaccesses as $lastaccess) {
$user->lastcourseaccess[$lastaccess->courseid] = $lastaccess->timeaccess;
}
}
$sql = "SELECT g.id, g.courseid\n FROM {$CFG->prefix}groups g, {$CFG->prefix}groups_members gm\n WHERE gm.groupid=g.id AND gm.userid={$user->id}";
// this is a special hack to speedup calendar display
$user->groupmember = array();
if ($groups = get_records_sql($sql)) {
foreach ($groups as $group) {
if (!array_key_exists($group->courseid, $user->groupmember)) {
$user->groupmember[$group->courseid] = array();
}
$user->groupmember[$group->courseid][$group->id] = $group->id;
}
}
/// Add the custom profile fields to the user record
include_once $CFG->dirroot . '/user/profile/lib.php';
$customfields = (array) profile_user_record($user->id);
foreach ($customfields as $cname => $cvalue) {
if (!isset($user->{$cname})) {
// Don't overwrite any standard fields
$user->{$cname} = $cvalue;
}
}
/// Rewrite some variables if necessary
if (!empty($user->description)) {
$user->description = true;
// No need to cart all of it around
}
if ($user->username == 'guest') {
$user->lang = $CFG->lang;
// Guest language always same as site
$user->firstname = get_string('guestuser');
// Name always in current language
$user->lastname = ' ';
}
if (isset($_SERVER['REMOTE_ADDR'])) {
$user->sesskey = random_string(10);
$user->sessionIP = md5(getremoteaddr());
// Store the current IP in the session
}
return $user;
}
示例6: get_users
//.........这里部分代码省略.........
}
foreach ($params['criteria'] as $criteriaindex => $criteria) {
// Check that the criteria has never been used.
if (array_key_exists($criteria['key'], $usedkeys)) {
throw new moodle_exception('keyalreadyset', '', '', null, 'The key ' . $criteria['key'] . ' can only be sent once');
} else {
$usedkeys[$criteria['key']] = true;
}
$invalidcriteria = false;
// Clean the parameters.
$paramtype = PARAM_RAW;
switch ($criteria['key']) {
case 'id':
$paramtype = PARAM_INT;
break;
case 'idnumber':
$paramtype = PARAM_RAW;
break;
case 'username':
$paramtype = PARAM_RAW;
break;
case 'email':
// We use PARAM_RAW to allow searches with %.
$paramtype = PARAM_RAW;
break;
case 'auth':
$paramtype = PARAM_AUTH;
break;
case 'lastname':
case 'firstname':
$paramtype = PARAM_TEXT;
break;
default:
if (substr($criteria['key'], 0, 14) == 'profile_field_' && in_array(substr($criteria['key'], 14, strlen($criteria['key'])), $customprofilefields)) {
$paramtype = PARAM_TEXT;
} else {
// Send back a warning that this search key is not supported in this version.
// This warning will make the function extandable without breaking clients.
$warnings[] = array('item' => $criteria['key'], 'warningcode' => 'invalidfieldparameter', 'message' => 'The search key \'' . $criteria['key'] . '\' is not supported, look at the web service documentation');
// Do not add this invalid criteria to the created SQL request.
$invalidcriteria = true;
unset($params['criteria'][$criteriaindex]);
}
break;
}
if (!$invalidcriteria) {
$cleanedvalue = clean_param($criteria['value'], $paramtype);
$sqlwhere .= ' AND ';
// Create the SQL.
switch ($criteria['key']) {
case 'id':
case 'idnumber':
case 'auth':
$sqlwhere .= '{user}.' . $criteria['key'] . ' = :' . $criteria['key'];
$sqlparams[$criteria['key']] = $cleanedvalue;
break;
case 'username':
case 'email':
case 'lastname':
case 'firstname':
$sqlwhere .= $DB->sql_like('{user}.' . $criteria['key'], ':' . $criteria['key'], false);
$sqlparams[$criteria['key']] = $cleanedvalue;
break;
default:
if (substr($criteria['key'], 0, 14) == 'profile_field_' && in_array(substr($criteria['key'], 14, strlen($criteria['key'])), $customprofilefields)) {
$c++;
$sqltables .= " LEFT JOIN {user_info_data} AS cfdata" . $c . " ON {user}.id = cfdata" . $c . ".userid LEFT JOIN {user_info_field} AS cfield" . $c . " ON cfdata" . $c . ".fieldid = cfield" . $c . ".id";
$sqlwhere .= 'cfield' . $c . '.shortname = :cfield' . $c . ' AND cfdata' . $c . '.data = :cfdata' . $c;
$sqlparams['cfield' . $c] = substr($criteria['key'], 14, strlen($criteria['key']));
$sqlparams['cfdata' . $c] = $cleanedvalue;
$warnings[] = array('warningcode' => 'customfieldname', 'message' => 'cfield' . $c . " = " . substr($criteria['key'], 14, strlen($criteria['key'])));
$warnings[] = array('warningcode' => 'customfielddata', 'message' => 'cfdata' . $c . " = " . $cleanedvalue);
}
break;
}
}
}
$sql = 'SELECT {user}.* FROM ' . $sqltables . ' WHERE ' . $sqlwhere . ' ORDER BY id ASC';
$users = $DB->get_records_sql($sql, $sqlparams);
// Finally retrieve each users information.
$returnedusers = array();
foreach ($users as $user) {
$userdetails = user_get_user_details_courses($user);
$customfields = profile_user_record($user->id);
// Return the user only if all the searched fields are returned.
// Otherwise it means that the $USER was not allowed to search the returned user.
if (!empty($userdetails)) {
$validuser = true;
foreach ($params['criteria'] as $criteria) {
if (substr($criteria['key'], 0, 14) != 'profile_field_' && empty($userdetails[$criteria['key']])) {
$validuser = false;
}
}
if ($validuser) {
$returnedusers[] = $userdetails;
}
}
}
return array('users' => $returnedusers, 'warnings' => $warnings);
}
示例7: get_users_by_id
/**
* Get user information
*
* @param array $userids array of user ids
* @return array An array of arrays describing users
*/
public static function get_users_by_id($userids)
{
global $CFG;
require_once $CFG->dirroot . "/user/lib.php";
//required for customfields related function
//TODO: move the functions somewhere else as
//they are "user" related
require_once $CFG->dirroot . "/user/profile/lib.php";
$params = self::validate_parameters(self::get_users_by_id_parameters(), array('userids' => $userids));
//TODO: check if there is any performance issue: we do one DB request to retrieve
// all user, then for each user the profile_load_data does at least two DB requests
$users = user_get_users_by_id($params['userids']);
$result = array();
foreach ($users as $user) {
$context = get_context_instance(CONTEXT_USER, $user->id);
require_capability('moodle/user:viewalldetails', $context);
self::validate_context($context);
if (empty($user->deleted)) {
$userarray = array();
//we want to return an array not an object
/// now we transfert all profile_field_xxx into the customfields
// external_multiple_structure required by description
$userarray['id'] = $user->id;
$userarray['username'] = $user->username;
$userarray['firstname'] = $user->firstname;
$userarray['lastname'] = $user->lastname;
$userarray['email'] = $user->email;
$userarray['auth'] = $user->auth;
$userarray['confirmed'] = $user->confirmed;
$userarray['idnumber'] = $user->idnumber;
$userarray['lang'] = $user->lang;
$userarray['theme'] = $user->theme;
$userarray['timezone'] = $user->timezone;
$userarray['mailformat'] = $user->mailformat;
$userarray['description'] = $user->description;
$userarray['descriptionformat'] = $user->descriptionformat;
$userarray['city'] = $user->city;
$userarray['country'] = $user->country;
$userarray['customfields'] = array();
$customfields = profile_user_record($user->id);
$customfields = (array) $customfields;
foreach ($customfields as $key => $value) {
$userarray['customfields'][] = array('type' => $key, 'value' => $value);
}
$result[] = $userarray;
}
}
return $result;
}
示例8: editUserProfile
function editUserProfile($requestingUser, $userold)
{
$wsdl = "http://ita-provisioner.cis.fiu.edu:8080/axis2/services/VirtualLabs?wsdl";
$location = "http://ita-provisioner.cis.fiu.edu:8080/axis2/services/VirtualLabs";
// Get the user timezone information
$user = profile_user_record($userold->id);
//$zone = getUserTimeZone($userold->id);
$zone = get_record('user_info_data', 'userid', $userold->id, 'fieldid', 4);
if (!empty($zone->data)) {
$timezone = $zone->data;
} else {
//$timezone = "GMT-05:00 America/New_York";
$timezone = "";
}
//Hash the password before saving
//$usernew->password = hash_internal_user_password($userold->newpassword);
//Get the user role
$userRole = get_record('role_assignments', 'userid', $userold->id, 'contextid', 1);
$role = get_record('role', 'id', $userRole->roleid);
if (!empty($role->name)) {
$newrole = $role->name;
} else {
$newrole = "Student";
}
try {
$params = array('requestingUser' => $requestingUser, 'userName' => $userold->username, 'password' => $userold->newpassword, 'firstName' => $userold->firstname, 'lastName' => $userold->lastname, 'emailAddress' => $userold->email, 'userRole' => $newrole, 'timeZone' => $timezone, 'contactInfo' => $userold->phone1);
$client = new SoapClient($wsdl, array('location' => $location));
$result = $client->editUserProfile($params);
$success = $result->success;
} catch (Exception $e) {
echo $e->getMessage();
$success = false;
} catch (SoapFault $soapfault) {
echo $soapfault->getMessage();
$success = false;
}
return $success;
}
示例9: moodle_user_update_users
//.........这里部分代码省略.........
$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';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1_updated'),
array('type' => $preferencename2, 'value' => 'preferencevalue2_updated'));
$customfieldname1 = 'testdatacustom1';
$customfieldname2 = 'testdatacustom2';
$user1->customfields = array(
array('type' => $customfieldname1, 'value' => 'customvalue_updated'),
array('type' => $customfieldname2, 'value' => 'customvalue2_updated'));
$user2->username = 'veryimprobabletestusername2_updated';
$user2->password = 'testpassword2_updated';
$user2->firstname = 'testfirstname2_updated';
$user2->lastname = 'testlastname2_updated';
$user2->email = 'testemail1_updated@moodle.com';
$users = array($user1, $user2);
//update the users by web service
$function = 'moodle_user_update_users';
$params = array('users' => $users);
$client->call($function, $params);
//compare DB user with the test data
$dbuser1 = $DB->get_record('user', array('username' => $user1->username));
$this->assertEqual($dbuser1->firstname, $user1->firstname);
$this->assertEqual($dbuser1->password,
hash_internal_user_password($user1->password));
$this->assertEqual($dbuser1->lastname, $user1->lastname);
$this->assertEqual($dbuser1->email, $user1->email);
$this->assertEqual($dbuser1->auth, $user1->auth);
$this->assertEqual($dbuser1->idnumber, $user1->idnumber);
$this->assertEqual($dbuser1->lang, $user1->lang);
$this->assertEqual($dbuser1->theme, $user1->theme);
$this->assertEqual($dbuser1->timezone, $user1->timezone);
$this->assertEqual($dbuser1->mailformat, $user1->mailformat);
$this->assertEqual($dbuser1->description, $user1->description);
$this->assertEqual($dbuser1->city, $user1->city);
$this->assertEqual($dbuser1->country, $user1->country);
$user1preference1 = get_user_preferences($user1->preferences[0]['type'],
null, $dbuser1->id);
$this->assertEqual($user1->preferences[0]['value'], $user1preference1);
$user1preference2 = get_user_preferences($user1->preferences[1]['type'],
null, $dbuser1->id);
$this->assertEqual($user1->preferences[1]['value'], $user1preference2);
require_once($CFG->dirroot . "/user/profile/lib.php");
$customfields = profile_user_record($dbuser1->id);
$customfields = (array) $customfields;
$customfieldname1 = $user1->customfields[0]['type'];
$customfieldname2 = $user1->customfields[1]['type'];
$this->assertEqual($customfields[$customfieldname1],
$user1->customfields[0]['value']);
$this->assertEqual($customfields[$customfieldname2],
$user1->customfields[1]['value']);
$dbuser2 = $DB->get_record('user', array('username' => $user2->username));
$this->assertEqual($dbuser2->firstname, $user2->firstname);
$this->assertEqual($dbuser2->password,
hash_internal_user_password($user2->password));
$this->assertEqual($dbuser2->lastname, $user2->lastname);
$this->assertEqual($dbuser2->email, $user2->email);
//unset preferences
$DB->delete_records('user_preferences', array('userid' => $dbuser1->id));
//clear custom fields data
$DB->delete_records('user_info_data', array('userid' => $dbuser1->id));
//delete custom fields
$DB->delete_records_list('user_info_field', 'shortname',
array($customfieldname1, $customfieldname2));
//delete users from DB
$DB->delete_records_list('user', 'id',
array($dbuser1->id, $dbuser2->id));
}
}
示例10: getItemByName
$output[] = '<td>' . $item->quantity . '</td>';
$output[] = '</tr>';
//Get item from store inventory ans save it in order summary
$dbitem = getItemByName($item->name);
$success = db_addOrderItem($dborder->id, $dbitem->id, $item->quantity, $item->price);
//Insert order summary for this item
if (!$success) {
array_push($purchaseFailed, $dbitem);
}
}
$output[] = '</tbody>';
$output[] = '</table>';
//Send Email to customer
$buyer = db_getUserById($dborder->userid);
// Buyer Information: added by JAM - 06/18/2012
$profile_fields = profile_user_record($dborder->userid);
$data = new object();
$data->userfullname = fullname($buyer);
$data->firstname = $buyer->firstname;
$data->lastname = $buyer->lastname;
$data->email = $buyer->email;
$data->username = $buyer->username;
$data->password = '';
//$buyer->password;
$data->gender = $profile_fields->gender;
$data->skypeid = $profile_fields->skypeid;
$data->kaseyasalesrep = $profile_fields->kaseyasalesrep;
$data->maintopic = $profile_fields->maintopic;
$data->typebundle = $profile_fields->typebundle;
$data->kaseyacustomerid = $profile_fields->kaseyacustomerid;
$data->zone = $profile_fields->zone;
示例11: get_complete_user_data
/**
* Get a complete user record, which includes all the info
* in the user record.
*
* Intended for setting as $USER session variable
*
* @global object
* @global object
* @uses SITEID
* @param string $field The user field to be checked for a given value.
* @param string $value The value to match for $field.
* @param int $mnethostid
* @return mixed False, or A {@link $USER} object.
*/
function get_complete_user_data($field, $value, $mnethostid = null)
{
global $CFG, $DB;
if (!$field || !$value) {
return false;
}
/// Build the WHERE clause for an SQL query
$params = array('fieldval' => $value);
$constraints = "{$field} = :fieldval AND deleted <> 1";
// If we are loading user data based on anything other than id,
// we must also restrict our search based on mnet host.
if ($field != 'id') {
if (empty($mnethostid)) {
// if empty, we restrict to local users
$mnethostid = $CFG->mnet_localhost_id;
}
}
if (!empty($mnethostid)) {
$params['mnethostid'] = $mnethostid;
$constraints .= " AND mnethostid = :mnethostid";
}
/// Get all the basic user data
if (!($user = $DB->get_record_select('user', $constraints, $params))) {
return false;
}
/// Get various settings and preferences
if ($displays = $DB->get_records('course_display', array('userid' => $user->id))) {
foreach ($displays as $display) {
$user->display[$display->course] = $display->display;
}
}
$user->preference = get_user_preferences(null, null, $user->id);
$user->preference['_lastloaded'] = time();
$user->lastcourseaccess = array();
// during last session
$user->currentcourseaccess = array();
// during current session
if ($lastaccesses = $DB->get_records('user_lastaccess', array('userid' => $user->id))) {
foreach ($lastaccesses as $lastaccess) {
$user->lastcourseaccess[$lastaccess->courseid] = $lastaccess->timeaccess;
}
}
$sql = "SELECT g.id, g.courseid\n FROM {groups} g, {groups_members} gm\n WHERE gm.groupid=g.id AND gm.userid=?";
// this is a special hack to speedup calendar display
$user->groupmember = array();
if ($groups = $DB->get_records_sql($sql, array($user->id))) {
foreach ($groups as $group) {
if (!array_key_exists($group->courseid, $user->groupmember)) {
$user->groupmember[$group->courseid] = array();
}
$user->groupmember[$group->courseid][$group->id] = $group->id;
}
}
/// Add the custom profile fields to the user record
require_once $CFG->dirroot . '/user/profile/lib.php';
$customfields = (array) profile_user_record($user->id);
foreach ($customfields as $cname => $cvalue) {
if (!isset($user->{$cname})) {
// Don't overwrite any standard fields
$user->{$cname} = $cvalue;
}
}
/// Rewrite some variables if necessary
if (!empty($user->description)) {
$user->description = true;
// No need to cart all of it around
}
if ($user->username == 'guest') {
$user->lang = $CFG->lang;
// Guest language always same as site
$user->firstname = get_string('guestuser');
// Name always in current language
$user->lastname = ' ';
}
return $user;
}
示例12: definition_after_data
/**
* Extend the form definition after the data has been parsed.
*/
public function definition_after_data()
{
global $CFG, $DB, $OUTPUT;
$mform = $this->_form;
$userid = $mform->getElementValue('id');
// Trim required name fields.
foreach (useredit_get_required_name_fields() as $field) {
$mform->applyFilter($field, 'trim');
}
if ($user = $DB->get_record('user', array('id' => $userid))) {
// Remove description.
if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
$mform->removeElement('description_editor');
}
// Print picture.
$context = context_user::instance($user->id, MUST_EXIST);
$fs = get_file_storage();
$hasuploadedpicture = $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg');
if (!empty($user->picture) && $hasuploadedpicture) {
$imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64));
} else {
$imagevalue = get_string('none');
}
$imageelement = $mform->getElement('currentpicture');
$imageelement->setValue($imagevalue);
if ($mform->elementExists('deletepicture') && !$hasuploadedpicture) {
$mform->removeElement('deletepicture');
}
// Disable fields that are locked by auth plugins.
$fields = get_user_fieldnames();
$authplugin = get_auth_plugin($user->auth);
$customfields = $authplugin->get_custom_user_profile_fields();
$customfieldsdata = profile_user_record($userid, false);
$fields = array_merge($fields, $customfields);
foreach ($fields as $field) {
if ($field === 'description') {
// Hard coded hack for description field. See MDL-37704 for details.
$formfield = 'description_editor';
} else {
$formfield = $field;
}
if (!$mform->elementExists($formfield)) {
continue;
}
// Get the original value for the field.
if (in_array($field, $customfields)) {
$key = str_replace('profile_field_', '', $field);
$value = isset($customfieldsdata->{$key}) ? $customfieldsdata->{$key} : '';
} else {
$value = $user->{$field};
}
$configvariable = 'field_lock_' . $field;
if (isset($authplugin->config->{$configvariable})) {
if ($authplugin->config->{$configvariable} === 'locked') {
$mform->hardFreeze($formfield);
$mform->setConstant($formfield, $value);
} else {
if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $value != '') {
$mform->hardFreeze($formfield);
$mform->setConstant($formfield, $value);
}
}
}
}
// Next the customisable profile fields.
profile_definition_after_data($mform, $user->id);
} else {
profile_definition_after_data($mform, 0);
}
}
示例13: moodle_user_create_users
function moodle_user_create_users($client)
{
global $DB, $CFG;
//Test data
//a full user: user1
$user1 = new stdClass();
$user1->username = 'testusername1';
$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 = 'testusername2';
$user2->password = 'testpassword2';
$user2->firstname = 'testfirstname2';
$user2->lastname = 'testlastname2';
$user2->email = 'testemail1@moodle.com';
$users = array($user1, $user2);
//do not run the test if user1 or user2 already exists
$existingusers = $DB->get_records_list('user', 'username', array($user1->username, $user2->username));
if (!empty($existingusers)) {
throw new moodle_exception('testdatausersalreadyexist');
}
//do not run the test if data test custom fields already exists
$existingcustomfields = $DB->get_records_list('user_info_field', 'shortname', array($customfieldname1, $customfieldname2));
if (!empty($existingcustomfields)) {
throw new moodle_exception('testdatacustomfieldsalreadyexist');
}
//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);
$function = 'moodle_user_create_users';
$params = array('users' => $users);
$resultusers = $client->call($function, $params);
$this->assertEqual(count($users), count($resultusers));
//retrieve user1 from the DB and check values
$dbuser1 = $DB->get_record('user', array('username' => $user1->username));
$this->assertEqual($dbuser1->firstname, $user1->firstname);
$this->assertEqual($dbuser1->password, hash_internal_user_password($user1->password));
$this->assertEqual($dbuser1->lastname, $user1->lastname);
$this->assertEqual($dbuser1->email, $user1->email);
$this->assertEqual($dbuser1->auth, $user1->auth);
$this->assertEqual($dbuser1->idnumber, $user1->idnumber);
$this->assertEqual($dbuser1->lang, $user1->lang);
$this->assertEqual($dbuser1->theme, $user1->theme);
$this->assertEqual($dbuser1->timezone, $user1->timezone);
$this->assertEqual($dbuser1->mailformat, $user1->mailformat);
$this->assertEqual($dbuser1->description, $user1->description);
$this->assertEqual($dbuser1->city, $user1->city);
$this->assertEqual($dbuser1->country, $user1->country);
$user1preference1 = get_user_preferences($user1->preferences[0]['type'], null, $dbuser1->id);
$this->assertEqual($user1->preferences[0]['value'], $user1preference1);
$user1preference2 = get_user_preferences($user1->preferences[1]['type'], null, $dbuser1->id);
$this->assertEqual($user1->preferences[1]['value'], $user1preference2);
require_once $CFG->dirroot . "/user/profile/lib.php";
$customfields = profile_user_record($dbuser1->id);
$customfields = (array) $customfields;
$customfieldname1 = $user1->customfields[0]['type'];
$customfieldname2 = $user1->customfields[1]['type'];
$this->assertEqual($customfields[$customfieldname1], $user1->customfields[0]['value']);
$this->assertEqual($customfields[$customfieldname2], $user1->customfields[1]['value']);
//retrieve user2 from the DB and check values
$dbuser2 = $DB->get_record('user', array('username' => $user2->username));
$this->assertEqual($dbuser2->firstname, $user2->firstname);
$this->assertEqual($dbuser2->password, hash_internal_user_password($user2->password));
$this->assertEqual($dbuser2->lastname, $user2->lastname);
$this->assertEqual($dbuser2->email, $user2->email);
//unset preferences
$DB->delete_records('user_preferences', array('userid' => $dbuser1->id));
//clear custom fields data
$DB->delete_records('user_info_data', array('userid' => $dbuser1->id));
//delete custom fields
$DB->delete_records_list('user_info_field', 'shortname', array($customfieldname1, $customfieldname2));
//delete users from DB
$DB->delete_records_list('user', 'id', array($dbuser1->id, $dbuser2->id));
}
示例14: enrolment_request_email
function enrolment_request_email($user, $course)
{
// Sent to the Admin
global $CFG;
$site = get_site();
$supportuser = generate_email_supportuser();
$profile_fields = profile_user_record($user->id);
$data = new object();
$data->userfullname = fullname($user);
$data->firstname = $user->firstname;
$data->lastname = $user->lastname;
$data->email = $user->email;
$data->username = $user->username;
$data->password = '';
//$user->password;
$data->gender = $profile_fields->gender;
$data->skypeid = $profile_fields->skypeid;
$data->kaseyasalesrep = $profile_fields->kaseyasalesrep;
$data->maintopic = $profile_fields->maintopic;
$data->typebundle = $profile_fields->typebundle;
$data->kaseyacustomerid = $profile_fields->kaseyacustomerid;
$data->zone = $profile_fields->zone;
$data->country = $user->country;
$data->companyname = $profile_fields->companyname;
$data->state = $profile_fields->state;
//$data->firstaccess = $user->firstaccess;
//$data->lastaccess = $user->lastaccess;
$data->firstaccess = date("D M j G:i:s T Y", $user->firstaccess);
$data->lastaccess = date("D M j G:i:s T Y", $user->lastaccess);
$data->course = format_string($course->fullname);
$data->sitename = format_string($site->fullname);
$data->admin = generate_email_signoff($user);
$coursedata = new object();
$coursedata->userfullname = fullname($user);
$coursedata->shortname = $course->shortname;
$coursedata->fullname = $course->fullname;
$subject = get_string('enrolmentrequestadminemailsubject', '', $coursedata);
//$data->link = $CFG->wwwroot .'/login/';
$message = get_string('enrolmentrequestadminemail', '', $data);
$messagehtml = text_to_html(get_string('enrolmentrequestadminemail', '', $data), false, false, true);
$user->mailformat = 1;
// Always send HTML version as well
/* for testing */
$otheruser = new object();
$otheruser->firstname = 'Admin';
$otheruser->lastname = 'Admin';
$otheruser->email = 'test@email.com';
//*/
return email_to_user($supportuser, $supportuser, $subject, $message, $messagehtml);
}
示例15: send_textmessages
function send_textmessages()
{
if (get_config('cancelcourse', 'providername') && get_config('cancelcourse', 'sendtext')) {
global $COURSE, $CFG;
//load the global parameters
$context = context_course::instance($COURSE->id);
//gets the user ID
$userids = get_enrolled_users($context, $withcapability = '', $groupid = 0, $userfields = 'u.*');
$addresses = array();
foreach ($userids as $userid) {
//Check each enrolled user for a phone number, and sends the text message to these users.
//var_dump(profile_user_record($userid));
if ($userid->phone2) {
//only procede if the user has filled in the cell phone number field in their profile.
$providerSN = get_config('cancelcourse', 'providername');
//get the custom user field shortname
$user_prov = profile_user_record($userid->id)->{$providerSN};
//get the user's cell provider from their profile, if they specified one.
//var_dump($userid->email); //for development only
$prov_email = get_config('cancelcourse', preg_replace('/\\s+/', '', $user_prov));
//figure out the provider's email suffix.
if ($prov_email) {
//a cell provider was given.
$usersPhone = preg_replace('~.*(\\d{3})[^\\d]*(\\d{3})[^\\d]*(\\d{4}).*~', '$1$2$3', $userid->phone2);
//clean up the phone number
$addresses[] = $usersPhone . '@' . $prov_email;
} else {
//no cell provider was given. We're going to have to try them all.
$providers = get_providers();
//get the array of providers
//$prov_emails = array();
$usersPhone = preg_replace('~.*(\\d{3})[^\\d]*(\\d{3})[^\\d]*(\\d{4}).*~', '$1$2$3', $userid->phone2);
//get the user's phone number
foreach ($providers as $provider) {
$prov_value = get_config('cancelcourse', preg_replace('/\\s+/', '', $provider));
//figure out the provider's email suffix.
if ($prov_value) {
//if there's a suffix (prevents attempting to send to unconfigured providers)
$addresses[] = $usersPhone . '@' . $prov_value;
}
}
}
}
}
return $addresses;
}
}