本文整理汇总了PHP中profile_load_data函数的典型用法代码示例。如果您正苦于以下问题:PHP profile_load_data函数的具体用法?PHP profile_load_data怎么用?PHP profile_load_data使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了profile_load_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ent_installer_route_teacher_category
/**
* Route teachers to their category if none is specified
* Files fixed :
* course/index.php
*
* @return bool Request has been marked for rerouting
*/
function ent_installer_route_teacher_category()
{
global $CFG, $DB, $USER;
// Exit if a category is already requested
$categoryid = optional_param('categoryid', 0, PARAM_INT);
if ($categoryid) {
return false;
}
require_once $CFG->dirroot . '/user/profile/lib.php';
$myuser = $DB->get_record('user', array('id' => $USER->id));
profile_load_data($myuser);
// Exit if current user is not a teacher
if (!isset($myuser->profile_field_enseignant) || !$myuser->profile_field_enseignant) {
return false;
}
$institutionid = get_config('local_ent_installer', 'institution_id');
$teachercatidnum = $institutionid . '$' . $myuser->idnumber . '$CAT';
$existingcategory = $DB->get_record('course_categories', array('idnumber' => $teachercatidnum));
// Exit if category cannot be found
if (!$existingcategory) {
return false;
}
//Let Moodle core course index trust that this category is requested
$_GET['categoryid'] = $existingcategory->id;
return true;
}
示例2: execute
public function execute()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->libdir . '/csvlib.class.php';
$username = $this->arguments[0];
$filename = $this->expandedOptions['name'];
$user = get_user_by_name($username);
if (!$user) {
cli_error("User not found.");
} else {
$userid = $user->id;
}
$fields = array('id' => 'id', 'username' => 'username', 'email' => 'email', 'firstname' => 'firstname', 'lastname' => 'lastname', 'idnumber' => 'idnumber', 'institution' => 'institution', 'department' => 'department', 'phone1' => 'phone1', 'phone2' => 'phone2', 'city' => 'city', 'url' => 'url', 'icq' => 'icq', 'skype' => 'skype', 'aim' => 'aim', 'yahoo' => 'yahoo', 'msn' => 'msn', 'country' => 'country');
if ($extrafields = $DB->get_records('user_info_field')) {
foreach ($extrafields as $n => $v) {
$fields['profile_field_' . $v->shortname] = 'profile_field_' . $v->shortname;
}
}
$csvexport = new \csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
$row = array();
profile_load_data($user);
$userprofiledata = array();
foreach ($fields as $field => $unused) {
if (is_array($user->{$field})) {
$userprofiledata[] = reset($user->{$field});
} else {
$userprofiledata[] = $user->{$field};
}
}
$csvexport->add_data($userprofiledata);
file_put_contents($filename, $csvexport->print_csv_data(true));
echo "User " . $user->username . " successfully downloaded\n";
}
示例3: 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);
}
示例4: user_download_csv
function user_download_csv($userids, $fields, $includecompanyfield)
{
global $CFG, $SESSION, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
$filename = clean_filename(get_string('users') . '.csv');
header("Content-Type: application/download\n");
header("Content-Disposition: attachment; filename={$filename}");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
$delimiter = get_string('listsep', 'langconfig');
$encdelim = '&#' . ord($delimiter);
$row = array();
foreach ($fields as $fieldname) {
if ($includecompanyfield || $fieldname != "profile_field_company") {
$row[] = str_replace($delimiter, $encdelim, $fieldname);
}
}
$row[] = "temppassword";
echo implode($delimiter, $row) . "\n";
foreach ($userids as $userid) {
// Stop the script from timing out on large numbers of users.
set_time_limit(30);
$row = array();
if (!($user = $DB->get_record('user', array('id' => $userid)))) {
continue;
}
profile_load_data($user);
foreach ($fields as $field => $unused) {
// Stop the script from timing out on large numbers of users.
set_time_limit(30);
if ($includecompanyfield || $field != "profile_field_company") {
$row[] = str_replace($delimiter, $encdelim, $user->{$field});
}
}
$row[] = str_replace($delimiter, $encdelim, company_user::get_temporary_password($user));
echo implode($delimiter, $row) . "\n";
}
die;
}
示例5: definition
//.........这里部分代码省略.........
foreach ($themeobjects as $key => $theme) {
if (empty($theme->hidefromselector)) {
$themes[$key] = get_string('pluginname', 'theme_' . $theme->name);
}
}
$mform->addElement('select', 'theme', get_string('forcetheme'), $themes);
}
//--------------------------------------------------------------------------------
enrol_course_edit_form($mform, $course, $context);
//--------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('groups', 'group'));
$choices = array();
$choices[NOGROUPS] = get_string('groupsnone', 'group');
$choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group');
$choices[VISIBLEGROUPS] = get_string('groupsvisible', 'group');
$mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $choices);
$mform->addHelpButton('groupmode', 'groupmode', 'group');
$mform->setDefault('groupmode', $courseconfig->groupmode);
$choices = array();
$choices['0'] = get_string('no');
$choices['1'] = get_string('yes');
$mform->addElement('select', 'groupmodeforce', get_string('groupmodeforce', 'group'), $choices);
$mform->addHelpButton('groupmodeforce', 'groupmodeforce', 'group');
$mform->setDefault('groupmodeforce', $courseconfig->groupmodeforce);
//default groupings selector
$options = array();
$options[0] = get_string('none');
$mform->addElement('select', 'defaultgroupingid', get_string('defaultgrouping', 'group'), $options);
//--------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('availability'));
$choices = array();
$choices['0'] = get_string('courseavailablenot');
$choices['1'] = get_string('courseavailable');
$mform->addElement('select', 'visible', get_string('availability'), $choices);
$mform->addHelpButton('visible', 'availability');
$mform->setDefault('visible', $courseconfig->visible);
if (!has_capability('moodle/course:visibility', $context)) {
$mform->hardFreeze('visible');
if (!empty($course->id)) {
$mform->setConstant('visible', $course->visible);
} else {
$mform->setConstant('visible', $category->visible);
}
}
//--------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('language'));
$languages = array();
$languages[''] = get_string('forceno');
$languages += get_string_manager()->get_list_of_translations();
$mform->addElement('select', 'lang', get_string('forcelanguage'), $languages);
$mform->setDefault('lang', $courseconfig->lang);
//--------------------------------------------------------------------------------
if (completion_info::is_enabled_for_site()) {
$mform->addElement('header', '', get_string('progress', 'completion'));
$mform->addElement('select', 'enablecompletion', get_string('completion', 'completion'), array(0 => get_string('completiondisabled', 'completion'), 1 => get_string('completionenabled', 'completion')));
$mform->setDefault('enablecompletion', $courseconfig->enablecompletion);
$mform->addElement('checkbox', 'completionstartonenrol', get_string('completionstartonenrol', 'completion'));
$mform->setDefault('completionstartonenrol', $courseconfig->completionstartonenrol);
$mform->disabledIf('completionstartonenrol', 'enablecompletion', 'eq', 0);
} else {
$mform->addElement('hidden', 'enablecompletion');
$mform->setType('enablecompletion', PARAM_INT);
$mform->setDefault('enablecompletion', 0);
$mform->addElement('hidden', 'completionstartonenrol');
$mform->setType('completionstartonenrol', PARAM_INT);
$mform->setDefault('completionstartonenrol', 0);
}
/// customizable role names in this course
//--------------------------------------------------------------------------------
$mform->addElement('header', 'rolerenaming', get_string('rolerenaming'));
$mform->addHelpButton('rolerenaming', 'rolerenaming');
if ($roles = get_all_roles()) {
if ($coursecontext) {
$roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS_RAW);
}
$assignableroles = get_roles_for_contextlevels(CONTEXT_COURSE);
foreach ($roles as $role) {
$mform->addElement('text', 'role_' . $role->id, get_string('yourwordforx', '', $role->name));
if (isset($role->localname)) {
$mform->setDefault('role_' . $role->id, $role->localname);
}
$mform->setType('role_' . $role->id, PARAM_TEXT);
if (!in_array($role->id, $assignableroles)) {
$mform->setAdvanced('role_' . $role->id);
}
}
}
// customisable profile fields
//--------------------------------------------------------------------------------
profile_definition($mform);
//--------------------------------------------------------------------------------
$this->add_action_buttons();
//--------------------------------------------------------------------------------
$mform->addElement('hidden', 'id', null);
$mform->setType('id', PARAM_INT);
/// finally set the current form data
//--------------------------------------------------------------------------------
profile_load_data($course);
$this->set_data($course);
}
示例6: get_final_update_data
/**
* Assemble the user data.
*
* This returns the final data to be passed to update_user().
*
* @param array $finaldata current data.
* @param bool $usedefaults are defaults allowed?
* @param array $existingdata existing category data.
* @param bool $missingonly ignore fields which are already set.
* @return array
*/
protected function get_final_update_data($data, $existingdata, $usedefaults = false, $missingonly = false)
{
global $DB, $UUC_STD_FIELDS, $UUC_PRF_FIELDS, $UUC_DEFAULTS;
$doupdate = false;
$existingdata->timemodified = time();
profile_load_data($existingdata);
// Changing auth information.
if (isset($existingdata->auth) && isset($data->auth)) {
$existingdata->auth = $data->auth;
if ($data->auth === 'nologin') {
$this->dologout = true;
}
}
$allfields = array_merge($UUC_STD_FIELDS, $UUC_PRF_FIELDS);
foreach ($allfields as $field) {
// These fields are being processed separatedly.
if ($field === 'password' || $field === 'auth' || $field === 'suspended' || $field === 'oldusername') {
continue;
}
// Field not present in the CSV file.
if (!isset($data->{$field}) && !isset($existingdata->{$field})) {
if ($this->updatemode === tool_uploadusercli_processor::UPDATE_ALL_WITH_DATA_OR_DEFAULTS && !empty($UUC_DEFAULTS[$field])) {
$data->{$field} = $UUC_DEFAULTS[$field];
} else {
continue;
}
}
if ($missingonly) {
if ($existingdata->{$field}) {
continue;
}
} else {
if ($this->updatemode === tool_uploadusercli_processor::UPDATE_ALL_WITH_DATA_OR_DEFAULTS) {
// Override everything.
} else {
if ($this->updatemode === tool_uploadusercli_processor::UPDATE_ALL_WITH_DATA_ONLY) {
if (!empty($UUC_DEFAULTS[$field])) {
// Do not override with form defaults.
continue;
}
}
}
}
if (!isset($data->{$field}) || $existingdata->{$field} !== $data->{$field}) {
if ($field === 'email') {
if ($DB->record_exists('user', array('email' => $data->email))) {
if ($this->importoptions['noemailduplicates']) {
$this->error('useremailduplicate', new lang_string('useremailduplicate', 'error'));
return false;
} else {
$this->set_status('useremailduplicate', new lang_string('useremailduplicate', 'error'));
}
}
if (!validate_email($data->email)) {
$this->set_status('invalidemail', new lang_string('invalidemail'));
}
} else {
if ($field === 'lang') {
if (empty($data->lang)) {
// Don't change language if not already set.
continue;
} else {
if (clean_param($data->lang, PARAM_LANG) === '') {
$this->set_status('cannotfindlang', new lang_string('cannotfindlang', 'error', $data->lang));
continue;
}
}
}
}
// A new field was added to data while processing it.
if (!empty($data->{$field}) && $data->{$field} !== '') {
$existingdata->{$field} = $data->{$field};
}
$doupdate = true;
}
}
try {
$auth = get_auth_plugin($existingdata->auth);
} catch (Exception $e) {
$this->error('userautherror', new lang_string('userautherror', 'error', s($existingdata->auth)));
return false;
}
$isinternalauth = $auth->is_internal();
if ($this->importoptions['allowsuspends'] && isset($data->suspended) && $data->suspended !== '') {
$data->suspended = $data->suspended ? 1 : 0;
if ($existingdata->suspended != $data->suspended) {
$existingdata->suspended = $data->suspended;
$doupdate = true;
if ($existingdata->suspended) {
//.........这里部分代码省略.........
示例7: get_users
/**
* Get all the users to be saved to file.
*
* @return stdClass[] The users.
*/
protected function get_users()
{
global $DB;
// Constructing the requested user fields.
$userfields = array();
$getprofilefields = false;
foreach ($this->fields as $field) {
if (preg_match('/^profile_field_/', $field)) {
$getprofilefields = true;
} else {
$userfields[] = 'u.' . $field;
}
}
$userfields[] = 'u.id';
$userfields = implode(',', $userfields);
$courses = $this->get_courses();
$users = array();
// Finding the users assigned to the course with the specified roles.
foreach ($courses as $key => $course) {
$coursecontext = context_course::instance($course->id);
foreach ($this->roles as $key => $role) {
$usersassigned = get_role_users($this->rolescache[$role], $coursecontext, false, $userfields, $userfields);
foreach ($usersassigned as $username => $user) {
if (!isset($users[$username])) {
$users[$username] = $user;
$users[$username]->roles = array();
}
$users[$username]->roles[] = array($role => $course->shortname);
}
}
}
// Getting all the profile fields.
if ($getprofilefields) {
foreach ($users as $username => $user) {
profile_load_data($user);
}
}
// Overridding fields.
if ($this->useoverrides) {
foreach ($users as $username => $user) {
foreach ($this->overrides as $field => $value) {
$user->{$field} = $value;
}
}
}
return $users;
}
示例8: synchronize_moodle_user
/**
* Function to synchronize the curriculum data with the Moodle data.
*
* @param boolean $tomoodle Optional direction to synchronize the data.
*
*/
function synchronize_moodle_user($tomoodle = true, $createnew = false)
{
global $CFG, $CURMAN;
static $mu_loop_detect = array();
// Create a new Moodle user record to update with.
if (!($muserid = get_field('user', 'id', 'idnumber', $this->idnumber, 'mnethostid', $CFG->mnet_localhost_id, 'deleted', 0)) && !$createnew) {
return false;
}
if ($tomoodle) {
if ($createnew && !$muserid) {
/// Add a new user
$record = new stdClass();
$record->idnumber = $this->idnumber;
$record->username = $this->username;
/// Check if already hashed... (not active now)
if (!empty($CURMAN->passwordnothashed)) {
$record->password = hash_internal_user_password($this->password);
} else {
$record->password = $this->password;
}
$record->firstname = $this->firstname;
$record->lastname = $this->lastname;
$record->email = $this->email;
$record->confirmed = 1;
$record->mnethostid = $CFG->mnet_localhost_id;
$record->address = $this->address;
$record->city = $this->city;
$record->country = $this->country;
$record->timemodified = time();
$record->lang = $this->language;
$record->id = insert_record('user', $record);
} else {
if ($muserid) {
/// Update an existing user
$record = new stdClass();
$record->id = $muserid;
$record->idnumber = $this->idnumber;
$record->username = $this->username;
/// Check if already hashed... (not active now)
if (!empty($CURMAN->passwordnothashed)) {
$record->password = hash_internal_user_password($this->password);
} else {
$record->password = $this->password;
}
$record->firstname = $this->firstname;
$record->lastname = $this->lastname;
$record->email = $this->email;
$record->address = $this->address;
$record->city = $this->city;
$record->country = $this->country;
$record->timemodified = time();
$record->lang = $this->language;
update_record('user', $record);
} else {
return true;
}
}
// avoid update loops
if (isset($mu_loop_detect[$this->id])) {
return $record->id;
}
$mu_loop_detect[$this->id] = true;
// synchronize profile fields
$origrec = clone $record;
profile_load_data($origrec);
$fields = field::get_for_context_level(context_level_base::get_custom_context_level('user', 'block_curr_admin'));
$mfields = $CURMAN->db->get_records('user_info_field', '', '', '', 'shortname');
$fields = $fields ? $fields : array();
$changed = false;
require_once CURMAN_DIRLOCATION . '/plugins/moodle_profile/custom_fields.php';
foreach ($fields as $field) {
$field = new field($field);
if (isset($field->owners['moodle_profile']) && $field->owners['moodle_profile']->exclude == cm_moodle_profile::sync_to_moodle && isset($mfields[$field->shortname])) {
$shortname = $field->shortname;
$fieldname = "field_{$shortname}";
$mfieldname = "profile_{$fieldname}";
$mfieldvalue = isset($origrec->{$mfieldname}) ? $origrec->{$mfieldname} : null;
if (isset($this->{$fieldname}) && $mfieldvalue != $this->{$fieldname}) {
$record->{$mfieldname} = $this->{$fieldname};
$changed = true;
}
}
}
profile_save_data(addslashes_recursive($record));
if ($muserid) {
if ($changed) {
events_trigger('user_updated', $record);
}
} else {
events_trigger('user_created', $record);
}
unset($mu_loop_detect[$this->id]);
return $record->id;
}
//.........这里部分代码省略.........
示例9: pm_moodle_user_to_pm
//.........这里部分代码省略.........
$idnumber_updated = true;
// update the PM user with the new idnumber
$cmuser = new user();
$cmuser->id = $um->cuserid;
$cmuser->idnumber = $mu->idnumber;
$cmuser->save();
// update the association table with the new idnumber
$um->idnumber = $mu->idnumber;
$um->save();
}
}
}
// find the linked PM user
//filter for the basic condition on the Moodle user id
$condition_filter = new field_filter('id', $mu->id);
//filter for joining the association table
$association_filter = new join_filter('muserid', 'user', 'id', $condition_filter);
//outermost filter
$filter = new join_filter('id', usermoodle::TABLE, 'cuserid', $association_filter);
$cu = user::find($filter);
if ($cu->valid()) {
$cu = $cu->current();
} else {
// if a user with the same username but different idnumber exists,
// we can't sync over because it will violate PM user uniqueness
// constraints
$cu = user::find(new field_filter('username', $mu->username));
if ($cu->valid()) {
return true;
}
// if no such PM user exists, create a new one
$cu = new user();
$cu->transfercredits = 0;
$cu->timecreated = time();
}
// synchronize standard fields
$cu->username = $mu->username;
$cu->password = $mu->password;
// only need to update the idnumber if it wasn't handled above
if (!$idnumber_updated) {
$cu->idnumber = $mu->idnumber;
}
$cu->firstname = $mu->firstname;
$cu->lastname = $mu->lastname;
$cu->email = $mu->email;
$cu->address = $mu->address;
$cu->city = $mu->city;
$cu->country = $mu->country;
if (!empty($mu->phone1)) {
$cu->phone = $mu->phone1;
}
if (!empty($mu->phone2)) {
$cu->phone2 = $mu->phone2;
}
if (!empty($mu->lang)) {
$cu->language = $mu->lang;
}
$cu->timemodified = time();
// synchronize custom profile fields
profile_load_data($mu);
fix_moodle_profile_fields($mu);
$fields = field::get_for_context_level(CONTEXT_ELIS_USER);
$fields = $fields ? $fields : array();
require_once elis::plugin_file('elisfields_moodleprofile', 'custom_fields.php');
foreach ($fields as $field) {
$field = new field($field);
if (!moodle_profile_can_sync($field->shortname)) {
continue;
}
if (isset($field->owners['moodle_profile']) && isset($mu->{"profile_field_{$field->shortname}"})) {
// check if should sync user profile field settings
if ($field->owners['moodle_profile']->exclude == pm_moodle_profile::sync_from_moodle) {
sync_profile_field_settings_from_moodle($field);
}
$fieldname = "field_{$field->shortname}";
$cu->{$fieldname} = $mu->{"profile_field_{$field->shortname}"};
}
}
//specifically tell the user save not to use the local_elisprogram_usr_mdl for syncing
//because the record hasn't been inserted yet (see below)
try {
$cu->save(false);
} catch (Exception $ex) {
if (in_cron()) {
mtrace(get_string('record_not_created_reason', 'local_elisprogram', array('message' => $ex->getMessage() . " [{$mu->id}]")));
return false;
} else {
throw new Exception($ex->getMessage());
}
}
// if no user association record exists, create one
if (!$moodle_user_exists) {
$um = new usermoodle();
$um->cuserid = $cu->id;
$um->muserid = $mu->id;
$um->idnumber = $mu->idnumber;
$um->save();
}
return true;
}
示例10: moodle_url
}
if ($skip) {
continue;
}
if ($existinguser) {
$user->id = $existinguser->id;
$upt->track('username', html_writer::link(new moodle_url('/user/profile.php', array('id' => $existinguser->id)), s($existinguser->username)), 'normal', false);
if (is_siteadmin($user->id)) {
$upt->track('status', $strusernotupdatedadmin, 'error');
$userserrors++;
continue;
}
$existinguser->timemodified = time();
// do NOT mess with timecreated or firstaccess here!
//load existing profile data
profile_load_data($existinguser);
$upt->track('auth', $existinguser->auth, 'normal', false);
$doupdate = false;
if ($updatetype != UU_UPDATE_NOCHANGES) {
if (!empty($user->auth) and $user->auth !== $existinguser->auth) {
$upt->track('auth', s($existinguser->auth) . '-->' . s($user->auth), 'info', false);
$existinguser->auth = $user->auth;
if (!isset($supportedauths[$user->auth])) {
$upt->track('auth', $struserauthunsupported, 'warning');
}
$doupdate = true;
}
$allcolumns = array_merge($STD_FIELDS, $PRF_FIELDS);
foreach ($allcolumns as $column) {
if ($column === 'username' or $column === 'password' or $column === 'auth') {
// these can not be changed here
示例11: test_user_custom_field_sync_on_user_update
/**
* Validate that custom user fields are synched over to Moodle when PM user is updated
* during an import
*/
public function test_user_custom_field_sync_on_user_update()
{
// NOTE: not testing all cases because ELIS handles the details and this.
// Seems to already work.
global $CFG, $DB;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::lib('data/customfield.class.php');
require_once elispm::file('accesslib.php');
require_once elispm::lib('data/user.class.php');
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/user/profile/definelib.php';
require_once $CFG->dirroot . '/user/profile/field/checkbox/define.class.php';
// The associated Moodle user profile field.
$profiledefinecheckbox = new profile_define_checkbox();
$data = new stdClass();
$data->datatype = 'checkbox';
$data->categoryid = 99999;
$data->shortname = 'testfieldshortname';
$data->name = 'testfieldname';
$profiledefinecheckbox->define_save($data);
// Set up the user.
$user = new user(array('idnumber' => 'testuseridnumber', 'username' => 'testuserusername', 'firstname' => 'testuserfirstname', 'lastname' => 'testuserlastname', 'email' => 'testuser@email.com', 'country' => 'CA'));
$user->save();
// Field category.
$fieldcategory = new field_category(array('name' => 'testcategoryname'));
$fieldcategory->save();
// Custom field.
$field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldshortname', 'name' => 'testfieldname', 'datatype' => 'bool'));
$field->save();
// Field owners
field_owner::ensure_field_owner_exists($field, 'moodle_profile');
$DB->execute("UPDATE {" . field_owner::TABLE . "} SET exclude = ?", array(pm_moodle_profile::sync_to_moodle));
$manualowneroptions = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox');
field_owner::ensure_field_owner_exists($field, 'manual', $manualowneroptions);
// Field context level assocation.
$fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER));
$fieldcontextlevel->save();
// Reset cached custom fields.
$user = new user();
$user->reset_custom_field_list();
// Run the user create action.
$record = new stdClass();
$record->action = 'update';
$record->idnumber = 'testuseridnumber';
$record->username = 'testuserusername';
$record->email = 'testuser@email.com';
$record->testfieldshortname = 1;
$importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
$importplugin->fslogger = new silent_fslogger(null);
$importplugin->process_record('user', $record, 'bogus');
// Validation.
$user = new stdClass();
$user->id = $DB->get_field('user', 'id', array('username' => 'testuserusername'));
profile_load_data($user);
$this->assertEquals(1, $user->profile_field_testfieldshortname);
}
示例12: user_authenticated_hook
/**
* Post authentication hook.
* This method is called from authenticate_user_login() for all enabled auth plugins.
*
* @param object $user user object, later used for $USER
* @param string $username (with system magic quotes)
* @param string $password plain text password (with system magic quotes)
*/
function user_authenticated_hook(&$user, $username, $password)
{
global $DB, $SESSION;
$context = context_system::instance();
$uid = $user->id;
// Ignore users from don't_touch list
$ignore = explode(",", $this->config->donttouchusers);
if (!empty($ignore) and array_search($username, $ignore) !== false) {
$SESSION->mcautoenrolled = TRUE;
return true;
}
// Ignore guests
if ($uid < 2) {
$SESSION->mcautoenrolled = TRUE;
return true;
}
// ********************** Get COHORTS data
$clause = array('contextid' => $context->id);
if ($this->config->enableunenrol == 1) {
$clause['component'] = self::COMPONENT_NAME;
}
$cohorts = $DB->get_records('cohort', $clause);
$cohorts_list = array();
foreach ($cohorts as $cohort) {
$cid = $cohort->id;
$cname = format_string($cohort->name);
$cohorts_list[$cid] = $cname;
}
// Get advanced user data
profile_load_data($user);
profile_load_custom_fields($user);
$user_profile_data = mcae_prepare_profile_data($user, $this->config->secondrule_fld);
// Additional values for email
list($email_username, $email_domain) = explode("@", $user_profile_data['email']);
// email root domain
$email_domain_array = explode('.', $email_domain);
if (count($email_domain_array) > 2) {
$email_rootdomain = $email_domain_array[count($email_domain_array) - 2] . '.' . $email_domain_array[count($email_domain_array) - 1];
} else {
$email_rootdomain = $email_domain;
}
$user_profile_data['email'] = array('full' => $user_profile_data['email'], 'username' => $email_username, 'domain' => $email_domain, 'rootdomain' => $email_rootdomain);
// Delimiter
$delimiter = $this->config->delim;
$delim = strtr($delimiter, array('CR+LF' => chr(13) . chr(10), 'CR' => chr(13), 'LF' => chr(10)));
// Calculate a cohort names for user
$replacements_tpl = $this->config->replace_arr;
$replacements = array();
if (!empty($replacements_tpl)) {
$replacements_pre = explode($delim, $replacements_tpl);
foreach ($replacements_pre as $rap) {
list($key, $val) = explode("|", $rap);
$replacements[$key] = $val;
}
}
// Generate cohorts array
$main_rule = $this->config->mainrule_fld;
$templates_tpl = array();
$templates = array();
if (!empty($main_rule)) {
$templates_tpl = explode($delim, $main_rule);
} else {
$SESSION->mcautoenrolled = TRUE;
return;
//Empty mainrule
}
// Find %split function
foreach ($templates_tpl as $item) {
if (preg_match('/(?<full>%split\\((?<fld>\\w*)\\|(?<delim>.{1,5})\\))/', $item, $split_params)) {
// Split!
$splitted = explode($split_params['delim'], $user_profile_data[$split_params['fld']]);
foreach ($splitted as $key => $val) {
$user_profile_data[$split_params['fld'] . "_{$key}"] = $val;
$templates[] = strtr($item, array("{$split_params['full']}" => "{{ {$split_params['fld']}_{$key} }}"));
}
} else {
$templates[] = $item;
}
}
$processed = array();
// Process templates with Mustache
foreach ($templates as $cohort) {
$cohortname = $this->mustache->render($cohort, $user_profile_data);
$cohortname = !empty($replacements) ? strtr($cohortname, $replacements) : $cohortname;
if ($cohortname == '') {
continue;
// We don't want an empty cohort name
}
$cid = array_search($cohortname, $cohorts_list);
if ($cid !== false) {
if (!$DB->record_exists('cohort_members', array('cohortid' => $cid, 'userid' => $user->id))) {
cohort_add_member($cid, $user->id);
//.........这里部分代码省略.........
示例13: defined
*/
defined('MOODLE_INTERNAL') || die;
global $USER;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->dirroot . '/auth/mcae/lib.php';
if ($hassiteconfig) {
// needs this condition or there is error on login page
$ADMIN->add('accounts', new admin_externalpage('cohorttoolmcae', get_string('auth_cohorttoolmcae', 'auth_mcae'), new moodle_url('/auth/mcae/convert.php')));
$ADMIN->add('accounts', new admin_externalpage('cohortviewmcae', get_string('auth_cohortviewmcae', 'auth_mcae'), new moodle_url('/auth/mcae/view.php')));
}
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configtextarea('auth_mcae/mainrule_fld', get_string('auth_mainrule_fld', 'auth_mcae'), '', ''));
// Profile field helper
$fldlist = array();
$usr_helper = $DB->get_record('user', array('id' => 2));
profile_load_data($usr_helper);
profile_load_custom_fields($usr_helper);
$fldlist = mcae_prepare_profile_data($usr_helper);
// Additional values for email
list($email_username, $email_domain) = explode("@", $fldlist['email']);
// Email root domain
$email_domain_array = explode('.', $email_domain);
if (count($email_domain_array) > 2) {
$email_rootdomain = $email_domain_array[count($email_domain_array) - 2] . '.' . $email_domain_array[count($email_domain_array) - 1];
} else {
$email_rootdomain = $email_domain;
}
$fldlist['email'] = array('full' => $fldlist['email'], 'username' => $email_username, 'domain' => $email_domain, 'rootdomain' => $email_rootdomain);
//print_r($fldlist);
$help_array = array();
mcae_print_profile_data($fldlist, '', $help_array);
示例14: user_download_csv
function user_download_csv($fields)
{
global $CFG, $SESSION, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->libdir . '/csvlib.class.php';
$filename = clean_filename(get_string('users'));
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
foreach ($SESSION->bulk_users as $userid) {
$row = array();
if (!($user = $DB->get_record('user', array('id' => $userid)))) {
continue;
}
profile_load_data($user);
$userprofiledata = array();
foreach ($fields as $field => $unused) {
// Custom user profile textarea fields come in an array
// The first element is the text and the second is the format.
// We only take the text.
if (is_array($user->{$field})) {
$userprofiledata[] = reset($user->{$field});
} else {
$userprofiledata[] = $user->{$field};
}
}
$csvexport->add_data($userprofiledata);
}
$csvexport->download_file();
die;
}
示例15: print_box
}
//if user has the right and the map doesn't require the students consent to appear on the map
//then show button to update locations for users - locations will be try to be set from users' profile location
if (has_capability("mod/map:setotherslocation", $context, $USER->id) && $map->requireok == 0 && $map->studentlocations == 1) {
print_box(print_single_button("update_locations.php?id=" . $id, null, get_string("updateuserlocations", "map"), "post", "_self", true), "button");
}
//only allow members to add student locations or extra locations
if ($memberOfGroup) {
//should this map show student locations
if ($map->studentlocations == 1 && has_capability('mod/map:setownlocation', $context)) {
$locForm = new mod_map_user_location_form();
if (!isset($user_map_location)) {
//no user location has been set for current user
//fill form with profile location
require_once $CFG->dirroot . '/user/profile/lib.php';
profile_load_data($USER);
print_box(format_text(get_string("usernolocation", "map"), FORMAT_PLAIN), 'generalbox', 'intro');
$curLocation = new object();
$curLocation->city = $USER->city;
$curLocation->state = map_get_user_state($USER);
$curLocation->country = $USER->country;
$curLocation->id = $cm->id;
$curLocation->action = "insertlocation";
$curLocation->userid = $USER->id;
$locForm->set_data($curLocation);
} else {
if ($user_map_location->showcode == 0) {
//user has explicitly said they don't want to show up on the map
$locForm = new mod_map_reset_location_form();
}
//user has set location